src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_crypt.c
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58489 2faeaa5933a6
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2019, 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;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    74
    CK_MECHANISM_PTR ckpMechanism = NULL;
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    75
    CK_MECHANISM_PTR ckpTemp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    CK_OBJECT_HANDLE ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    ckKeyHandle = jLongToCKULong(jKeyHandle);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    84
    ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism);
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    85
    TRACE1("DEBUG C_EncryptInit: created pMech = %p\n",
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    86
            ckpMechanism);
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    87
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
    88
    if ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    90
    rv = (*ckpFunctions->C_EncryptInit)(ckSessionHandle, ckpMechanism,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                        ckKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    93
    if (ckpMechanism->mechanism == CKM_AES_GCM) {
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    94
        if (rv == CKR_ARGUMENTS_BAD || rv == CKR_MECHANISM_PARAM_INVALID) {
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    95
            // retry with CKM_GCM_PARAMS structure in pkcs11t.h
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    96
            TRACE0("DEBUG C_EncryptInit: retry with CK_GCM_PARAMS\n");
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    97
            ckpTemp = updateGCMParams(env, ckpMechanism);
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    98
            if (ckpTemp != NULL) { // only re-call if conversion succeeds
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
    99
                ckpMechanism = ckpTemp;
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   100
                rv = (*ckpFunctions->C_EncryptInit)(ckSessionHandle, ckpMechanism,
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   101
                        ckKeyHandle);
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   102
            }
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   103
        }
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   104
    }
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   105
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   106
    TRACE1("DEBUG C_EncryptInit: freed pMech = %p\n", ckpMechanism);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   107
    freeCKMechanismPtr(ckpMechanism);
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   108
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   110
    TRACE0("FINISHED\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#ifdef P11_ENABLE_C_ENCRYPT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * Method:    C_Encrypt
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   118
 * Signature: (JJ[BIIJ[BII)I
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   121
 * @param   jlong directIn              CK_BYTE_PTR pData
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @param   jbyteArray jData            CK_BYTE_PTR pData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *                                      CK_ULONG ulDataLen
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   124
 * @param   jlong directOut             CK_BYTE_PTR pEncryptedData
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   125
 * @return  jint encryptedDataLen       CK_BYTE_PTR pEncryptedData
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *                                      CK_ULONG_PTR pulEncryptedDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Encrypt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
(JNIEnv *env, jobject obj, jlong jSessionHandle,
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   131
 jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen,
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   132
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    CK_RV rv;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   136
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    CK_BYTE_PTR outBufP;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   139
    CK_ULONG ckEncryptedLen = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   146
    if (directIn != 0) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   147
      inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   148
    } else {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   149
      inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   150
      if (inBufP == NULL) { return 0; }
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
   151
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   153
    if (directOut != 0) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   154
      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   155
    } else {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   156
      outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   157
      if (outBufP == NULL) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   158
          goto cleanup;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   159
      }
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   160
    }
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   161
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   162
    ckEncryptedLen = jOutLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   164
    rv = (*ckpFunctions->C_Encrypt)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   165
                                    (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
   166
                                    (CK_BYTE_PTR)(outBufP + jOutOfs),
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   167
                                    &ckEncryptedLen);
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   168
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   169
    ckAssertReturnValueOK(env, rv);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   170
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   171
cleanup:
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   172
    if (directIn == 0 && inBufP != NULL) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   173
        (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   174
    }
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   175
    if (directOut == 0 && outBufP != NULL) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   176
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   177
    }
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   178
    return ckEncryptedLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
#ifdef P11_ENABLE_C_ENCRYPTUPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * Method:    C_EncryptUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * Signature: (J[BII[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * @param   jbyteArray jPart            CK_BYTE_PTR pPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *                                      CK_ULONG ulPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * @return  jbyteArray jEncryptedPart   CK_BYTE_PTR pEncryptedPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 *                                      CK_ULONG_PTR pulEncryptedPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    CK_RV rv;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   202
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    CK_BYTE_PTR outBufP;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   205
    CK_ULONG ckEncryptedPartLen = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    if (directIn != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   213
      inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    } else {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   215
      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
   216
      if (inBufP == NULL) { return 0; }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   217
    }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   218
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   219
    if (directOut != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   220
      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
   221
    } else {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   222
      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
   223
      if (outBufP == NULL) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   224
          goto cleanup;
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
   225
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    ckEncryptedPartLen = jOutLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    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
   231
                                          (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
   232
                                          (CK_BYTE_PTR)(outBufP + jOutOfs),
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   233
                                          &ckEncryptedPartLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   235
    ckAssertReturnValueOK(env, rv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   237
cleanup:
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   238
    if (directIn == 0 && inBufP != NULL) {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   239
        (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   241
    if (directOut == 0 && outBufP != NULL) {
27487
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents: 25859
diff changeset
   242
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    return ckEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
#ifdef P11_ENABLE_C_ENCRYPTFINAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * Method:    C_EncryptFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * Signature: (J[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * Parametermapping:                        *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * @param   jlong jSessionHandle            CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * @return  jbyteArray jLastEncryptedPart   CK_BYTE_PTR pLastEncryptedDataPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 *                                          CK_ULONG_PTR pulLastEncryptedDataPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    CK_BYTE_PTR outBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    CK_ULONG ckLastEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    if (directOut != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   274
      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    } else {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   276
      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
   277
      if (outBufP == NULL) { return 0; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   280
    ckLastEncryptedPartLen = jOutLen;
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   281
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   282
    rv = (*ckpFunctions->C_EncryptFinal)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   283
                                         (CK_BYTE_PTR)(outBufP + jOutOfs),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                         &ckLastEncryptedPartLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   286
    if (directOut == 0) {
27487
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents: 25859
diff changeset
   287
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   290
    ckAssertReturnValueOK(env, rv);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   291
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    return ckLastEncryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
#ifdef P11_ENABLE_C_DECRYPTINIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * Method:    C_DecryptInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * @param   jlong jKeyHandle            CK_OBJECT_HANDLE hKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 jobject jMechanism, jlong jKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    CK_SESSION_HANDLE ckSessionHandle;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   312
    CK_MECHANISM_PTR ckpMechanism = NULL;
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   313
    CK_MECHANISM_PTR ckpTemp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    CK_OBJECT_HANDLE ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    ckKeyHandle = jLongToCKULong(jKeyHandle);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   322
    ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism);
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   323
    TRACE1("DEBUG C_DecryptInit: created pMech = %p\n",
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   324
            ckpMechanism);
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   325
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
   326
    if ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   328
    rv = (*ckpFunctions->C_DecryptInit)(ckSessionHandle, ckpMechanism,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                        ckKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   331
    if (ckpMechanism->mechanism == CKM_AES_GCM) {
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   332
        if (rv == CKR_ARGUMENTS_BAD || rv == CKR_MECHANISM_PARAM_INVALID) {
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   333
            // retry with CKM_GCM_PARAMS structure in pkcs11t.h
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   334
            TRACE0("DEBUG C_DecryptInit: retry with CK_GCM_PARAMS\n");
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   335
            ckpTemp = updateGCMParams(env, ckpMechanism);
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   336
            if (ckpTemp != NULL) { // only re-call if conversion succeeds
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   337
                ckpMechanism = ckpTemp;
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   338
                rv = (*ckpFunctions->C_DecryptInit)(ckSessionHandle, ckpMechanism,
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   339
                        ckKeyHandle);
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   340
            }
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   341
        }
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   342
    }
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   343
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   344
    TRACE1("DEBUG C_DecryptInit: freed pMech = %p\n", ckpMechanism);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   345
    freeCKMechanismPtr(ckpMechanism);
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   346
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
58489
2faeaa5933a6 8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents: 55332
diff changeset
   348
    TRACE0("FINISHED\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
#ifdef P11_ENABLE_C_DECRYPT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
 * Method:    C_Decrypt
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   356
 * Signature: (JJ[BIIJ[BII)I
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
 * @param   jbyteArray jEncryptedData   CK_BYTE_PTR pEncryptedData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
 *                                      CK_ULONG ulEncryptedDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 * @return  jbyteArray jData            CK_BYTE_PTR pData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 *                                      CK_ULONG_PTR pulDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Decrypt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
(JNIEnv *env, jobject obj, jlong jSessionHandle,
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   367
 jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen,
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   368
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    CK_RV rv;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   372
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    CK_BYTE_PTR outBufP;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   375
    CK_ULONG ckOutLen = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   382
    if (directIn != 0) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   383
      inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   384
    } else {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   385
      inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   386
      if (inBufP == NULL) { return 0; }
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
   387
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   389
    if (directOut != 0) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   390
      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   391
    } else {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   392
      outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   393
      if (outBufP == NULL) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   394
          goto cleanup;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   395
      }
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   396
    }
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   397
    ckOutLen = jOutLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   399
    rv = (*ckpFunctions->C_Decrypt)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   400
                                    (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
   401
                                    (CK_BYTE_PTR)(outBufP + jOutOfs),
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   402
                                    &ckOutLen);
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   403
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   404
    ckAssertReturnValueOK(env, rv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   406
cleanup:
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   407
    if (directIn == 0 && inBufP != NULL) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   408
        (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   409
    }
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   410
    if (directOut == 0 && outBufP != NULL) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   411
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   412
    }
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   413
    return ckOutLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
#ifdef P11_ENABLE_C_DECRYPTUPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
 * Method:    C_DecryptUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
 * Signature: (J[BII[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
 * @param   jbyteArray jEncryptedPart   CK_BYTE_PTR pEncryptedPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
 *                                      CK_ULONG ulEncryptedPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 * @return  jbyteArray jPart            CK_BYTE_PTR pPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 *                                      CK_ULONG_PTR pulPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
 jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    CK_RV rv;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   437
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    CK_BYTE_PTR outBufP;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   440
    CK_ULONG ckDecryptedPartLen = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    if (directIn != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   448
      inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    } else {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   450
      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
   451
      if (inBufP == NULL) { return 0; }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   452
    }
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   453
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   454
    if (directOut != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   455
      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
   456
    } else {
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   457
      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
   458
      if (outBufP == NULL) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   459
          goto cleanup;
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
   460
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    ckDecryptedPartLen = jOutLen;
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   464
    rv = (*ckpFunctions->C_DecryptUpdate)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   465
                                          (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
   466
                                          (CK_BYTE_PTR)(outBufP + jOutOfs),
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   467
                                          &ckDecryptedPartLen);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   468
    ckAssertReturnValueOK(env, rv);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   469
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   470
cleanup:
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   471
    if (directIn == 0 && inBufP != NULL) {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   472
        (*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   474
    if (directOut == 0 && outBufP != NULL) {
27487
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents: 25859
diff changeset
   475
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    return ckDecryptedPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
#ifdef P11_ENABLE_C_DECRYPTFINAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
 * Method:    C_DecryptFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
 * Signature: (J[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
 * @return  jbyteArray jLastPart        CK_BYTE_PTR pLastPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
 *                                      CK_ULONG_PTR pulLastPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
(JNIEnv *env, jobject obj, jlong jSessionHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
 jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    CK_BYTE_PTR outBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    CK_ULONG ckLastPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    if (directOut != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 6894
diff changeset
   508
      outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    } else {
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   510
      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
   511
      if (outBufP == NULL) { return 0; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   514
    ckLastPartLen = jOutLen;
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   515
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   516
    rv = (*ckpFunctions->C_DecryptFinal)(ckSessionHandle,
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   517
                                         (CK_BYTE_PTR)(outBufP + jOutOfs),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                         &ckLastPartLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   520
    if (directOut == 0) {
27487
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents: 25859
diff changeset
   521
        (*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT);
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   522
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
6894
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   525
    ckAssertReturnValueOK(env, rv);
361524087cdb 6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents: 5506
diff changeset
   526
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    return ckLastPartLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
#endif