jdk/src/share/native/sun/security/pkcs11/wrapper/p11_crypt.c
author jzavgren
Wed, 07 Nov 2012 10:49:19 +0000
changeset 14414 f338be3ef659
parent 6894 361524087cdb
child 23010 6dadb192ad81
permissions -rw-r--r--
8001579: Cleanup warnings in security native code Reviewed-by: chegar, alanb, vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * Redistribution and use in  source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * modification, are permitted  provided that the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * 1. Redistributions of  source code must retain the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *    this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * 2. Redistributions in  binary form must reproduce the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *    this list of conditions and the following disclaimer in the documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *    and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 3. The end-user documentation included with the redistribution, if any, must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *    include the following acknowledgment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *    "This product includes software developed by IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *     Technology."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *    Alternately, this acknowledgment may appear in the software itself, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *    and wherever such third-party acknowledgments normally appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * 4. The names "Graz University of Technology" and "IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *    Technology" must not be used to endorse or promote products derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *    this software without prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * 5. Products derived from this software may not be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *    "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *    written permission of Graz University of Technology.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  POSSIBILITY  OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include "pkcs11wrapper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#include <assert.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#include "sun_security_pkcs11_wrapper_PKCS11.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#ifdef P11_ENABLE_C_ENCRYPTINIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Method:    C_EncryptInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @param   jlong jKeyHandle            CK_OBJECT_HANDLE hKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 jobject jMechanism, jlong jKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    CK_MECHANISM ckMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    CK_OBJECT_HANDLE ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    ckKeyHandle = jLongToCKULong(jKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    jMechanismToCKMechanism(env, jMechanism, &ckMechanism);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
    84
    if ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    rv = (*ckpFunctions->C_EncryptInit)(ckSessionHandle, &ckMechanism,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                        ckKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    if (ckMechanism.pParameter != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        free(ckMechanism.pParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
#ifdef P11_ENABLE_C_ENCRYPT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * Method:    C_Encrypt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * Signature: (J[BII[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @param   jbyteArray jData            CK_BYTE_PTR pData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *                                      CK_ULONG ulDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * @return  jbyteArray jEncryptedData   CK_BYTE_PTR pEncryptedData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *                                      CK_ULONG_PTR pulEncryptedDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Encrypt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 jbyteArray jIn, jint jInOfs, jint jInLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    CK_RV rv;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   117
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    CK_BYTE_PTR outBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    CK_ULONG ckEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   127
    inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   128
    if (inBufP == NULL) { return 0; }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   129
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   130
    outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   131
    if (outBufP == NULL) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   132
        // Make sure to release inBufP
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   133
        (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   134
        return 0;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   135
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    ckEncryptedPartLen = jOutLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   139
    rv = (*ckpFunctions->C_Encrypt)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   140
                                    (CK_BYTE_PTR)(inBufP + jInOfs), jInLen,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   141
                                    (CK_BYTE_PTR)(outBufP + jOutOfs),
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   142
                                    &ckEncryptedPartLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   144
    (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_ABORT);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   145
    (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   146
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   147
    ckAssertReturnValueOK(env, rv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    return ckEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
#ifdef P11_ENABLE_C_ENCRYPTUPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * Method:    C_EncryptUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * Signature: (J[BII[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * @param   jbyteArray jPart            CK_BYTE_PTR pPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *                                      CK_ULONG ulPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * @return  jbyteArray jEncryptedPart   CK_BYTE_PTR pEncryptedPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *                                      CK_ULONG_PTR pulEncryptedPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    CK_RV rv;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   172
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    CK_BYTE_PTR outBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    CK_ULONG ckEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    if (directIn != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   183
      inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    } else {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   185
      inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   186
      if (inBufP == NULL) { return 0; }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   187
    }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   188
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   189
    if (directOut != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   190
      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   191
    } else {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   192
      outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   193
      if (outBufP == NULL) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   194
          // Make sure to release inBufP
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   195
          (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   196
          return 0;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   197
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    ckEncryptedPartLen = jOutLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    //printf("EU: inBufP=%i, jInOfs=%i, jInLen=%i, outBufP=%i\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    //       inBufP, jInOfs, jInLen, outBufP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    rv = (*ckpFunctions->C_EncryptUpdate)(ckSessionHandle,
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   206
                                          (CK_BYTE_PTR)(inBufP + jInOfs), jInLen,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   207
                                          (CK_BYTE_PTR)(outBufP + jOutOfs),
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   208
                                          &ckEncryptedPartLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    //printf("EU: ckEncryptedPartLen=%i\n", ckEncryptedPartLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   212
    if (directIn == 0) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   213
        (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   216
    if (directOut == 0) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   217
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_ABORT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   219
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   220
    ckAssertReturnValueOK(env, rv);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   221
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    return ckEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
#ifdef P11_ENABLE_C_ENCRYPTFINAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * Method:    C_EncryptFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * Signature: (J[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * Parametermapping:                        *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * @param   jlong jSessionHandle            CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * @return  jbyteArray jLastEncryptedPart   CK_BYTE_PTR pLastEncryptedDataPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *                                          CK_ULONG_PTR pulLastEncryptedDataPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    CK_BYTE_PTR outBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    CK_ULONG ckLastEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    if (directOut != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   252
      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    } else {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   254
      outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   255
      if (outBufP == NULL) { return 0; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   258
    ckLastEncryptedPartLen = jOutLen;
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   259
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    //printf("EF: outBufP=%i\n", outBufP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   262
    rv = (*ckpFunctions->C_EncryptFinal)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   263
                                         (CK_BYTE_PTR)(outBufP + jOutOfs),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                         &ckLastEncryptedPartLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    //printf("EF: ckLastEncryptedPartLen=%i", ckLastEncryptedPartLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   268
    if (directOut == 0) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   269
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_ABORT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   272
    ckAssertReturnValueOK(env, rv);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   273
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    return ckLastEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
#ifdef P11_ENABLE_C_DECRYPTINIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * Method:    C_DecryptInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 * @param   jlong jKeyHandle            CK_OBJECT_HANDLE hKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 jobject jMechanism, jlong jKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    CK_MECHANISM ckMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    CK_OBJECT_HANDLE ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    ckKeyHandle = jLongToCKULong(jKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    jMechanismToCKMechanism(env, jMechanism, &ckMechanism);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   304
    if ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    rv = (*ckpFunctions->C_DecryptInit)(ckSessionHandle, &ckMechanism,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                        ckKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    if (ckMechanism.pParameter != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        free(ckMechanism.pParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
#ifdef P11_ENABLE_C_DECRYPT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 * Method:    C_Decrypt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 * Signature: (J[BII[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 * @param   jbyteArray jEncryptedData   CK_BYTE_PTR pEncryptedData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 *                                      CK_ULONG ulEncryptedDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 * @return  jbyteArray jData            CK_BYTE_PTR pData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 *                                      CK_ULONG_PTR pulDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Decrypt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 jbyteArray jIn, jint jInOfs, jint jInLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    CK_RV rv;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   337
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    CK_BYTE_PTR outBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    CK_ULONG ckPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   347
    inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   348
    if (inBufP == NULL) { return 0; }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   349
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   350
    outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   351
    if (outBufP == NULL) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   352
        // Make sure to release inBufP
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   353
        (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   354
        return 0;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   355
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    ckPartLen = jOutLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   359
    rv = (*ckpFunctions->C_Decrypt)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   360
                                    (CK_BYTE_PTR)(inBufP + jInOfs), jInLen,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   361
                                    (CK_BYTE_PTR)(outBufP + jOutOfs),
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   362
                                    &ckPartLen);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   363
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   364
    (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_ABORT);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   365
    (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   366
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   367
    ckAssertReturnValueOK(env, rv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    return ckPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
#ifdef P11_ENABLE_C_DECRYPTUPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * Method:    C_DecryptUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 * Signature: (J[BII[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
 * @param   jbyteArray jEncryptedPart   CK_BYTE_PTR pEncryptedPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
 *                                      CK_ULONG ulEncryptedPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
 * @return  jbyteArray jPart            CK_BYTE_PTR pPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
 *                                      CK_ULONG_PTR pulPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
 jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    CK_RV rv;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   393
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    CK_BYTE_PTR outBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    CK_ULONG ckDecryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    if (directIn != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   404
      inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    } else {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   406
      inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   407
      if (inBufP == NULL) { return 0; }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   408
    }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   409
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   410
    if (directOut != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   411
      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   412
    } else {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   413
      outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   414
      if (outBufP == NULL) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   415
          // Make sure to release inBufP
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   416
          (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   417
          return 0;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   418
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    ckDecryptedPartLen = jOutLen;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   422
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   423
    rv = (*ckpFunctions->C_DecryptUpdate)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   424
                                          (CK_BYTE_PTR)(inBufP + jInOfs), jInLen,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   425
                                          (CK_BYTE_PTR)(outBufP + jOutOfs),
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   426
                                          &ckDecryptedPartLen);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   427
    if (directIn == 0) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   428
        (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   431
    if (directOut == 0) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   432
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_ABORT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   435
    ckAssertReturnValueOK(env, rv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    return ckDecryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
#ifdef P11_ENABLE_C_DECRYPTFINAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
 * Method:    C_DecryptFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
 * Signature: (J[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
 * @return  jbyteArray jLastPart        CK_BYTE_PTR pLastPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
 *                                      CK_ULONG_PTR pulLastPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    CK_BYTE_PTR outBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    CK_ULONG ckLastPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    if (directOut != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   468
      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    } else {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   470
      outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   471
      if (outBufP == NULL) { return 0; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   474
    ckLastPartLen = jOutLen;
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   475
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   476
    rv = (*ckpFunctions->C_DecryptFinal)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   477
                                         (CK_BYTE_PTR)(outBufP + jOutOfs),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                                         &ckLastPartLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   480
    if (directOut == 0) {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   481
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_ABORT);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   482
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   485
    ckAssertReturnValueOK(env, rv);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   486
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    return ckLastPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
#endif