src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c
author mikael
Wed, 19 Sep 2018 09:24:40 -0700
changeset 51802 15094d12a632
parent 51800 bccd9966f1ed
child 55332 f492567244ab
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661 Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * Redistribution and use in  source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * modification, are permitted  provided that the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * 1. Redistributions of  source code must retain the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *    this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * 2. Redistributions in  binary form must reproduce the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *    this list of conditions and the following disclaimer in the documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *    and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 3. The end-user documentation included with the redistribution, if any, must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *    include the following acknowledgment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *    "This product includes software developed by IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *     Technology."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *    Alternately, this acknowledgment may appear in the software itself, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *    and wherever such third-party acknowledgments normally appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * 4. The names "Graz University of Technology" and "IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *    Technology" must not be used to endorse or promote products derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *    this software without prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * 5. Products derived from this software may not be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *    "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *    written permission of Graz University of Technology.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  POSSIBILITY  OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * pkcs11wrapper.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * 18.05.2001
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * This is the implementation of the native functions of the Java to PKCS#11 interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * All function use some helper functions to convert the JNI types to PKCS#11 types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#include "pkcs11wrapper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#include <assert.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#include "sun_security_pkcs11_wrapper_PKCS11.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
/* declare file private functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * converts a pointer to a CK_DATE structure into a Java CK_DATE Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @param ckpValue - the pointer to the CK_DATE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @return - the new Java CK_DATE object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpDate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    jclass jDateClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    jobject jDateObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    jcharArray jYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    jcharArray jMonth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    jcharArray jDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /* load CK_DATE class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    jDateClass = (*env)->FindClass(env, CLASS_DATE);
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
    92
    if (jDateClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /* load CK_DATE constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    jCtrId = (*env)->GetMethodID(env, jDateClass, "<init>", "([C[C[C)V");
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
    96
    if (jCtrId == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /* prep all fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    jYear = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->year), 4);
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
   100
    if (jYear == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jMonth = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->month), 2);
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
   102
    if (jMonth == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    jDay = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->day), 2);
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
   104
    if (jDay == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /* create new CK_DATE object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    jDateObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      (*env)->NewObject(env, jDateClass, jCtrId, jYear, jMonth, jDay);
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
   109
    if (jDateObject == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    (*env)->DeleteLocalRef(env, jDateClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    (*env)->DeleteLocalRef(env, jYear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    (*env)->DeleteLocalRef(env, jMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    (*env)->DeleteLocalRef(env, jDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    return jDateObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * converts a pointer to a CK_VERSION structure into a Java CK_VERSION Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * @param ckpVersion - the pointer to the CK_VERSION structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * @return - the new Java CK_VERSION object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    jclass jVersionClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    jobject jVersionObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    jint jMajor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    jint jMinor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /* load CK_VERSION class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    jVersionClass = (*env)->FindClass(env, CLASS_VERSION);
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
   137
    if (jVersionClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /* load CK_VERSION constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    jCtrId = (*env)->GetMethodID(env, jVersionClass, "<init>", "(II)V");
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
   141
    if (jCtrId == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /* prep both fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    jMajor = ckpVersion->major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    jMinor = ckpVersion->minor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /* create new CK_VERSION object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    jVersionObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      (*env)->NewObject(env, jVersionClass, jCtrId, jMajor, jMinor);
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
   150
    if (jVersionObject == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    (*env)->DeleteLocalRef(env, jVersionClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    return jVersionObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * converts a pointer to a CK_SESSION_INFO structure into a Java CK_SESSION_INFO Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * @param ckpSessionInfo - the pointer to the CK_SESSION_INFO structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * @return - the new Java CK_SESSION_INFO object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    jclass jSessionInfoClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    jobject jSessionInfoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    jlong jSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    jlong jState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    jlong jFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    jlong jDeviceError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /* load CK_SESSION_INFO class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    jSessionInfoClass = (*env)->FindClass(env, CLASS_SESSION_INFO);
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
   177
    if (jSessionInfoClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /* load CK_SESSION_INFO constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    jCtrId = (*env)->GetMethodID(env, jSessionInfoClass, "<init>", "(JJJJ)V");
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
   181
    if (jCtrId == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /* prep all fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    jSlotID = ckULongToJLong(ckpSessionInfo->slotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    jState = ckULongToJLong(ckpSessionInfo->state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    jFlags = ckULongToJLong(ckpSessionInfo->flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    jDeviceError = ckULongToJLong(ckpSessionInfo->ulDeviceError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /* create new CK_SESSION_INFO object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    jSessionInfoObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      (*env)->NewObject(env, jSessionInfoClass, jCtrId, jSlotID, jState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        jFlags, jDeviceError);
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
   193
    if (jSessionInfoObject == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    (*env)->DeleteLocalRef(env, jSessionInfoClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    return jSessionInfoObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * converts a pointer to a CK_ATTRIBUTE structure into a Java CK_ATTRIBUTE Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * @return - the new Java CK_ATTRIBUTE object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    jclass jAttributeClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    jobject jAttributeObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    jlong jType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    jobject jPValue = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    jAttributeClass = (*env)->FindClass(env, CLASS_ATTRIBUTE);
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 (jAttributeClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /* load CK_INFO constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    jCtrId = (*env)->GetMethodID(env, jAttributeClass, "<init>", "(JLjava/lang/Object;)V");
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 (jCtrId == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /* prep both fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    jType = ckULongToJLong(ckpAttribute->type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    jPValue = ckAttributeValueToJObject(env, ckpAttribute);
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 ((*env)->ExceptionCheck(env)) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /* create new CK_ATTRIBUTE object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    jAttributeObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      (*env)->NewObject(env, jAttributeClass, jCtrId, jType, jPValue);
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
   231
    if (jAttributeObject == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    (*env)->DeleteLocalRef(env, jAttributeClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    (*env)->DeleteLocalRef(env, jPValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    return jAttributeObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * converts a Java CK_VERSION object into a pointer to a CK_VERSION structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * @param jVersion - the Java CK_VERSION object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * @return - the pointer to the new CK_VERSION structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    CK_VERSION_PTR ckpVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    jclass jVersionClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    jfieldID jFieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    jbyte jMajor, jMinor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    if (jVersion == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /* get CK_VERSION class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    jVersionClass = (*env)->GetObjectClass(env, jVersion);
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
   261
    if (jVersionClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /* get Major */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    jFieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B");
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 (jFieldID == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    jMajor = (*env)->GetByteField(env, jVersion, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /* get Minor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    jFieldID = (*env)->GetFieldID(env, jVersionClass, "minor", "B");
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
   270
    if (jFieldID == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    jMinor = (*env)->GetByteField(env, jVersion, jFieldID);
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
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
    /* allocate memory for CK_VERSION pointer */
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
    ckpVersion = (CK_VERSION_PTR) malloc(sizeof(CK_VERSION));
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
    if (ckpVersion == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   276
        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
   277
        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
   278
    }
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
   279
    ckpVersion->major = jByteToCKByte(jMajor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    ckpVersion->minor = jByteToCKByte(jMinor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    return ckpVersion ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * converts a Java CK_DATE object into a pointer to a CK_DATE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * @param jVersion - the Java CK_DATE object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * @return - the pointer to the new CK_DATE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    CK_DATE * ckpDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    CK_ULONG ckLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    jclass jDateClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    jfieldID jFieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    jobject jYear, jMonth, jDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    jchar *jTempChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
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
   303
    if (jDate == 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
   304
        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
   305
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /* get CK_DATE class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    jDateClass = (*env)->FindClass(env, CLASS_DATE);
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
   309
    if (jDateClass == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /* get Year */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    jFieldID = (*env)->GetFieldID(env, jDateClass, "year", "[C");
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
   313
    if (jFieldID == NULL) { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    jYear = (*env)->GetObjectField(env, jDate, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
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
   316
    /* get Month */
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
    jFieldID = (*env)->GetFieldID(env, jDateClass, "month", "[C");
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
   318
    if (jFieldID == NULL) { 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
   319
    jMonth = (*env)->GetObjectField(env, jDate, jFieldID);
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
   320
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
   321
    /* get Day */
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
   322
    jFieldID = (*env)->GetFieldID(env, jDateClass, "day", "[C");
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
   323
    if (jFieldID == NULL) { 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
   324
    jDay = (*env)->GetObjectField(env, jDate, jFieldID);
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
   325
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   326
    /* allocate memory for CK_DATE pointer */
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
   327
    ckpDate = (CK_DATE *) malloc(sizeof(CK_DATE));
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
   328
    if (ckpDate == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   329
        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
   330
        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
   331
    }
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
   332
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    if (jYear == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        ckpDate->year[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        ckpDate->year[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        ckpDate->year[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        ckpDate->year[3] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        ckLength = (*env)->GetArrayLength(env, jYear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
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
   341
        if (jTempChars == 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
   342
            free(ckpDate);
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   343
            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
   344
            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
   345
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        (*env)->GetCharArrayRegion(env, jYear, 0, ckLength, jTempChars);
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
   347
        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
   348
            free(ckpDate);
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
            free(jTempChars);
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
   350
            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
   351
        }
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
   352
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        for (i = 0; (i < ckLength) && (i < 4) ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            ckpDate->year[i] = jCharToCKChar(jTempChars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        free(jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    if (jMonth == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        ckpDate->month[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        ckpDate->month[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        ckLength = (*env)->GetArrayLength(env, jMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
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
        if (jTempChars == 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
   366
            free(ckpDate);
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   367
            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
   368
            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
   369
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        (*env)->GetCharArrayRegion(env, jMonth, 0, ckLength, jTempChars);
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
   371
        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
   372
            free(ckpDate);
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
            free(jTempChars);
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
            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
   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
11356
898d37526be1 6839886: Array overrun in pkcs11
valeriep
parents: 10798
diff changeset
   377
        for (i = 0; (i < ckLength) && (i < 2) ; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            ckpDate->month[i] = jCharToCKChar(jTempChars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        free(jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    if (jDay == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        ckpDate->day[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        ckpDate->day[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        ckLength = (*env)->GetArrayLength(env, jDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
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
   389
        if (jTempChars == 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
   390
            free(ckpDate);
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   391
            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
   392
            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
   393
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        (*env)->GetCharArrayRegion(env, jDay, 0, ckLength, jTempChars);
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
   395
        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
   396
            free(ckpDate);
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
   397
            free(jTempChars);
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
   398
            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
   399
        }
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
   400
11356
898d37526be1 6839886: Array overrun in pkcs11
valeriep
parents: 10798
diff changeset
   401
        for (i = 0; (i < ckLength) && (i < 2) ; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            ckpDate->day[i] = jCharToCKChar(jTempChars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        free(jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    return ckpDate ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
 * converts a Java CK_ATTRIBUTE object into a CK_ATTRIBUTE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
 * @param jAttribute - the Java CK_ATTRIBUTE object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
 * @return - the new CK_ATTRIBUTE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    CK_ATTRIBUTE ckAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    jclass jAttributeClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    jfieldID jFieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    jlong jType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    jobject jPValue;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 11356
diff changeset
   425
    memset(&ckAttribute, 0, sizeof(CK_ATTRIBUTE));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
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
   427
    // TBD: what if jAttribute == 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
   428
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    TRACE0("\nDEBUG: jAttributeToCKAttribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /* get CK_ATTRIBUTE class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    TRACE0(", getting attribute object class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    jAttributeClass = (*env)->GetObjectClass(env, jAttribute);
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
   433
    if (jAttributeClass == NULL) { return ckAttribute; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /* get type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    TRACE0(", getting type field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    jFieldID = (*env)->GetFieldID(env, jAttributeClass, "type", "J");
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
   438
    if (jFieldID == NULL) { return ckAttribute; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    jType = (*env)->GetLongField(env, jAttribute, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    TRACE1(", type=0x%X", jType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /* get pValue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    TRACE0(", getting pValue field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    jFieldID = (*env)->GetFieldID(env, jAttributeClass, "pValue", "Ljava/lang/Object;");
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
   445
    if (jFieldID == NULL) { return ckAttribute; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    jPValue = (*env)->GetObjectField(env, jAttribute, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    TRACE1(", pValue=%p", jPValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    ckAttribute.type = jLongToCKULong(jType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    TRACE0(", converting pValue to primitive object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /* convert the Java pValue object to a CK-type pValue pointer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    jObjectToPrimitiveCKObjectPtrPtr(env, jPValue, &(ckAttribute.pValue), &(ckAttribute.ulValueLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    TRACE0("\nFINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    return ckAttribute ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   460
void masterKeyDeriveParamToCKMasterKeyDeriveParam(JNIEnv *env, jobject jParam,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   461
        jclass masterKeyDeriveParamClass,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   462
        CK_VERSION_PTR* cKMasterKeyDeriveParamVersion,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   463
        CK_SSL3_RANDOM_DATA* cKMasterKeyDeriveParamRandomInfo) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    jclass jSsl3RandomDataClass;
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
   466
    jobject jRandomInfo, jRIClientRandom, jRIServerRandom, jVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /* get RandomInfo */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   469
    fieldID = (*env)->GetFieldID(env, masterKeyDeriveParamClass, "RandomInfo",
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   470
            "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   471
    if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /* get pClientRandom and ulClientRandomLength out of RandomInfo */
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
   475
    jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA);
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   476
    if (jSsl3RandomDataClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B");
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   478
    if (fieldID == NULL) { return; }
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
   479
    jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /* get pServerRandom and ulServerRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B");
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   483
    if (fieldID == NULL) { return; }
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
   484
    jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /* get pVersion */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   487
    fieldID = (*env)->GetFieldID(env, masterKeyDeriveParamClass, "pVersion",
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   488
            "Lsun/security/pkcs11/wrapper/CK_VERSION;");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   489
    if (fieldID == NULL) { return; }
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
   490
    jVersion = (*env)->GetObjectField(env, jParam, fieldID);
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
   491
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
   492
    /* populate java values */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   493
    *cKMasterKeyDeriveParamVersion = jVersionToCKVersionPtr(env, jVersion);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   494
    if ((*env)->ExceptionCheck(env)) { return; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   495
    jByteArrayToCKByteArray(env, jRIClientRandom,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   496
            &(cKMasterKeyDeriveParamRandomInfo->pClientRandom),
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   497
            &(cKMasterKeyDeriveParamRandomInfo->ulClientRandomLen));
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
   498
    if ((*env)->ExceptionCheck(env)) {
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   499
        free(*cKMasterKeyDeriveParamVersion);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   500
        return;
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
   501
    }
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   502
    jByteArrayToCKByteArray(env, jRIServerRandom,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   503
            &(cKMasterKeyDeriveParamRandomInfo->pServerRandom),
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   504
            &(cKMasterKeyDeriveParamRandomInfo->ulServerRandomLen));
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
   505
    if ((*env)->ExceptionCheck(env)) {
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   506
        free(*cKMasterKeyDeriveParamVersion);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   507
        free(cKMasterKeyDeriveParamRandomInfo->pClientRandom);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   508
        return;
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
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   512
/*
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   513
 * converts the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to a
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   514
 * CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   515
 *
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   516
 * @param env - used to call JNI functions to get the Java classes and objects
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   517
 * @param jParam - the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to convert
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   518
 * @return - the new CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   519
 */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   520
CK_SSL3_MASTER_KEY_DERIVE_PARAMS
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   521
jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(JNIEnv *env,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   522
        jobject jParam)
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   523
{
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   524
    CK_SSL3_MASTER_KEY_DERIVE_PARAMS ckParam;
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   525
    jclass jSsl3MasterKeyDeriveParamsClass;
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   526
    memset(&ckParam, 0, sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS));
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   527
    jSsl3MasterKeyDeriveParamsClass =
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   528
            (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   529
    if (jSsl3MasterKeyDeriveParamsClass == NULL) { return ckParam; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   530
    masterKeyDeriveParamToCKMasterKeyDeriveParam(env, jParam,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   531
            jSsl3MasterKeyDeriveParamsClass,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   532
            &ckParam.pVersion, &ckParam.RandomInfo);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   533
    return ckParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   534
}
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   535
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   536
/*
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   537
 * converts the Java CK_TLS12_MASTER_KEY_DERIVE_PARAMS object to a
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   538
 * CK_TLS12_MASTER_KEY_DERIVE_PARAMS structure
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   539
 *
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   540
 * @param env - used to call JNI functions to get the Java classes and objects
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   541
 * @param jParam - the Java CK_TLS12_MASTER_KEY_DERIVE_PARAMS object to convert
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   542
 * @return - the new CK_TLS12_MASTER_KEY_DERIVE_PARAMS structure
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   543
 */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   544
CK_TLS12_MASTER_KEY_DERIVE_PARAMS
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   545
jTls12MasterKeyDeriveParamToCKTls12MasterKeyDeriveParam(JNIEnv *env,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   546
        jobject jParam)
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   547
{
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   548
    CK_TLS12_MASTER_KEY_DERIVE_PARAMS ckParam;
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   549
    jclass jTls12MasterKeyDeriveParamsClass;
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   550
    jfieldID fieldID;
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   551
    memset(&ckParam, 0, sizeof(CK_TLS12_MASTER_KEY_DERIVE_PARAMS));
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   552
    jTls12MasterKeyDeriveParamsClass =
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   553
            (*env)->FindClass(env, CLASS_TLS12_MASTER_KEY_DERIVE_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   554
    if (jTls12MasterKeyDeriveParamsClass == NULL) { return ckParam; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   555
    masterKeyDeriveParamToCKMasterKeyDeriveParam(env, jParam,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   556
            jTls12MasterKeyDeriveParamsClass, &ckParam.pVersion,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   557
            &ckParam.RandomInfo);
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   558
    fieldID = (*env)->GetFieldID(env,
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   559
            jTls12MasterKeyDeriveParamsClass, "prfHashMechanism", "J");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   560
    if (fieldID != NULL) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   561
        jlong prfHashMechanism =
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   562
                (*env)->GetLongField(env, jParam, fieldID);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   563
        ckParam.prfHashMechanism = (CK_MECHANISM_TYPE)prfHashMechanism;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   564
    }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   565
    return ckParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   566
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
 * converts the Java CK_TLS_PRF_PARAMS object to a CK_TLS_PRF_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
CK_TLS_PRF_PARAMS jTlsPrfParamsToCKTlsPrfParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
{
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
   573
    jclass jTlsPrfParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    CK_TLS_PRF_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    jfieldID fieldID;
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
   576
    jobject jSeed, jLabel, jOutput;
32094
bebc489aace3 8132551: Initialize local varibales before returning them in p11_convert.c
simonis
parents: 25859
diff changeset
   577
    memset(&ckParam, 0, sizeof(CK_TLS_PRF_PARAMS));
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
   578
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
   579
    // TBD: what if jParam == NULL?!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
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
   581
    /* get pSeed */
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
   582
    jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS);
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
   583
    if (jTlsPrfParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pSeed", "[B");
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
   585
    if (fieldID == NULL) { return ckParam; }
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
   586
    jSeed = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
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
   588
    /* get pLabel */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pLabel", "[B");
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
   590
    if (fieldID == NULL) { return ckParam; }
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
   591
    jLabel = (*env)->GetObjectField(env, jParam, fieldID);
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
   592
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
   593
    /* get pOutput */
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
    fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pOutput", "[B");
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
    if (fieldID == NULL) { return ckParam; }
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
   596
    jOutput = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
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
   598
    /* populate java values */
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
   599
    jByteArrayToCKByteArray(env, jSeed, &(ckParam.pSeed), &(ckParam.ulSeedLen));
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 ((*env)->ExceptionCheck(env)) { return ckParam; }
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
   601
    jByteArrayToCKByteArray(env, jLabel, &(ckParam.pLabel), &(ckParam.ulLabelLen));
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
   602
    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
   603
        free(ckParam.pSeed);
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
        return ckParam;
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
   605
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    ckParam.pulOutputLen = malloc(sizeof(CK_ULONG));
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
   607
    if (ckParam.pulOutputLen == 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
   608
        free(ckParam.pSeed);
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
   609
        free(ckParam.pLabel);
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   610
        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
   611
        return ckParam;
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
   612
    }
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
   613
    jByteArrayToCKByteArray(env, jOutput, &(ckParam.pOutput), ckParam.pulOutputLen);
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
   614
    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
   615
        free(ckParam.pSeed);
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
   616
        free(ckParam.pLabel);
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
   617
        free(ckParam.pulOutputLen);
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
   618
        return ckParam;
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
   619
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
/*
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   625
 * converts the Java CK_TLS_MAC_PARAMS object to a CK_TLS_MAC_PARAMS structure
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   627
CK_TLS_MAC_PARAMS jTlsMacParamsToCKTlsMacParam(JNIEnv *env, jobject jParam)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
{
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   629
    jclass jTlsMacParamsClass;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   630
    CK_TLS_MAC_PARAMS ckParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   631
    jfieldID fieldID;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   632
    jlong jPrfMechanism, jUlMacLength, jUlServerOrClient;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   633
    memset(&ckParam, 0, sizeof(CK_TLS_MAC_PARAMS));
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   634
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   635
    jTlsMacParamsClass = (*env)->FindClass(env, CLASS_TLS_MAC_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   636
    if (jTlsMacParamsClass == NULL) { return ckParam; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   637
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   638
    /* get prfMechanism */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   639
    fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "prfMechanism", "J");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   640
    if (fieldID == NULL) { return ckParam; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   641
    jPrfMechanism = (*env)->GetLongField(env, jParam, fieldID);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   642
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   643
    /* get ulMacLength */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   644
    fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "ulMacLength", "J");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   645
    if (fieldID == NULL) { return ckParam; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   646
    jUlMacLength = (*env)->GetLongField(env, jParam, fieldID);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   647
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   648
    /* get ulServerOrClient */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   649
    fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "ulServerOrClient", "J");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   650
    if (fieldID == NULL) { return ckParam; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   651
    jUlServerOrClient = (*env)->GetLongField(env, jParam, fieldID);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   652
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   653
    /* populate java values */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   654
    ckParam.prfMechanism = jLongToCKULong(jPrfMechanism);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   655
    ckParam.ulMacLength = jLongToCKULong(jUlMacLength);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   656
    ckParam.ulServerOrClient = jLongToCKULong(jUlServerOrClient);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   657
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   658
    return ckParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   659
}
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   660
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   661
void keyMatParamToCKKeyMatParam(JNIEnv *env, jobject jParam,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   662
        jclass jKeyMatParamClass,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   663
        CK_ULONG* cKKeyMatParamUlMacSizeInBits,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   664
        CK_ULONG* cKKeyMatParamUlKeySizeInBits,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   665
        CK_ULONG* cKKeyMatParamUlIVSizeInBits,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   666
        CK_BBOOL* cKKeyMatParamBIsExport,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   667
        CK_SSL3_RANDOM_DATA* cKKeyMatParamRandomInfo,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   668
        CK_SSL3_KEY_MAT_OUT_PTR* cKKeyMatParamPReturnedKeyMaterial)
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   669
{
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   670
    jclass jSsl3RandomDataClass, jSsl3KeyMatOutClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    jfieldID fieldID;
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
    jlong jMacSizeInBits, jKeySizeInBits, jIVSizeInBits;
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
    jboolean jIsExport;
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
    jobject jRandomInfo, jRIClientRandom, jRIServerRandom;
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
   675
    jobject jReturnedKeyMaterial, jRMIvClient, jRMIvServer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    CK_ULONG ckTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /* get ulMacSizeInBits */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   679
    fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulMacSizeInBits", "J");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   680
    if (fieldID == NULL) { return; }
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
   681
    jMacSizeInBits = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /* get ulKeySizeInBits */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   684
    fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulKeySizeInBits", "J");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   685
    if (fieldID == NULL) { return; }
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
   686
    jKeySizeInBits = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /* get ulIVSizeInBits */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   689
    fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulIVSizeInBits", "J");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   690
    if (fieldID == NULL) { return; }
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
   691
    jIVSizeInBits = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /* get bIsExport */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   694
    fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "bIsExport", "Z");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   695
    if (fieldID == NULL) { return; }
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
   696
    jIsExport = (*env)->GetBooleanField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /* get RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA);
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   700
    if (jSsl3RandomDataClass == NULL) { return; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   701
    fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "RandomInfo",
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   702
            "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   703
    if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    /* get pClientRandom and ulClientRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B");
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   708
    if (fieldID == NULL) { return; }
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
   709
    jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    /* get pServerRandom and ulServerRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B");
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   713
    if (fieldID == NULL) { return; }
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
   714
    jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /* get pReturnedKeyMaterial */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    jSsl3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT);
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   718
    if (jSsl3KeyMatOutClass == NULL) { return; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   719
    fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "pReturnedKeyMaterial",
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   720
            "Lsun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT;");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   721
    if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    jReturnedKeyMaterial = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
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
   724
    /* get pIVClient out of pReturnedKeyMaterial */
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
   725
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVClient", "[B");
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   726
    if (fieldID == NULL) { return; }
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
   727
    jRMIvClient = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID);
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
   728
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
   729
    /* get pIVServer out of pReturnedKeyMaterial */
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
   730
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVServer", "[B");
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   731
    if (fieldID == NULL) { return; }
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
   732
    jRMIvServer = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID);
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
   733
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
   734
    /* populate java values */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   735
    *cKKeyMatParamUlMacSizeInBits = jLongToCKULong(jMacSizeInBits);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   736
    *cKKeyMatParamUlKeySizeInBits = jLongToCKULong(jKeySizeInBits);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   737
    *cKKeyMatParamUlIVSizeInBits = jLongToCKULong(jIVSizeInBits);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   738
    *cKKeyMatParamBIsExport = jBooleanToCKBBool(jIsExport);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   739
    jByteArrayToCKByteArray(env, jRIClientRandom,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   740
            &(cKKeyMatParamRandomInfo->pClientRandom),
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   741
            &(cKKeyMatParamRandomInfo->ulClientRandomLen));
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   742
    if ((*env)->ExceptionCheck(env)) { return; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   743
    jByteArrayToCKByteArray(env, jRIServerRandom,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   744
            &(cKKeyMatParamRandomInfo->pServerRandom),
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   745
            &(cKKeyMatParamRandomInfo->ulServerRandomLen));
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
   746
    if ((*env)->ExceptionCheck(env)) {
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   747
        free(cKKeyMatParamRandomInfo->pClientRandom);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   748
        return;
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
   749
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    /* allocate memory for pRetrunedKeyMaterial */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   751
    *cKKeyMatParamPReturnedKeyMaterial =
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   752
            (CK_SSL3_KEY_MAT_OUT_PTR)malloc(sizeof(CK_SSL3_KEY_MAT_OUT));
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   753
    if (*cKKeyMatParamPReturnedKeyMaterial == NULL) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   754
        free(cKKeyMatParamRandomInfo->pClientRandom);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   755
        free(cKKeyMatParamRandomInfo->pServerRandom);
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   756
        throwOutOfMemoryError(env, 0);
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   757
        return;
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
   758
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    // the handles are output params only, no need to fetch them from Java
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   761
    (*cKKeyMatParamPReturnedKeyMaterial)->hClientMacSecret = 0;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   762
    (*cKKeyMatParamPReturnedKeyMaterial)->hServerMacSecret = 0;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   763
    (*cKKeyMatParamPReturnedKeyMaterial)->hClientKey = 0;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   764
    (*cKKeyMatParamPReturnedKeyMaterial)->hServerKey = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   766
    jByteArrayToCKByteArray(env, jRMIvClient,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   767
            &((*cKKeyMatParamPReturnedKeyMaterial)->pIVClient), &ckTemp);
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
   768
    if ((*env)->ExceptionCheck(env)) {
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   769
        free(cKKeyMatParamRandomInfo->pClientRandom);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   770
        free(cKKeyMatParamRandomInfo->pServerRandom);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   771
        free((*cKKeyMatParamPReturnedKeyMaterial));
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   772
        return;
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
   773
    }
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   774
    jByteArrayToCKByteArray(env, jRMIvServer,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   775
            &((*cKKeyMatParamPReturnedKeyMaterial)->pIVServer), &ckTemp);
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
   776
    if ((*env)->ExceptionCheck(env)) {
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   777
        free(cKKeyMatParamRandomInfo->pClientRandom);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   778
        free(cKKeyMatParamRandomInfo->pServerRandom);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   779
        free((*cKKeyMatParamPReturnedKeyMaterial)->pIVClient);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   780
        free((*cKKeyMatParamPReturnedKeyMaterial));
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   781
        return;
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
   782
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   784
    return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   785
}
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   786
/*
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   787
 * converts the Java CK_SSL3_KEY_MAT_PARAMS object to a
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   788
 * CK_SSL3_KEY_MAT_PARAMS structure
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   789
 *
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   790
 * @param env - used to call JNI funktions to get the Java classes and objects
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   791
 * @param jParam - the Java CK_SSL3_KEY_MAT_PARAMS object to convert
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   792
 * @return - the new CK_SSL3_KEY_MAT_PARAMS structure
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   793
 */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   794
CK_SSL3_KEY_MAT_PARAMS
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   795
jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject jParam)
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   796
{
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   797
    CK_SSL3_KEY_MAT_PARAMS ckParam;
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   798
    jclass jSsl3KeyMatParamsClass;
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   799
    memset(&ckParam, 0, sizeof(CK_SSL3_KEY_MAT_PARAMS));
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   800
    jSsl3KeyMatParamsClass = (*env)->FindClass(env,
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   801
            CLASS_SSL3_KEY_MAT_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   802
    if (jSsl3KeyMatParamsClass == NULL) { return ckParam; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   803
    keyMatParamToCKKeyMatParam(env, jParam, jSsl3KeyMatParamsClass,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   804
            &ckParam.ulMacSizeInBits, &ckParam.ulKeySizeInBits,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   805
            &ckParam.ulIVSizeInBits, &ckParam.bIsExport,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   806
            &ckParam.RandomInfo, &ckParam.pReturnedKeyMaterial);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   807
    return ckParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   808
}
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   809
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   810
/*
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   811
 * converts the Java CK_TLS12_KEY_MAT_PARAMS object to a
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   812
 * CK_TLS12_KEY_MAT_PARAMS structure
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   813
 *
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   814
 * @param env - used to call JNI functions to get the Java classes and objects
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   815
 * @param jParam - the Java CK_TLS12_KEY_MAT_PARAMS object to convert
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   816
 * @return - the new CK_TLS12_KEY_MAT_PARAMS structure
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   817
 */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   818
CK_TLS12_KEY_MAT_PARAMS jTls12KeyMatParamToCKTls12KeyMatParam(JNIEnv *env,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   819
        jobject jParam)
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   820
{
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   821
    CK_TLS12_KEY_MAT_PARAMS ckParam;
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   822
    jclass jTls12KeyMatParamsClass;
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   823
    jfieldID fieldID;
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   824
    memset(&ckParam, 0, sizeof(CK_TLS12_KEY_MAT_PARAMS));
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   825
    jTls12KeyMatParamsClass = (*env)->FindClass(env,
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   826
            CLASS_TLS12_KEY_MAT_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   827
    if (jTls12KeyMatParamsClass == NULL) { return ckParam; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   828
    keyMatParamToCKKeyMatParam(env, jParam, jTls12KeyMatParamsClass,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   829
            &ckParam.ulMacSizeInBits, &ckParam.ulKeySizeInBits,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   830
            &ckParam.ulIVSizeInBits, &ckParam.bIsExport,
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   831
            &ckParam.RandomInfo, &ckParam.pReturnedKeyMaterial);
51802
15094d12a632 8210912: Build error in src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c after JDK-8029661
mikael
parents: 51800
diff changeset
   832
    fieldID = (*env)->GetFieldID(env, jTls12KeyMatParamsClass,
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   833
            "prfHashMechanism", "J");
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   834
    if (fieldID != NULL) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   835
        jlong prfHashMechanism = (*env)->GetLongField(env, jParam, fieldID);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   836
        ckParam.prfHashMechanism = (CK_MECHANISM_TYPE)prfHashMechanism;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   837
    }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
   838
    return ckParam;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
/*
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   842
 * converts the Java CK_AES_CTR_PARAMS object to a CK_AES_CTR_PARAMS structure
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   843
 *
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   844
 * @param env - used to call JNI funktions to get the Java classes and objects
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   845
 * @param jParam - the Java CK_AES_CTR_PARAMS object to convert
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   846
 * @param ckpParam - pointer to the new CK_AES_CTR_PARAMS structure
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   847
 */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   848
void jAesCtrParamsToCKAesCtrParam(JNIEnv *env, jobject jParam,
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   849
                                  CK_AES_CTR_PARAMS_PTR ckpParam) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   850
    jclass jAesCtrParamsClass;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   851
    jfieldID fieldID;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   852
    jlong jCounterBits;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   853
    jobject jCb;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   854
    CK_BYTE_PTR ckBytes;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   855
    CK_ULONG ckTemp;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   856
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   857
    /* get ulCounterBits */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   858
    jAesCtrParamsClass = (*env)->FindClass(env, CLASS_AES_CTR_PARAMS);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   859
    if (jAesCtrParamsClass == NULL) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   860
    fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "ulCounterBits", "J");
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   861
    if (fieldID == NULL) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   862
    jCounterBits = (*env)->GetLongField(env, jParam, fieldID);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   863
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   864
    /* get cb */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   865
    fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "cb", "[B");
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   866
    if (fieldID == NULL) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   867
    jCb = (*env)->GetObjectField(env, jParam, fieldID);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   868
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   869
    /* populate java values */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   870
    ckpParam->ulCounterBits = jLongToCKULong(jCounterBits);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   871
    jByteArrayToCKByteArray(env, jCb, &ckBytes, &ckTemp);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   872
    if ((*env)->ExceptionCheck(env)) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   873
    if (ckTemp != 16) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   874
        TRACE1("ERROR: WRONG CTR IV LENGTH %d", ckTemp);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   875
    } else {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   876
        memcpy(ckpParam->cb, ckBytes, ckTemp);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   877
        free(ckBytes);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   878
    }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   879
}
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   880
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   881
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
 * converts a Java CK_MECHANISM object into a CK_MECHANISM structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
 * @param jMechanism - the Java CK_MECHANISM object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
 * @return - the new CK_MECHANISM structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
void jMechanismToCKMechanism(JNIEnv *env, jobject jMechanism, CK_MECHANISM_PTR ckMechanismPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    jlong jMechanismType = (*env)->GetLongField(env, jMechanism, mech_mechanismID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    jobject jParameter = (*env)->GetObjectField(env, jMechanism, mech_pParameterID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    (*ckMechanismPtr).mechanism = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    /* convert the specific Java mechanism parameter object to a pointer to a CK-type mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    if (jParameter == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        (*ckMechanismPtr).pParameter = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        (*ckMechanismPtr).ulParameterLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        jMechanismParameterToCKMechanismParameter(env, jParameter, &(*ckMechanismPtr).pParameter, &(*ckMechanismPtr).ulParameterLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
 * the following functions convert Attribute and Mechanism value pointers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
 * jobject ckAttributeValueToJObject(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
 *                                   const CK_ATTRIBUTE_PTR ckpAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
 * void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
 *                                       jobject jObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
 *                                       CK_VOID_PTR *ckpObjectPtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
 *                                       CK_ULONG *pLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
 * void jMechanismParameterToCKMechanismParameter(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
 *                                                jobject jParam,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
 *                                                CK_VOID_PTR *ckpParamPtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
 *                                                CK_ULONG *ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
 * These functions are used if a PKCS#11 mechanism or attribute structure gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
 * convertet to a Java attribute or mechanism object or vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
 * ckAttributeValueToJObject converts a PKCS#11 attribute value pointer to a Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
 * object depending on the type of the Attribute. A PKCS#11 attribute value can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
 * be a CK_ULONG, CK_BYTE[], CK_CHAR[], big integer, CK_BBOOL, CK_UTF8CHAR[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
 * CK_DATE or CK_FLAGS that gets converted to a corresponding Java object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
 * jObjectToPrimitiveCKObjectPtrPtr is used by jAttributeToCKAttributePtr for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
 * converting the Java attribute value to a PKCS#11 attribute value pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
 * For now only primitive datatypes and arrays of primitive datatypes can get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
 * converted. Otherwise this function throws a PKCS#11Exception with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
 * errorcode CKR_VENDOR_DEFINED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
 * jMechanismParameterToCKMechanismParameter converts a Java mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
 * to a PKCS#11 mechanism parameter. First this function determines what mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
 * parameter the Java object is, then it allocates the memory for the new PKCS#11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
 * structure and calls the corresponding function to convert the Java object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
 * a PKCS#11 mechanism parameter structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
 * converts the pValue of a CK_ATTRIBUTE structure into a Java Object by checking the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
 * of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
 * @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure that contains the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
 *                       and the pValue to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
 * @return - the new Java object of the CK-type pValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    jint jValueLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    jobject jValueObject = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    jValueLength = ckULongToJInt(ckpAttribute->ulValueLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    if ((jValueLength <= 0) || (ckpAttribute->pValue == NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        return NULL ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    switch(ckpAttribute->type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        case CKA_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            /* value CK_OBJECT_CLASS, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        case CKA_KEY_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            /* value CK_KEY_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        case CKA_CERTIFICATE_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            /* value CK_CERTIFICATE_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        case CKA_HW_FEATURE_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            /* value CK_HW_FEATURE_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        case CKA_MODULUS_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        case CKA_VALUE_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        case CKA_VALUE_LEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        case CKA_KEY_GEN_MECHANISM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        case CKA_PRIME_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        case CKA_SUB_PRIME_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            /* value CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            /* can be CK_BYTE[],CK_CHAR[] or big integer; defacto always CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        case CKA_VALUE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        case CKA_OBJECT_ID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        case CKA_SUBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        case CKA_ID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        case CKA_ISSUER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        case CKA_SERIAL_NUMBER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        case CKA_OWNER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        case CKA_AC_ISSUER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        case CKA_ATTR_TYPES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        case CKA_ECDSA_PARAMS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            /* CKA_EC_PARAMS is the same, these two are equivalent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        case CKA_EC_POINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        case CKA_PRIVATE_EXPONENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        case CKA_PRIME_1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        case CKA_PRIME_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        case CKA_EXPONENT_1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        case CKA_EXPONENT_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        case CKA_COEFFICIENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            /* value CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        case CKA_RESET_ON_INIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        case CKA_HAS_RESET:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        case CKA_TOKEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        case CKA_PRIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        case CKA_MODIFIABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        case CKA_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        case CKA_LOCAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        case CKA_ENCRYPT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        case CKA_VERIFY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        case CKA_VERIFY_RECOVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        case CKA_WRAP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        case CKA_SENSITIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        case CKA_SECONDARY_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        case CKA_DECRYPT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        case CKA_SIGN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        case CKA_SIGN_RECOVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        case CKA_UNWRAP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        case CKA_EXTRACTABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        case CKA_ALWAYS_SENSITIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        case CKA_NEVER_EXTRACTABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        case CKA_TRUSTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            /* value CK_BBOOL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            jValueObject = ckBBoolPtrToJBooleanObject(env, (CK_BBOOL*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        case CKA_LABEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        case CKA_APPLICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            /* value RFC 2279 (UTF-8) string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            jValueObject = ckUTF8CharArrayToJCharArray(env, (CK_UTF8CHAR*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        case CKA_START_DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        case CKA_END_DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            /* value CK_DATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            jValueObject = ckDatePtrToJDateObject(env, (CK_DATE*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        case CKA_MODULUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        case CKA_PUBLIC_EXPONENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        case CKA_PRIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        case CKA_SUBPRIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        case CKA_BASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            /* value big integer, i.e. CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        case CKA_AUTH_PIN_FLAGS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            /* value FLAGS, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        case CKA_VENDOR_DEFINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            /* we make a CK_BYTE[] out of this */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        // Netscape trust attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        case CKA_NETSCAPE_TRUST_SERVER_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        case CKA_NETSCAPE_TRUST_CLIENT_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        case CKA_NETSCAPE_TRUST_CODE_SIGNING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        case CKA_NETSCAPE_TRUST_EMAIL_PROTECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            /* value CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            /* we make a CK_BYTE[] out of this */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    return jValueObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
 * the following functions convert a Java mechanism parameter object to a PKCS#11
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
 * mechanism parameter structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
 * CK_<Param>_PARAMS j<Param>ParamToCK<Param>Param(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
 *                                                 jobject jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
 * These functions get a Java object, that must be the right Java mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
 * object and they return the new PKCS#11 mechanism parameter structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
 * Every field of the Java object is retrieved, gets converted to a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
 * PKCS#11 type and is set in the new PKCS#11 structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
 * converts the given Java mechanism parameter to a CK mechanism parameter structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
 * and store the length in bytes in the length variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
 * The memory of *ckpParamPtr has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
 * @param jParam - the Java mechanism parameter object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
 * @param ckpParamPtr - the reference of the new pointer to the new CK mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
 *                      structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
 * @param ckpLength - the reference of the length in bytes of the new CK mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
 *                    structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
void jMechanismParameterToCKMechanismParameter(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    if (jParam == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        *ckpParamPtr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        *ckpLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    } else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *)ckpParamPtr, ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    } else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        *ckpParamPtr = jLongObjectToCKULongPtr(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        *ckpLength = sizeof(CK_ULONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    } 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
  1115
        TRACE0("\nSLOW PATH jMechanismParameterToCKMechanismParameter\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        jMechanismParameterToCKMechanismParameterSlow(env, jParam, ckpParamPtr, ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    /* get all Java mechanism parameter classes */
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1123
    jclass jVersionClass, jSsl3MasterKeyDeriveParamsClass;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1124
    jclass jTls12MasterKeyDeriveParamsClass, jSsl3KeyMatParamsClass;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1125
    jclass jTls12KeyMatParamsClass;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1126
    jclass jTlsPrfParamsClass, jTlsMacParamsClass, jAesCtrParamsClass;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1127
    jclass jRsaPkcsOaepParamsClass;
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1128
    jclass jPbeParamsClass, jPkcs5Pbkd2ParamsClass, jRsaPkcsPssParamsClass;
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
  1129
    jclass jEcdh1DeriveParamsClass, jEcdh2DeriveParamsClass;
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
  1130
    jclass jX942Dh1DeriveParamsClass, jX942Dh2DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    TRACE0("\nDEBUG: jMechanismParameterToCKMechanismParameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
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
  1133
    /* most common cases, i.e. NULL/byte[]/long, are already handled by
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
  1134
     * jMechanismParameterToCKMechanismParameter before calling this method.
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
  1135
     */
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
  1136
    jVersionClass = (*env)->FindClass(env, CLASS_VERSION);
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
  1137
    if (jVersionClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    if ((*env)->IsInstanceOf(env, jParam, jVersionClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
         * CK_VERSION used by CKM_SSL3_PRE_MASTER_KEY_GEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        CK_VERSION_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        ckpParam = jVersionToCKVersionPtr(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        *ckpLength = sizeof(CK_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        *ckpParamPtr = ckpParam;
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
  1150
        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
  1151
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
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
  1153
    jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS);
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
  1154
    if (jSsl3MasterKeyDeriveParamsClass == NULL) { 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
  1155
    if ((*env)->IsInstanceOf(env, jParam, jSsl3MasterKeyDeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
         * CK_SSL3_MASTER_KEY_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        ckpParam = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR) malloc(sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS));
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
  1162
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1163
            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
  1164
            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
  1165
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        *ckpParam = jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(env, jParam);
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
  1169
        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
  1170
            free(ckpParam);
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
  1171
            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
  1172
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        *ckpLength = sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        *ckpParamPtr = ckpParam;
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
  1177
        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
  1178
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
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
  1180
    jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS);
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
  1181
    if (jSsl3KeyMatParamsClass == NULL) { 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
  1182
    if ((*env)->IsInstanceOf(env, jParam, jSsl3KeyMatParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
         * CK_SSL3_KEY_MAT_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        CK_SSL3_KEY_MAT_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        ckpParam = (CK_SSL3_KEY_MAT_PARAMS_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_PARAMS));
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
  1189
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1190
            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
  1191
            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
  1192
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        *ckpParam = jSsl3KeyMatParamToCKSsl3KeyMatParam(env, jParam);
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
  1196
        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
  1197
            free(ckpParam);
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
  1198
            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
  1199
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        *ckpLength = sizeof(CK_SSL3_KEY_MAT_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        *ckpParamPtr = ckpParam;
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
  1204
        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
  1205
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1207
    jTls12KeyMatParamsClass = (*env)->FindClass(env, CLASS_TLS12_KEY_MAT_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1208
    if (jTls12KeyMatParamsClass == NULL) { return; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1209
    if ((*env)->IsInstanceOf(env, jParam, jTls12KeyMatParamsClass)) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1210
        /*
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1211
         * CK_TLS12_KEY_MAT_PARAMS
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1212
         */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1213
        CK_TLS12_KEY_MAT_PARAMS_PTR ckpParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1214
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1215
        ckpParam = (CK_TLS12_KEY_MAT_PARAMS_PTR) malloc(sizeof(CK_TLS12_KEY_MAT_PARAMS));
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1216
        if (ckpParam == NULL) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1217
            throwOutOfMemoryError(env, 0);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1218
            return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1219
        }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1220
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1221
        /* convert jParameter to CKParameter */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1222
        *ckpParam = jTls12KeyMatParamToCKTls12KeyMatParam(env, jParam);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1223
        if ((*env)->ExceptionCheck(env)) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1224
            free(ckpParam);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1225
            return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1226
        }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1227
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1228
        /* get length and pointer of parameter */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1229
        *ckpLength = sizeof(CK_TLS12_KEY_MAT_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1230
        *ckpParamPtr = ckpParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1231
        return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1232
    }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1233
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1234
    jTls12MasterKeyDeriveParamsClass =
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1235
            (*env)->FindClass(env, CLASS_TLS12_MASTER_KEY_DERIVE_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1236
    if (jTls12MasterKeyDeriveParamsClass == NULL) { return; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1237
    if ((*env)->IsInstanceOf(env, jParam, jTls12MasterKeyDeriveParamsClass)) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1238
        /*
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1239
         * CK_TLS12_MASTER_KEY_DERIVE_PARAMS
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1240
         */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1241
        CK_TLS12_MASTER_KEY_DERIVE_PARAMS_PTR ckpParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1242
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1243
        ckpParam = (CK_TLS12_MASTER_KEY_DERIVE_PARAMS_PTR)malloc(
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1244
                sizeof(CK_TLS12_MASTER_KEY_DERIVE_PARAMS));
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1245
        if (ckpParam == NULL) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1246
            throwOutOfMemoryError(env, 0);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1247
            return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1248
        }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1249
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1250
        /* convert jParameter to CKParameter */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1251
        *ckpParam = jTls12MasterKeyDeriveParamToCKTls12MasterKeyDeriveParam(env, jParam);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1252
        if ((*env)->ExceptionCheck(env)) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1253
            free(ckpParam);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1254
            return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1255
        }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1256
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1257
        /* get length and pointer of parameter */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1258
        *ckpLength = sizeof(CK_TLS12_MASTER_KEY_DERIVE_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1259
        *ckpParamPtr = ckpParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1260
        return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1261
    }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1262
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
  1263
    jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS);
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
  1264
    if (jTlsPrfParamsClass == NULL) { 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
  1265
    if ((*env)->IsInstanceOf(env, jParam, jTlsPrfParamsClass)) {
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
  1266
        /*
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
  1267
         * CK_TLS_PRF_PARAMS
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
  1268
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        CK_TLS_PRF_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        ckpParam = (CK_TLS_PRF_PARAMS_PTR) malloc(sizeof(CK_TLS_PRF_PARAMS));
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
  1272
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1273
            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
  1274
            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
  1275
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
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
  1277
        /* convert jParameter to CKParameter */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        *ckpParam = jTlsPrfParamsToCKTlsPrfParam(env, jParam);
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
  1279
        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
  1280
            free(ckpParam);
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
  1281
            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
  1282
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
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
  1284
        /* get length and pointer of parameter */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        *ckpLength = sizeof(CK_TLS_PRF_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        *ckpParamPtr = ckpParam;
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
  1287
        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
  1288
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
51800
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1290
    jTlsMacParamsClass = (*env)->FindClass(env, CLASS_TLS_MAC_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1291
    if (jTlsMacParamsClass == NULL) { return; }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1292
    if ((*env)->IsInstanceOf(env, jParam, jTlsMacParamsClass)) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1293
        CK_TLS_MAC_PARAMS_PTR ckpParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1294
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1295
        ckpParam = (CK_TLS_MAC_PARAMS_PTR) malloc(sizeof(CK_TLS_MAC_PARAMS));
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1296
        if (ckpParam == NULL) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1297
            throwOutOfMemoryError(env, 0);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1298
            return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1299
        }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1300
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1301
        /* convert jParameter to CKParameter */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1302
        *ckpParam = jTlsMacParamsToCKTlsMacParam(env, jParam);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1303
        if ((*env)->ExceptionCheck(env)) {
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1304
            free(ckpParam);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1305
            return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1306
        }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1307
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1308
        /* get length and pointer of parameter */
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1309
        *ckpLength = sizeof(CK_TLS_MAC_PARAMS);
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1310
        *ckpParamPtr = ckpParam;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1311
        return;
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1312
    }
bccd9966f1ed 8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents: 47216
diff changeset
  1313
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1314
    jAesCtrParamsClass = (*env)->FindClass(env, CLASS_AES_CTR_PARAMS);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1315
    if (jAesCtrParamsClass == NULL) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1316
    if ((*env)->IsInstanceOf(env, jParam, jAesCtrParamsClass)) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1317
        /*
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1318
         * CK_AES_CTR_PARAMS
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1319
         */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1320
        CK_AES_CTR_PARAMS_PTR ckpParam;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1321
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1322
        ckpParam = (CK_AES_CTR_PARAMS_PTR) malloc(sizeof(CK_AES_CTR_PARAMS));
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1323
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1324
            throwOutOfMemoryError(env, 0);
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1325
            return;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1326
        }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1327
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1328
        /* convert jParameter to CKParameter */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1329
        jAesCtrParamsToCKAesCtrParam(env, jParam, ckpParam);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1330
        if ((*env)->ExceptionCheck(env)) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1331
            free(ckpParam);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1332
            return;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1333
        }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1334
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1335
        /* get length and pointer of parameter */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1336
        *ckpLength = sizeof(CK_AES_CTR_PARAMS);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1337
        *ckpParamPtr = ckpParam;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1338
        return;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1339
    }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1340
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
  1341
    jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS);
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
  1342
    if (jRsaPkcsOaepParamsClass == NULL) { 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
  1343
    if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsOaepParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
         * CK_RSA_PKCS_OAEP_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        CK_RSA_PKCS_OAEP_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        ckpParam = (CK_RSA_PKCS_OAEP_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_OAEP_PARAMS));
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
  1350
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1351
            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
  1352
            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
  1353
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        *ckpParam = jRsaPkcsOaepParamToCKRsaPkcsOaepParam(env, jParam);
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
  1357
        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
  1358
            free(ckpParam);
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
  1359
            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
  1360
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        *ckpLength = sizeof(CK_RSA_PKCS_OAEP_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        *ckpParamPtr = ckpParam;
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
  1365
        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
  1366
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
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
  1368
    jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
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
  1369
    if (jPbeParamsClass == NULL) { 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
  1370
    if ((*env)->IsInstanceOf(env, jParam, jPbeParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
         * CK_PBE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        CK_PBE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        ckpParam = (CK_PBE_PARAMS_PTR) malloc(sizeof(CK_PBE_PARAMS));
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
  1377
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1378
            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
  1379
            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
  1380
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        *ckpParam = jPbeParamToCKPbeParam(env, jParam);
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
  1384
        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
  1385
            free(ckpParam);
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
  1386
            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
  1387
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        *ckpLength = sizeof(CK_PBE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        *ckpParamPtr = ckpParam;
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
  1392
        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
  1393
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
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
  1395
    jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS);
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
  1396
    if (jPkcs5Pbkd2ParamsClass == NULL) { 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
  1397
    if ((*env)->IsInstanceOf(env, jParam, jPkcs5Pbkd2ParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
         * CK_PKCS5_PBKD2_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        CK_PKCS5_PBKD2_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        ckpParam = (CK_PKCS5_PBKD2_PARAMS_PTR) malloc(sizeof(CK_PKCS5_PBKD2_PARAMS));
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
  1404
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1405
            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
  1406
            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
  1407
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        *ckpParam = jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(env, jParam);
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
  1411
        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
  1412
            free(ckpParam);
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
  1413
            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
  1414
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        *ckpLength = sizeof(CK_PKCS5_PBKD2_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        *ckpParamPtr = ckpParam;
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
  1419
        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
  1420
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
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
  1422
    jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS);
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
  1423
    if (jRsaPkcsPssParamsClass == NULL) { 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
  1424
    if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsPssParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
         * CK_RSA_PKCS_PSS_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        CK_RSA_PKCS_PSS_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        ckpParam = (CK_RSA_PKCS_PSS_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_PSS_PARAMS));
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
  1431
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1432
            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
  1433
            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
  1434
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        *ckpParam = jRsaPkcsPssParamToCKRsaPkcsPssParam(env, jParam);
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
  1438
        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
  1439
            free(ckpParam);
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
  1440
            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
  1441
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        *ckpLength = sizeof(CK_RSA_PKCS_PSS_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        *ckpParamPtr = ckpParam;
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
  1446
        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
  1447
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
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
  1449
    jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS);
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
  1450
    if (jEcdh1DeriveParamsClass == NULL) { 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
  1451
    if ((*env)->IsInstanceOf(env, jParam, jEcdh1DeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
         * CK_ECDH1_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        CK_ECDH1_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        ckpParam = (CK_ECDH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH1_DERIVE_PARAMS));
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
  1458
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1459
            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
  1460
            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
  1461
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        *ckpParam = jEcdh1DeriveParamToCKEcdh1DeriveParam(env, jParam);
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
  1465
        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
  1466
            free(ckpParam);
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
  1467
            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
  1468
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        *ckpLength = sizeof(CK_ECDH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        *ckpParamPtr = ckpParam;
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
  1473
        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
  1474
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
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
  1476
    jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS);
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
  1477
    if (jEcdh2DeriveParamsClass == NULL) { 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
  1478
    if ((*env)->IsInstanceOf(env, jParam, jEcdh2DeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
         * CK_ECDH2_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        CK_ECDH2_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        ckpParam = (CK_ECDH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH2_DERIVE_PARAMS));
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
  1485
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1486
            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
  1487
            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
  1488
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        *ckpParam = jEcdh2DeriveParamToCKEcdh2DeriveParam(env, jParam);
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
  1492
        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
  1493
            free(ckpParam);
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
  1494
            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
  1495
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        *ckpLength = sizeof(CK_ECDH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        *ckpParamPtr = ckpParam;
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
  1500
        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
  1501
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
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
  1503
    jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS);
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
  1504
    if (jX942Dh1DeriveParamsClass == NULL) { 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
  1505
    if ((*env)->IsInstanceOf(env, jParam, jX942Dh1DeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
         * CK_X9_42_DH1_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        CK_X9_42_DH1_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        ckpParam = (CK_X9_42_DH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH1_DERIVE_PARAMS));
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
  1512
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1513
            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
  1514
            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
  1515
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        *ckpParam = jX942Dh1DeriveParamToCKX942Dh1DeriveParam(env, jParam);
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
  1519
        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
  1520
            free(ckpParam);
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
  1521
            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
  1522
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        *ckpLength = sizeof(CK_X9_42_DH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        *ckpParamPtr = ckpParam;
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
  1527
        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
  1528
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
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
  1530
    jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS);
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
  1531
    if (jX942Dh2DeriveParamsClass == NULL) { 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
  1532
    if ((*env)->IsInstanceOf(env, jParam, jX942Dh2DeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
         * CK_X9_42_DH2_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        CK_X9_42_DH2_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        ckpParam = (CK_X9_42_DH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH2_DERIVE_PARAMS));
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
  1539
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1540
            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
  1541
            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
  1542
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        *ckpParam = jX942Dh2DeriveParamToCKX942Dh2DeriveParam(env, jParam);
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
  1546
        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
  1547
            free(ckpParam);
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
  1548
            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
  1549
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        *ckpLength = sizeof(CK_X9_42_DH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        *ckpParamPtr = ckpParam;
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
  1554
        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
  1555
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
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
  1557
    /* if everything faild up to here */
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
  1558
    /* try if the parameter is a primitive Java type */
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
  1559
    jObjectToPrimitiveCKObjectPtrPtr(env, jParam, ckpParamPtr, ckpLength);
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
  1560
    /* *ckpParamPtr = jObjectToCKVoidPtr(jParam); */
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
  1561
    /* *ckpLength = 1; */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
/* the mechanism parameter convertion functions: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
 * converts the Java CK_RSA_PKCS_OAEP_PARAMS object to a CK_RSA_PKCS_OAEP_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
 * @param jParam - the Java CK_RSA_PKCS_OAEP_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
 * @return - the new CK_RSA_PKCS_OAEP_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
CK_RSA_PKCS_OAEP_PARAMS jRsaPkcsOaepParamToCKRsaPkcsOaepParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
{
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
  1578
    jclass jRsaPkcsOaepParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    CK_RSA_PKCS_OAEP_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
    jfieldID fieldID;
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
  1581
    jlong jHashAlg, jMgf, jSource;
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
  1582
    jobject jSourceData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    CK_BYTE_PTR ckpByte;
32094
bebc489aace3 8132551: Initialize local varibales before returning them in p11_convert.c
simonis
parents: 25859
diff changeset
  1584
    memset(&ckParam, 0, sizeof(CK_RSA_PKCS_OAEP_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    /* get hashAlg */
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
  1587
    jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS);
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
  1588
    if (jRsaPkcsOaepParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "hashAlg", "J");
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
  1590
    if (fieldID == NULL) { return ckParam; }
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
  1591
    jHashAlg = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    /* get mgf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "mgf", "J");
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
  1595
    if (fieldID == NULL) { return ckParam; }
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
  1596
    jMgf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    /* get source */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "source", "J");
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
  1600
    if (fieldID == NULL) { return ckParam; }
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
  1601
    jSource = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    /* get sourceData and sourceDataLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "pSourceData", "[B");
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
  1605
    if (fieldID == NULL) { return ckParam; }
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
  1606
    jSourceData = (*env)->GetObjectField(env, jParam, fieldID);
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
  1607
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
  1608
    /* populate java values */
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
  1609
    ckParam.hashAlg = jLongToCKULong(jHashAlg);
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
  1610
    ckParam.mgf = jLongToCKULong(jMgf);
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
  1611
    ckParam.source = jLongToCKULong(jSource);
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
  1612
    jByteArrayToCKByteArray(env, jSourceData, & ckpByte, &(ckParam.ulSourceDataLen));
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
  1613
    if ((*env)->ExceptionCheck(env)) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    ckParam.pSourceData = (CK_VOID_PTR) ckpByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
 * converts the Java CK_PBE_PARAMS object to a CK_PBE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
 * @param jParam - the Java CK_PBE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
 * @return - the new CK_PBE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
CK_PBE_PARAMS jPbeParamToCKPbeParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
{
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
  1628
    jclass jPbeParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
    CK_PBE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    jfieldID fieldID;
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
  1631
    jlong jIteration;
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
  1632
    jobject jInitVector, jPassword, jSalt;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
    CK_ULONG ckTemp;
32094
bebc489aace3 8132551: Initialize local varibales before returning them in p11_convert.c
simonis
parents: 25859
diff changeset
  1634
    memset(&ckParam, 0, sizeof(CK_PBE_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    /* get pInitVector */
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
  1637
    jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
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
  1638
    if (jPbeParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVector", "[C");
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
  1640
    if (fieldID == NULL) { return ckParam; }
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
  1641
    jInitVector = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    /* get pPassword and ulPasswordLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pPassword", "[C");
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
  1645
    if (fieldID == NULL) { return ckParam; }
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
  1646
    jPassword = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    /* get pSalt and ulSaltLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pSalt", "[C");
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
  1650
    if (fieldID == NULL) { return ckParam; }
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
  1651
    jSalt = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    /* get ulIteration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
    fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "ulIteration", "J");
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
  1655
    if (fieldID == NULL) { return ckParam; }
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
  1656
    jIteration = (*env)->GetLongField(env, jParam, fieldID);
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
  1657
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
  1658
    /* populate java values */
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
  1659
    ckParam.ulIteration = jLongToCKULong(jIteration);
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
  1660
    jCharArrayToCKCharArray(env, jInitVector, &(ckParam.pInitVector), &ckTemp);
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
  1661
    if ((*env)->ExceptionCheck(env)) { return ckParam; }
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
  1662
    jCharArrayToCKCharArray(env, jPassword, &(ckParam.pPassword), &(ckParam.ulPasswordLen));
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
  1663
    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
  1664
        free(ckParam.pInitVector);
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
  1665
        return ckParam;
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
  1666
    }
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
  1667
    jCharArrayToCKCharArray(env, jSalt, &(ckParam.pSalt), &(ckParam.ulSaltLen));
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
  1668
    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
  1669
        free(ckParam.pInitVector);
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
  1670
        free(ckParam.pPassword);
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
  1671
        return ckParam;
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
  1672
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
 * Copy back the initialization vector from the native structure to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
 * Java object. This is only used for CKM_PBE_* mechanisms and their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
 * CK_PBE_PARAMS parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
{
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
  1685
    jclass jMechanismClass, jPbeParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
    CK_PBE_PARAMS *ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
    CK_MECHANISM_TYPE ckMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    jlong jMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    jobject jParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    jobject jInitVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    jint jInitVectorLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    CK_CHAR_PTR initVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
    jchar* jInitVectorChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    /* get mechanism */
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
  1698
    jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM);
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
  1699
    if (jMechanismClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J");
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
  1701
    if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    ckMechanismType = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
    if (ckMechanismType != ckMechanism->mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        /* we do not have maching types, this should not occur */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
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
  1709
    jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
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
  1710
    if (jPbeParamsClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    ckParam = (CK_PBE_PARAMS *) ckMechanism->pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    if (ckParam != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        initVector = ckParam->pInitVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        if (initVector != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            /* get pParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;");
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
  1717
            if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            jParameter = (*env)->GetObjectField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVektor", "[C");
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
  1720
            if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            jInitVector = (*env)->GetObjectField(env, jParameter, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
            if (jInitVector != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                jInitVectorLength = (*env)->GetArrayLength(env, jInitVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                jInitVectorChars = (*env)->GetCharArrayElements(env, jInitVector, NULL);
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
  1726
                if (jInitVectorChars == NULL) { 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
  1727
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                /* copy the chars to the Java buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                for (i=0; i < jInitVectorLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                    jInitVectorChars[i] = ckCharToJChar(initVector[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                /* copy back the Java buffer to the object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                (*env)->ReleaseCharArrayElements(env, jInitVector, jInitVectorChars, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
 * converts the Java CK_PKCS5_PBKD2_PARAMS object to a CK_PKCS5_PBKD2_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
 * @param jParam - the Java CK_PKCS5_PBKD2_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
 * @return - the new CK_PKCS5_PBKD2_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
CK_PKCS5_PBKD2_PARAMS jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
{
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
  1748
    jclass jPkcs5Pbkd2ParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
    CK_PKCS5_PBKD2_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    jfieldID fieldID;
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
  1751
    jlong jSaltSource, jIteration, jPrf;
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
  1752
    jobject jSaltSourceData, jPrfData;
32094
bebc489aace3 8132551: Initialize local varibales before returning them in p11_convert.c
simonis
parents: 25859
diff changeset
  1753
    memset(&ckParam, 0, sizeof(CK_PKCS5_PBKD2_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
    /* get saltSource */
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
  1756
    jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS);
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
  1757
    if (jPkcs5Pbkd2ParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "saltSource", "J");
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
  1759
    if (fieldID == NULL) { return ckParam; }
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
  1760
    jSaltSource = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    /* get pSaltSourceData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pSaltSourceData", "[B");
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
  1764
    if (fieldID == NULL) { return ckParam; }
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
  1765
    jSaltSourceData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
    /* get iterations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "iterations", "J");
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
  1769
    if (fieldID == NULL) { return ckParam; }
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
  1770
    jIteration = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
    /* get prf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "prf", "J");
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
  1774
    if (fieldID == NULL) { return ckParam; }
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
  1775
    jPrf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
    /* get pPrfData and ulPrfDataLength in byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pPrfData", "[B");
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
  1779
    if (fieldID == NULL) { return ckParam; }
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
  1780
    jPrfData = (*env)->GetObjectField(env, jParam, fieldID);
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
  1781
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
  1782
    /* populate java values */
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
  1783
    ckParam.saltSource = jLongToCKULong(jSaltSource);
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
  1784
    jByteArrayToCKByteArray(env, jSaltSourceData, (CK_BYTE_PTR *) &(ckParam.pSaltSourceData), &(ckParam.ulSaltSourceDataLen));
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
  1785
    if ((*env)->ExceptionCheck(env)) { return ckParam; }
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
  1786
    ckParam.iterations = jLongToCKULong(jIteration);
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
  1787
    ckParam.prf = jLongToCKULong(jPrf);
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
  1788
    jByteArrayToCKByteArray(env, jPrfData, (CK_BYTE_PTR *) &(ckParam.pPrfData), &(ckParam.ulPrfDataLen));
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
  1789
    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
  1790
        free(ckParam.pSaltSourceData);
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
  1791
        return ckParam;
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
  1792
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
 * converts the Java CK_RSA_PKCS_PSS_PARAMS object to a CK_RSA_PKCS_PSS_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
 * @param jParam - the Java CK_RSA_PKCS_PSS_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
 * @return - the new CK_RSA_PKCS_PSS_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
CK_RSA_PKCS_PSS_PARAMS jRsaPkcsPssParamToCKRsaPkcsPssParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
{
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
  1806
    jclass jRsaPkcsPssParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
    CK_RSA_PKCS_PSS_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    jfieldID fieldID;
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
  1809
    jlong jHashAlg, jMgf, jSLen;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 11356
diff changeset
  1810
    memset(&ckParam, 0, sizeof(CK_RSA_PKCS_PSS_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
    /* get hashAlg */
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
  1813
    jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS);
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
  1814
    if (jRsaPkcsPssParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
    fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "hashAlg", "J");
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
  1816
    if (fieldID == NULL) { return ckParam; }
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
  1817
    jHashAlg = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
    /* get mgf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
    fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "mgf", "J");
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
  1821
    if (fieldID == NULL) { return ckParam; }
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
  1822
    jMgf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
    /* get sLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "sLen", "J");
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
  1826
    if (fieldID == NULL) { return ckParam; }
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
  1827
    jSLen = (*env)->GetLongField(env, jParam, fieldID);
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
  1828
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
  1829
    /* populate java values */
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
  1830
    ckParam.hashAlg = jLongToCKULong(jHashAlg);
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
  1831
    ckParam.mgf = jLongToCKULong(jMgf);
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
  1832
    ckParam.sLen = jLongToCKULong(jSLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
 * converts the Java CK_ECDH1_DERIVE_PARAMS object to a CK_ECDH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
 * @param jParam - the Java CK_ECDH1_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
 * @return - the new CK_ECDH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
CK_ECDH1_DERIVE_PARAMS jEcdh1DeriveParamToCKEcdh1DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
{
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
  1846
    jclass jEcdh1DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    CK_ECDH1_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    jlong jLong;
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
  1850
    jobject jSharedData, jPublicData;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 11356
diff changeset
  1851
    memset(&ckParam, 0, sizeof(CK_ECDH1_DERIVE_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
    /* get kdf */
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
  1854
    jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS);
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
  1855
    if (jEcdh1DeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
    fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "kdf", "J");
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
  1857
    if (fieldID == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    ckParam.kdf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
    /* get pSharedData and ulSharedDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
    fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pSharedData", "[B");
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
  1863
    if (fieldID == NULL) { return ckParam; }
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
  1864
    jSharedData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pPublicData", "[B");
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
  1868
    if (fieldID == NULL) { return ckParam; }
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
  1869
    jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
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
  1870
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
  1871
    /* populate java values */
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
  1872
    ckParam.kdf = jLongToCKULong(jLong);
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
  1873
    jByteArrayToCKByteArray(env, jSharedData, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen));
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
  1874
    if ((*env)->ExceptionCheck(env)) { return ckParam; }
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
  1875
    jByteArrayToCKByteArray(env, jPublicData, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
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
  1876
    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
  1877
        free(ckParam.pSharedData);
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
  1878
        return ckParam;
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
  1879
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
 * converts the Java CK_ECDH2_DERIVE_PARAMS object to a CK_ECDH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
 * @param jParam - the Java CK_ECDH2_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
 * @return - the new CK_ECDH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
CK_ECDH2_DERIVE_PARAMS jEcdh2DeriveParamToCKEcdh2DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
{
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
  1893
    jclass jEcdh2DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    CK_ECDH2_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
    jfieldID fieldID;
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
  1896
    jlong jKdf, jPrivateDataLen, jPrivateData;
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
  1897
    jobject jSharedData, jPublicData, jPublicData2;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 11356
diff changeset
  1898
    memset(&ckParam, 0, sizeof(CK_ECDH2_DERIVE_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
    /* get kdf */
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
  1901
    jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS);
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
  1902
    if (jEcdh2DeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "kdf", "J");
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
  1904
    if (fieldID == NULL) { return ckParam; }
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
  1905
    jKdf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
    /* get pSharedData and ulSharedDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pSharedData", "[B");
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
  1909
    if (fieldID == NULL) { return ckParam; }
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
  1910
    jSharedData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData", "[B");
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
  1914
    if (fieldID == NULL) { return ckParam; }
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
  1915
    jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    /* get ulPrivateDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "ulPrivateDataLen", "J");
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
  1919
    if (fieldID == NULL) { return ckParam; }
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
  1920
    jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
    /* get hPrivateData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "hPrivateData", "J");
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
  1924
    if (fieldID == NULL) { return ckParam; }
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
  1925
    jPrivateData = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
    /* get pPublicData2 and ulPublicDataLen2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData2", "[B");
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
  1929
    if (fieldID == NULL) { return ckParam; }
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
  1930
    jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
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
  1932
    /* populate java values */
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
  1933
    ckParam.kdf = jLongToCKULong(jKdf);
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
  1934
    jByteArrayToCKByteArray(env, jSharedData, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen));
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
  1935
    if ((*env)->ExceptionCheck(env)) { return ckParam; }
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
  1936
    jByteArrayToCKByteArray(env, jPublicData, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
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
  1937
    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
  1938
        free(ckParam.pSharedData);
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
  1939
        return ckParam;
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
  1940
    }
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
  1941
    ckParam.ulPrivateDataLen = jLongToCKULong(jPrivateDataLen);
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
  1942
    ckParam.hPrivateData = jLongToCKULong(jPrivateData);
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
  1943
    jByteArrayToCKByteArray(env, jPublicData2, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2));
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
  1944
    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
  1945
        free(ckParam.pSharedData);
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
  1946
        free(ckParam.pPublicData);
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
  1947
        return ckParam;
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
  1948
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
 * converts the Java CK_X9_42_DH1_DERIVE_PARAMS object to a CK_X9_42_DH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
 * @param jParam - the Java CK_X9_42_DH1_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
 * @return - the new CK_X9_42_DH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
CK_X9_42_DH1_DERIVE_PARAMS jX942Dh1DeriveParamToCKX942Dh1DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
{
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
  1961
    jclass jX942Dh1DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    CK_X9_42_DH1_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
    jfieldID fieldID;
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
  1964
    jlong jKdf;
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
  1965
    jobject jOtherInfo, jPublicData;
32094
bebc489aace3 8132551: Initialize local varibales before returning them in p11_convert.c
simonis
parents: 25859
diff changeset
  1966
    memset(&ckParam, 0, sizeof(CK_X9_42_DH1_DERIVE_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
    /* get kdf */
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
  1969
    jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS);
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
  1970
    if (jX942Dh1DeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "kdf", "J");
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
  1972
    if (fieldID == NULL) { return ckParam; }
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
  1973
    jKdf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
    /* get pOtherInfo and ulOtherInfoLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
    fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pOtherInfo", "[B");
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
  1977
    if (fieldID == NULL) { return ckParam; }
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
  1978
    jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
    fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pPublicData", "[B");
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
  1982
    if (fieldID == NULL) { return ckParam; }
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
  1983
    jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
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
  1984
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
  1985
    /* populate java values */
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
  1986
    ckParam.kdf = jLongToCKULong(jKdf);
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
  1987
    jByteArrayToCKByteArray(env, jOtherInfo, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen));
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
  1988
    if ((*env)->ExceptionCheck(env)) { return ckParam; }
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
  1989
    jByteArrayToCKByteArray(env, jPublicData, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
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
  1990
    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
  1991
        free(ckParam.pOtherInfo);
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
  1992
        return ckParam;
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
  1993
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
 * converts the Java CK_X9_42_DH2_DERIVE_PARAMS object to a CK_X9_42_DH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
 * @param jParam - the Java CK_X9_42_DH2_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
 * @return - the new CK_X9_42_DH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
CK_X9_42_DH2_DERIVE_PARAMS jX942Dh2DeriveParamToCKX942Dh2DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
{
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
  2007
    jclass jX942Dh2DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
    CK_X9_42_DH2_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
    jfieldID fieldID;
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
  2010
    jlong jKdf, jPrivateDataLen, jPrivateData;
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
  2011
    jobject jOtherInfo, jPublicData, jPublicData2;
32094
bebc489aace3 8132551: Initialize local varibales before returning them in p11_convert.c
simonis
parents: 25859
diff changeset
  2012
    memset(&ckParam, 0, sizeof(CK_X9_42_DH2_DERIVE_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
    /* get kdf */
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
  2015
    jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS);
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
  2016
    if (jX942Dh2DeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "kdf", "J");
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
  2018
    if (fieldID == NULL) { return ckParam; }
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
  2019
    jKdf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
    /* get pOtherInfo and ulOtherInfoLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pOtherInfo", "[B");
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
  2023
    if (fieldID == NULL) { return ckParam; }
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
  2024
    jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData", "[B");
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
  2028
    if (fieldID == NULL) { return ckParam; }
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
  2029
    jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    /* get ulPrivateDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "ulPrivateDataLen", "J");
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
  2033
    if (fieldID == NULL) { return ckParam; }
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
  2034
    jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
    /* get hPrivateData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "hPrivateData", "J");
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
  2038
    if (fieldID == NULL) { return ckParam; }
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
  2039
    jPrivateData = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
    /* get pPublicData2 and ulPublicDataLen2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData2", "[B");
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
  2043
    if (fieldID == NULL) { return ckParam; }
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
  2044
    jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID);
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
  2045
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
  2046
    /* populate java values */
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
  2047
    ckParam.kdf = jLongToCKULong(jKdf);
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
  2048
    jByteArrayToCKByteArray(env, jOtherInfo, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen));
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
  2049
    if ((*env)->ExceptionCheck(env)) { return ckParam; }
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
  2050
    jByteArrayToCKByteArray(env, jPublicData, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
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
  2051
    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
  2052
        free(ckParam.pOtherInfo);
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
  2053
        return ckParam;
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
  2054
    }
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
  2055
    ckParam.ulPrivateDataLen = jLongToCKULong(jPrivateDataLen);
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
  2056
    ckParam.hPrivateData = jLongToCKULong(jPrivateData);
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
  2057
    jByteArrayToCKByteArray(env, jPublicData2, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2));
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
  2058
    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
  2059
        free(ckParam.pOtherInfo);
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
  2060
        free(ckParam.pPublicData);
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
  2061
        return ckParam;
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
  2062
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
}