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