src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_sign.c
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 55410 c3b354fdbaa4
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
#include "pkcs11wrapper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include <assert.h>
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 14342
diff changeset
    54
#include "jlong.h"
2
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_SIGNINIT
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_SignInit
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
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    66
 * @param   jlong jKeyHandle            CK_OBJECT_HANDLE hKey
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    CK_SESSION_HANDLE ckSessionHandle;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    72
    CK_MECHANISM_PTR ckpMechanism = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    CK_OBJECT_HANDLE ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    79
    TRACE0("DEBUG: C_SignInit\n");
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    80
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    ckSessionHandle = jLongToCKULong(jSessionHandle);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    82
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    83
    ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism);
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; }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    85
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    ckKeyHandle = jLongToCKULong(jKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    88
    rv = (*ckpFunctions->C_SignInit)(ckSessionHandle, ckpMechanism, ckKeyHandle);
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
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK ||
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    91
            (ckpMechanism->pParameter == NULL)) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    92
        freeCKMechanismPtr(ckpMechanism);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    93
    } else {
55410
c3b354fdbaa4 8225695: 32-bit build failures after JDK-8080462 (Update SunPKCS11 provider with PKCS11 v2.40 support)
shade
parents: 55332
diff changeset
    94
        (*env)->SetLongField(env, jMechanism, mech_pHandleID, ptr_to_jlong(ckpMechanism));
c3b354fdbaa4 8225695: 32-bit build failures after JDK-8080462 (Update SunPKCS11 provider with PKCS11 v2.40 support)
shade
parents: 55332
diff changeset
    95
        TRACE1("DEBUG C_SignInit: stored pMech = 0x%lX\n", ptr_to_jlong(ckpMechanism));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
    97
    TRACE0("FINISHED\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
#ifdef P11_ENABLE_C_SIGN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * Method:    C_Sign
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   105
 * Signature: (J[BI)[B
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * @param   jbyteArray jData            CK_BYTE_PTR pData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *                                      CK_ULONG ulDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * @return  jbyteArray jSignature       CK_BYTE_PTR pSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *                                      CK_ULONG_PTR pulSignatureLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    CK_BYTE_PTR ckpData = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    CK_ULONG ckDataLength;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   119
    CK_BYTE_PTR bufP;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   120
    CK_ULONG ckSignatureLength;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   121
    CK_BYTE BUF[MAX_STACK_BUFFER_LEN];
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   122
    jbyteArray jSignature = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   128
    TRACE0("DEBUG: C_Sign\n");
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   129
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    jByteArrayToCKByteArray(env, jData, &ckpData, &ckDataLength);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   132
    if ((*env)->ExceptionCheck(env)) {
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
   133
        return NULL;
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
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   136
    TRACE1("DEBUG C_Sign: data length = %lu\n", ckDataLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   138
    // unknown signature length
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   139
    bufP = BUF;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   140
    ckSignatureLength = MAX_STACK_BUFFER_LEN;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   141
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   142
    rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength,
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   143
        bufP, &ckSignatureLength);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   144
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   145
    TRACE1("DEBUG C_Sign: ret rv=0x%lX\n", rv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   147
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   148
        jSignature = ckByteArrayToJByteArray(env, bufP, ckSignatureLength);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   149
        TRACE1("DEBUG C_Sign: signature length = %lu\n", ckSignatureLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   151
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    free(ckpData);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   153
    if (bufP != BUF) { free(bufP); }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   155
    TRACE0("FINISHED\n");
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   156
    return jSignature;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
#ifdef P11_ENABLE_C_SIGNUPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * Method:    C_SignUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * Signature: (J[BII)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * @param   jbyteArray jPart            CK_BYTE_PTR pPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *                                      CK_ULONG ulPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    CK_BYTE_PTR bufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    CK_BYTE BUF[MAX_STACK_BUFFER_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    jsize bufLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    if (directIn != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 14342
diff changeset
   185
        rv = (*ckpFunctions->C_SignUpdate)(ckSessionHandle, (CK_BYTE_PTR) jlong_to_ptr(directIn), jInLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        ckAssertReturnValueOK(env, rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    if (jInLen <= MAX_STACK_BUFFER_LEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        bufLen = MAX_STACK_BUFFER_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        bufP = BUF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen);
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
   195
        bufP = (CK_BYTE_PTR) malloc((size_t)bufLen);
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
        if (bufP == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   197
            throwOutOfMemoryError(env, 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
   198
            return;
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
   199
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    while (jInLen > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        jsize chunkLen = min(bufLen, jInLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        (*env)->GetByteArrayRegion(env, jIn, jInOfs, chunkLen, (jbyte *)bufP);
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
   205
        if ((*env)->ExceptionCheck(env)) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   206
            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
   207
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        rv = (*ckpFunctions->C_SignUpdate)(ckSessionHandle, bufP, chunkLen);
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
   209
        if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   210
            goto cleanup;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        jInOfs += chunkLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        jInLen -= chunkLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   216
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
   217
    if (bufP != BUF) { free(bufP); }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   218
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   219
    return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
#ifdef P11_ENABLE_C_SIGNFINAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * Method:    C_SignFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * Signature: (J)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * @return  jbyteArray jSignature       CK_BYTE_PTR pSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *                                      CK_ULONG_PTR pulSignatureLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jint jExpectedLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    jbyteArray jSignature = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    CK_BYTE BUF[MAX_STACK_BUFFER_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    CK_BYTE_PTR bufP = BUF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    CK_ULONG ckSignatureLength = MAX_STACK_BUFFER_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 14342
diff changeset
   248
    if ((jExpectedLength > 0) && ((CK_ULONG)jExpectedLength < ckSignatureLength)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        ckSignatureLength = jExpectedLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    rv = (*ckpFunctions->C_SignFinal)(ckSessionHandle, bufP, &ckSignatureLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if (rv == CKR_BUFFER_TOO_SMALL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        bufP = (CK_BYTE_PTR) malloc(ckSignatureLength);
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
   255
        if (bufP == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   256
            throwOutOfMemoryError(env, 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
   257
            return NULL;
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
   258
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        rv = (*ckpFunctions->C_SignFinal)(ckSessionHandle, bufP, &ckSignatureLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        jSignature = ckByteArrayToJByteArray(env, bufP, ckSignatureLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
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
   265
    if (bufP != BUF) { free(bufP); }
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
   266
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    return jSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
#ifdef P11_ENABLE_C_SIGNRECOVERINIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * Method:    C_SignRecoverInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   279
 * @param   jlong jKeyHandle            CK_OBJECT_HANDLE hKey
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecoverInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    CK_SESSION_HANDLE ckSessionHandle;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   285
    CK_MECHANISM_PTR ckpMechanism = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    CK_OBJECT_HANDLE ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   292
    TRACE0("DEBUG: C_SignRecoverInit\n");
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   293
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    ckSessionHandle = jLongToCKULong(jSessionHandle);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   295
    ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism);
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
   296
    if ((*env)->ExceptionCheck(env)) { return; }
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
   297
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    ckKeyHandle = jLongToCKULong(jKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   300
    rv = (*ckpFunctions->C_SignRecoverInit)(ckSessionHandle, ckpMechanism, ckKeyHandle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   302
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK ||
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   303
            (ckpMechanism->pParameter == NULL)) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   304
        freeCKMechanismPtr(ckpMechanism);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   305
    } else {
55410
c3b354fdbaa4 8225695: 32-bit build failures after JDK-8080462 (Update SunPKCS11 provider with PKCS11 v2.40 support)
shade
parents: 55332
diff changeset
   306
        (*env)->SetLongField(env, jMechanism, mech_pHandleID, ptr_to_jlong(ckpMechanism));
c3b354fdbaa4 8225695: 32-bit build failures after JDK-8080462 (Update SunPKCS11 provider with PKCS11 v2.40 support)
shade
parents: 55332
diff changeset
   307
        TRACE1("DEBUG C_SignRecoverInit, stored pMech = 0x%lX\n", ptr_to_jlong(ckpMechanism));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   309
    TRACE0("FINISHED\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
#ifdef P11_ENABLE_C_SIGNRECOVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 * Method:    C_SignRecover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
 * Signature: (J[BII[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 * @param   jbyteArray jData            CK_BYTE_PTR pData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 *                                      CK_ULONG ulDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 * @return  jbyteArray jSignature       CK_BYTE_PTR pSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 *                                      CK_ULONG_PTR pulSignatureLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
  (JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jIn, jint jInOfs, jint jInLen, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    CK_BYTE INBUF[MAX_STACK_BUFFER_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    CK_BYTE OUTBUF[MAX_STACK_BUFFER_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    CK_BYTE_PTR outBufP = OUTBUF;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   334
    CK_ULONG ckSignatureLength = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    if (jInLen <= MAX_STACK_BUFFER_LEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        inBufP = INBUF;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   343
        ckSignatureLength = MAX_STACK_BUFFER_LEN;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    } else {
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
   345
        inBufP = (CK_BYTE_PTR) malloc((size_t)jInLen);
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
   346
        if (inBufP == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   347
            throwOutOfMemoryError(env, 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
   348
            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
   349
        }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   350
        ckSignatureLength = jInLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP);
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
    if ((*env)->ExceptionCheck(env)) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   355
        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
   356
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   357
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    rv = (*ckpFunctions->C_SignRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckSignatureLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /* re-alloc larger buffer if it fits into our Java buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    if ((rv == CKR_BUFFER_TOO_SMALL) && (ckSignatureLength <= jIntToCKULong(jOutLen))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        outBufP = (CK_BYTE_PTR) malloc(ckSignatureLength);
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
   362
        if (outBufP == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   363
            throwOutOfMemoryError(env, 0);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   364
            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
   365
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        rv = (*ckpFunctions->C_SignRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckSignatureLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        (*env)->SetByteArrayRegion(env, jOut, jOutOfs, ckSignatureLength, (jbyte *)outBufP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   371
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
   372
    if (inBufP != INBUF) { free(inBufP); }
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
   373
    if (outBufP != OUTBUF) { free(outBufP); }
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
   374
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    return ckSignatureLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
#ifdef P11_ENABLE_C_VERIFYINIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
 * Method:    C_VerifyInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   387
 * @param   jlong jKeyHandle            CK_OBJECT_HANDLE hKey
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    CK_SESSION_HANDLE ckSessionHandle;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   393
    CK_MECHANISM_PTR ckpMechanism = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    CK_OBJECT_HANDLE ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   400
    TRACE0("DEBUG: C_VerifyInit\n");
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   401
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    ckSessionHandle = jLongToCKULong(jSessionHandle);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   403
    ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   404
    if ((*env)->ExceptionCheck(env)) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   405
        return;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   406
    }
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
   407
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    ckKeyHandle = jLongToCKULong(jKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   410
    rv = (*ckpFunctions->C_VerifyInit)(ckSessionHandle, ckpMechanism, ckKeyHandle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   412
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK ||
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   413
            (ckpMechanism->pParameter == NULL)) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   414
        freeCKMechanismPtr(ckpMechanism);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   415
    } else {
55410
c3b354fdbaa4 8225695: 32-bit build failures after JDK-8080462 (Update SunPKCS11 provider with PKCS11 v2.40 support)
shade
parents: 55332
diff changeset
   416
        (*env)->SetLongField(env, jMechanism, mech_pHandleID, ptr_to_jlong(ckpMechanism));
c3b354fdbaa4 8225695: 32-bit build failures after JDK-8080462 (Update SunPKCS11 provider with PKCS11 v2.40 support)
shade
parents: 55332
diff changeset
   417
        TRACE1("DEBUG C_VerifyInit: stored pMech = 0x%lX\n", ptr_to_jlong(ckpMechanism));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   419
    TRACE0("FINISHED\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
#ifdef P11_ENABLE_C_VERIFY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 * Method:    C_Verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 * Signature: (J[B[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
 * @param   jbyteArray jData            CK_BYTE_PTR pData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
 *                                      CK_ULONG ulDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
 * @param   jbyteArray jSignature       CK_BYTE_PTR pSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
 *                                      CK_ULONG_PTR pulSignatureLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jData, jbyteArray jSignature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    CK_BYTE_PTR ckpData = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    CK_BYTE_PTR ckpSignature = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    CK_ULONG ckDataLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    CK_ULONG ckSignatureLength;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   443
    CK_RV rv = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    ckSessionHandle = jLongToCKULong(jSessionHandle);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   449
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    jByteArrayToCKByteArray(env, jData, &ckpData, &ckDataLength);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   451
    if ((*env)->ExceptionCheck(env)) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   452
        return;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   453
    }
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
   454
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    jByteArrayToCKByteArray(env, jSignature, &ckpSignature, &ckSignatureLength);
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
   456
    if ((*env)->ExceptionCheck(env)) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   457
        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
   458
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /* verify the signature */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    rv = (*ckpFunctions->C_Verify)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, ckSignatureLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   463
cleanup:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    free(ckpData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    free(ckpSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   467
    ckAssertReturnValueOK(env, rv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
#ifdef P11_ENABLE_C_VERIFYUPDATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
 * Method:    C_VerifyUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
 * Signature: (J[BII)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
 * @param   jbyteArray jPart            CK_BYTE_PTR pPart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
 *                                      CK_ULONG ulPartLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
  (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    CK_BYTE_PTR bufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    CK_BYTE BUF[MAX_STACK_BUFFER_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    jsize bufLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    if (directIn != 0) {
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 14342
diff changeset
   496
        rv = (*ckpFunctions->C_VerifyUpdate)(ckSessionHandle, (CK_BYTE_PTR)jlong_to_ptr(directIn), jInLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        ckAssertReturnValueOK(env, rv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    if (jInLen <= MAX_STACK_BUFFER_LEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        bufLen = MAX_STACK_BUFFER_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        bufP = BUF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen);
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
   506
        bufP = (CK_BYTE_PTR) malloc((size_t)bufLen);
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
   507
        if (bufP == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   508
            throwOutOfMemoryError(env, 0);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   509
            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
   510
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    while (jInLen > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        jsize chunkLen = min(bufLen, jInLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        (*env)->GetByteArrayRegion(env, jIn, jInOfs, chunkLen, (jbyte *)bufP);
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
   516
        if ((*env)->ExceptionCheck(env)) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   517
            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
   518
        }
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
   519
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        rv = (*ckpFunctions->C_VerifyUpdate)(ckSessionHandle, bufP, chunkLen);
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
   521
        if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   522
            goto cleanup;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        jInOfs += chunkLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        jInLen -= chunkLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   528
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
   529
    if (bufP != BUF) { free(bufP); }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
#ifdef P11_ENABLE_C_VERIFYFINAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
 * Method:    C_VerifyFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
 * Signature: (J[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
 * @param   jbyteArray jSignature       CK_BYTE_PTR pSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
 *                                      CK_ULONG ulSignatureLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jSignature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    CK_BYTE_PTR ckpSignature = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    CK_ULONG ckSignatureLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    jByteArrayToCKByteArray(env, jSignature, &ckpSignature, &ckSignatureLength);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   556
    if ((*env)->ExceptionCheck(env)) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   557
        return;
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   558
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /* verify the signature */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    rv = (*ckpFunctions->C_VerifyFinal)(ckSessionHandle, ckpSignature, ckSignatureLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    free(ckpSignature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   565
    ckAssertReturnValueOK(env, rv);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
#ifdef P11_ENABLE_C_VERIFYRECOVERINIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
 * Method:    C_VerifyRecoverInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 * @return  jlong jKeyHandle            CK_OBJECT_HANDLE hKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecoverInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    CK_SESSION_HANDLE ckSessionHandle;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   583
    CK_MECHANISM_PTR ckpMechanism = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    CK_OBJECT_HANDLE ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   590
    TRACE0("DEBUG: C_VerifyRecoverInit\n");
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   591
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    ckSessionHandle = jLongToCKULong(jSessionHandle);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   593
    ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism);
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
   594
    if ((*env)->ExceptionCheck(env)) { return; }
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
   595
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    ckKeyHandle = jLongToCKULong(jKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   598
    rv = (*ckpFunctions->C_VerifyRecoverInit)(ckSessionHandle, ckpMechanism, ckKeyHandle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   600
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK ||
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   601
            (ckpMechanism->pParameter == NULL)) {
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   602
        freeCKMechanismPtr(ckpMechanism);
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   603
    } else {
55410
c3b354fdbaa4 8225695: 32-bit build failures after JDK-8080462 (Update SunPKCS11 provider with PKCS11 v2.40 support)
shade
parents: 55332
diff changeset
   604
        (*env)->SetLongField(env, jMechanism, mech_pHandleID, ptr_to_jlong(ckpMechanism));
c3b354fdbaa4 8225695: 32-bit build failures after JDK-8080462 (Update SunPKCS11 provider with PKCS11 v2.40 support)
shade
parents: 55332
diff changeset
   605
        TRACE1("DEBUG C_VerifyRecoverInit: stored pMech = 0x%lX\n", ptr_to_jlong(ckpMechanism));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   607
    TRACE0("FINISHED\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
#ifdef P11_ENABLE_C_VERIFYRECOVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
 * Method:    C_VerifyRecover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
 * Signature: (J[BII[BII)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
 * @param   jbyteArray jSignature       CK_BYTE_PTR pSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
 *                                      CK_ULONG ulSignatureLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
 * @return  jbyteArray jData            CK_BYTE_PTR pData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
 *                                      CK_ULONG_PTR pulDataLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
  (JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jIn, jint jInOfs, jint jInLen, jbyteArray jOut, jint jOutOfs, jint jOutLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    CK_BYTE INBUF[MAX_STACK_BUFFER_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    CK_BYTE OUTBUF[MAX_STACK_BUFFER_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    CK_BYTE_PTR inBufP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    CK_BYTE_PTR outBufP = OUTBUF;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   632
    CK_ULONG ckDataLength = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    if (ckpFunctions == NULL) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    if (jInLen <= MAX_STACK_BUFFER_LEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        inBufP = INBUF;
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   641
        ckDataLength = MAX_STACK_BUFFER_LEN;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    } else {
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
   643
        inBufP = (CK_BYTE_PTR) malloc((size_t)jInLen);
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
   644
        if (inBufP == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   645
            throwOutOfMemoryError(env, 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
   646
            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
   647
        }
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   648
        ckDataLength = jInLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    (*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP);
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
   652
    if ((*env)->ExceptionCheck(env)) {
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   653
        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
   654
    }
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
   655
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    rv = (*ckpFunctions->C_VerifyRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckDataLength);
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
   657
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /* re-alloc larger buffer if it fits into our Java buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    if ((rv == CKR_BUFFER_TOO_SMALL) && (ckDataLength <= jIntToCKULong(jOutLen))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        outBufP = (CK_BYTE_PTR) malloc(ckDataLength);
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
   661
        if (outBufP == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   662
            throwOutOfMemoryError(env, 0);
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   663
            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
   664
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        rv = (*ckpFunctions->C_VerifyRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckDataLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        (*env)->SetByteArrayRegion(env, jOut, jOutOfs, ckDataLength, (jbyte *)outBufP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
55332
f492567244ab 8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents: 47216
diff changeset
   671
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
   672
    if (inBufP != INBUF) { free(inBufP); }
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
   673
    if (outBufP != OUTBUF) { free(outBufP); }
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
   674
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    return ckDataLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
#endif