jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c
author jzavgren
Wed, 07 Nov 2012 10:49:19 +0000
changeset 14414 f338be3ef659
parent 11356 898d37526be1
child 16012 d10572eb1f48
permissions -rw-r--r--
8001579: Cleanup warnings in security native code Reviewed-by: chegar, alanb, vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2011, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
 * converts the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
 * CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 * @param jParam - the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 * @return - the new CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
CK_SSL3_MASTER_KEY_DERIVE_PARAMS jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    // XXX don't return structs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    // XXX prefetch class and field ids
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   472
    jclass jSsl3MasterKeyDeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    CK_SSL3_MASTER_KEY_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    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
   476
    jobject jRandomInfo, jRIClientRandom, jRIServerRandom, jVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /* get 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
   479
    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
   480
    if (jSsl3MasterKeyDeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    fieldID = (*env)->GetFieldID(env, jSsl3MasterKeyDeriveParamsClass, "RandomInfo", "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   482
    if (fieldID == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /* 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
   486
    jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   487
    if (jSsl3RandomDataClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[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
   489
    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
   490
    jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /* get pServerRandom and ulServerRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[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
   494
    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
   495
    jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /* get pVersion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    fieldID = (*env)->GetFieldID(env, jSsl3MasterKeyDeriveParamsClass, "pVersion",  "Lsun/security/pkcs11/wrapper/CK_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
   499
    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
   500
    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
   501
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   502
    /* 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
   503
    ckParam.pVersion = jVersionToCKVersionPtr(env, jVersion);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   504
    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
   505
    jByteArrayToCKByteArray(env, jRIClientRandom, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen));
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   506
    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
   507
        free(ckParam.pVersion);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   508
        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
   509
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   510
    jByteArrayToCKByteArray(env, jRIServerRandom, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen));
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   511
    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
   512
        free(ckParam.pVersion);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   513
        free(ckParam.RandomInfo.pClientRandom);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   514
        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
   515
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
 * converts the Java CK_TLS_PRF_PARAMS object to a CK_TLS_PRF_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
CK_TLS_PRF_PARAMS jTlsPrfParamsToCKTlsPrfParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
{
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   526
    jclass jTlsPrfParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    CK_TLS_PRF_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    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
   529
    jobject jSeed, jLabel, jOutput;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   530
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   531
    // TBD: what if jParam == NULL?!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   533
    /* 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
   534
    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
   535
    if (jTlsPrfParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    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
   537
    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
   538
    jSeed = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   540
    /* get pLabel */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    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
   542
    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
   543
    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
   544
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   545
    /* 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
   546
    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
   547
    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
   548
    jOutput = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   550
    /* 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
   551
    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
   552
    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
   553
    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
   554
    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
   555
        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
   556
        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
   557
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    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
   559
    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
   560
        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
   561
        free(ckParam.pLabel);
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   562
        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
   563
        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
   564
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   565
    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
   566
    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
   567
        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
   568
        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
   569
        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
   570
        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
   571
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 * converts the Java CK_SSL3_KEY_MAT_PARAMS object to a CK_SSL3_KEY_MAT_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
 * @param jParam - the Java CK_SSL3_KEY_MAT_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
 * @return - the new CK_SSL3_KEY_MAT_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    // XXX don't return structs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    // XXX prefetch class and field ids
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   587
    jclass jSsl3KeyMatParamsClass, jSsl3RandomDataClass, jSsl3KeyMatOutClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    CK_SSL3_KEY_MAT_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    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
   590
    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
   591
    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
   592
    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
   593
    jobject jReturnedKeyMaterial, jRMIvClient, jRMIvServer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    CK_ULONG ckTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /* get ulMacSizeInBits */
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   597
    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
   598
    if (jSsl3KeyMatParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulMacSizeInBits", "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
   600
    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
   601
    jMacSizeInBits = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /* get ulKeySizeInBits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulKeySizeInBits", "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
   605
    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
   606
    jKeySizeInBits = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /* get ulIVSizeInBits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulIVSizeInBits", "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
   610
    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
   611
    jIVSizeInBits = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    /* get bIsExport */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "bIsExport", "Z");
2180
9994f4f08a59 6812738: SSL 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
    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
   616
    jIsExport = (*env)->GetBooleanField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /* get RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   620
    if (jSsl3RandomDataClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "RandomInfo",  "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   622
    if (fieldID == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    /* get pClientRandom and ulClientRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[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
   627
    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
   628
    jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    /* get pServerRandom and ulServerRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[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
   632
    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
   633
    jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /* get pReturnedKeyMaterial */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    jSsl3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   637
    if (jSsl3KeyMatOutClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "pReturnedKeyMaterial",  "Lsun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT;");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   639
    if (fieldID == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    jReturnedKeyMaterial = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   642
    /* 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
   643
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVClient", "[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
   644
    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
   645
    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
   646
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   647
    /* 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
   648
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVServer", "[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
   649
    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
   650
    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
   651
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   652
    /* 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
   653
    ckParam.ulMacSizeInBits = jLongToCKULong(jMacSizeInBits);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   654
    ckParam.ulKeySizeInBits = jLongToCKULong(jKeySizeInBits);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   655
    ckParam.ulIVSizeInBits = jLongToCKULong(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
   656
    ckParam.bIsExport = jBooleanToCKBBool(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
   657
    jByteArrayToCKByteArray(env, jRIClientRandom, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen));
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   658
    if ((*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
   659
    jByteArrayToCKByteArray(env, jRIServerRandom, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen));
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   660
    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
   661
        free(ckParam.RandomInfo.pClientRandom);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   662
        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
   663
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /* allocate memory for pRetrunedKeyMaterial */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    ckParam.pReturnedKeyMaterial = (CK_SSL3_KEY_MAT_OUT_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_OUT));
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   666
    if (ckParam.pReturnedKeyMaterial == 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
   667
        free(ckParam.RandomInfo.pClientRandom);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   668
        free(ckParam.RandomInfo.pServerRandom);
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
   669
        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
   670
        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
   671
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    // the handles are output params only, no need to fetch them from Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    ckParam.pReturnedKeyMaterial->hClientMacSecret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    ckParam.pReturnedKeyMaterial->hServerMacSecret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    ckParam.pReturnedKeyMaterial->hClientKey = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    ckParam.pReturnedKeyMaterial->hServerKey = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   679
    jByteArrayToCKByteArray(env, jRMIvClient, &(ckParam.pReturnedKeyMaterial->pIVClient), &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
   680
    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
   681
        free(ckParam.RandomInfo.pClientRandom);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   682
        free(ckParam.RandomInfo.pServerRandom);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   683
        free(ckParam.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
   684
        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
   685
    }
9994f4f08a59 6812738: SSL 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
    jByteArrayToCKByteArray(env, jRMIvServer, &(ckParam.pReturnedKeyMaterial->pIVServer), &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
   687
    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
   688
        free(ckParam.RandomInfo.pClientRandom);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   689
        free(ckParam.RandomInfo.pServerRandom);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   690
        free(ckParam.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
   691
        free(ckParam.pReturnedKeyMaterial->pIVClient);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   692
        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
   693
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
/*
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   699
 * 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
   700
 *
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   701
 * @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
   702
 * @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
   703
 * @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
   704
 */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   705
void jAesCtrParamsToCKAesCtrParam(JNIEnv *env, jobject jParam,
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   706
                                  CK_AES_CTR_PARAMS_PTR ckpParam) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   707
    jclass jAesCtrParamsClass;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   708
    jfieldID fieldID;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   709
    jlong jCounterBits;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   710
    jobject jCb;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   711
    CK_BYTE_PTR ckBytes;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   712
    CK_ULONG ckTemp;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   713
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   714
    /* get ulCounterBits */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   715
    jAesCtrParamsClass = (*env)->FindClass(env, CLASS_AES_CTR_PARAMS);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   716
    if (jAesCtrParamsClass == NULL) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   717
    fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "ulCounterBits", "J");
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   718
    if (fieldID == NULL) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   719
    jCounterBits = (*env)->GetLongField(env, jParam, fieldID);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   720
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   721
    /* get cb */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   722
    fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "cb", "[B");
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   723
    if (fieldID == NULL) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   724
    jCb = (*env)->GetObjectField(env, jParam, fieldID);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   725
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   726
    /* populate java values */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   727
    ckpParam->ulCounterBits = jLongToCKULong(jCounterBits);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   728
    jByteArrayToCKByteArray(env, jCb, &ckBytes, &ckTemp);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   729
    if ((*env)->ExceptionCheck(env)) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   730
    if (ckTemp != 16) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   731
        TRACE1("ERROR: WRONG CTR IV LENGTH %d", ckTemp);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   732
    } else {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   733
        memcpy(ckpParam->cb, ckBytes, ckTemp);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   734
        free(ckBytes);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   735
    }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   736
}
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   737
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   738
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
 * converts a Java CK_MECHANISM object into a CK_MECHANISM structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
 * @param jMechanism - the Java CK_MECHANISM object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
 * @return - the new CK_MECHANISM structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
void jMechanismToCKMechanism(JNIEnv *env, jobject jMechanism, CK_MECHANISM_PTR ckMechanismPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    jlong jMechanismType = (*env)->GetLongField(env, jMechanism, mech_mechanismID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    jobject jParameter = (*env)->GetObjectField(env, jMechanism, mech_pParameterID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    (*ckMechanismPtr).mechanism = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /* convert the specific Java mechanism parameter object to a pointer to a CK-type mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    if (jParameter == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        (*ckMechanismPtr).pParameter = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        (*ckMechanismPtr).ulParameterLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        jMechanismParameterToCKMechanismParameter(env, jParameter, &(*ckMechanismPtr).pParameter, &(*ckMechanismPtr).ulParameterLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
 * the following functions convert Attribute and Mechanism value pointers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
 * jobject ckAttributeValueToJObject(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
 *                                   const CK_ATTRIBUTE_PTR ckpAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
 * void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
 *                                       jobject jObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
 *                                       CK_VOID_PTR *ckpObjectPtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
 *                                       CK_ULONG *pLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
 * void jMechanismParameterToCKMechanismParameter(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
 *                                                jobject jParam,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
 *                                                CK_VOID_PTR *ckpParamPtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
 *                                                CK_ULONG *ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
 * These functions are used if a PKCS#11 mechanism or attribute structure gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
 * convertet to a Java attribute or mechanism object or vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
 * ckAttributeValueToJObject converts a PKCS#11 attribute value pointer to a Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
 * object depending on the type of the Attribute. A PKCS#11 attribute value can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
 * be a CK_ULONG, CK_BYTE[], CK_CHAR[], big integer, CK_BBOOL, CK_UTF8CHAR[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
 * CK_DATE or CK_FLAGS that gets converted to a corresponding Java object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
 * jObjectToPrimitiveCKObjectPtrPtr is used by jAttributeToCKAttributePtr for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
 * converting the Java attribute value to a PKCS#11 attribute value pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
 * For now only primitive datatypes and arrays of primitive datatypes can get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
 * converted. Otherwise this function throws a PKCS#11Exception with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
 * errorcode CKR_VENDOR_DEFINED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
 * jMechanismParameterToCKMechanismParameter converts a Java mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
 * to a PKCS#11 mechanism parameter. First this function determines what mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
 * parameter the Java object is, then it allocates the memory for the new PKCS#11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 * structure and calls the corresponding function to convert the Java object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 * a PKCS#11 mechanism parameter structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
 * converts the pValue of a CK_ATTRIBUTE structure into a Java Object by checking the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
 * of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
 * @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure that contains the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
 *                       and the pValue to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
 * @return - the new Java object of the CK-type pValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    jint jValueLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    jobject jValueObject = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    jValueLength = ckULongToJInt(ckpAttribute->ulValueLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    if ((jValueLength <= 0) || (ckpAttribute->pValue == NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        return NULL ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    switch(ckpAttribute->type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        case CKA_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            /* value CK_OBJECT_CLASS, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        case CKA_KEY_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            /* value CK_KEY_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        case CKA_CERTIFICATE_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            /* value CK_CERTIFICATE_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        case CKA_HW_FEATURE_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            /* value CK_HW_FEATURE_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        case CKA_MODULUS_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        case CKA_VALUE_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        case CKA_VALUE_LEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        case CKA_KEY_GEN_MECHANISM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        case CKA_PRIME_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        case CKA_SUB_PRIME_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            /* value CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            /* can be CK_BYTE[],CK_CHAR[] or big integer; defacto always CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        case CKA_VALUE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        case CKA_OBJECT_ID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        case CKA_SUBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        case CKA_ID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        case CKA_ISSUER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        case CKA_SERIAL_NUMBER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        case CKA_OWNER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        case CKA_AC_ISSUER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        case CKA_ATTR_TYPES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        case CKA_ECDSA_PARAMS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            /* CKA_EC_PARAMS is the same, these two are equivalent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        case CKA_EC_POINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        case CKA_PRIVATE_EXPONENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        case CKA_PRIME_1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        case CKA_PRIME_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        case CKA_EXPONENT_1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        case CKA_EXPONENT_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        case CKA_COEFFICIENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            /* value CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        case CKA_RESET_ON_INIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        case CKA_HAS_RESET:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        case CKA_TOKEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        case CKA_PRIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        case CKA_MODIFIABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        case CKA_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        case CKA_LOCAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        case CKA_ENCRYPT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        case CKA_VERIFY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        case CKA_VERIFY_RECOVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        case CKA_WRAP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        case CKA_SENSITIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        case CKA_SECONDARY_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        case CKA_DECRYPT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        case CKA_SIGN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        case CKA_SIGN_RECOVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        case CKA_UNWRAP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        case CKA_EXTRACTABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        case CKA_ALWAYS_SENSITIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        case CKA_NEVER_EXTRACTABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        case CKA_TRUSTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            /* value CK_BBOOL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            jValueObject = ckBBoolPtrToJBooleanObject(env, (CK_BBOOL*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        case CKA_LABEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        case CKA_APPLICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            /* value RFC 2279 (UTF-8) string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            jValueObject = ckUTF8CharArrayToJCharArray(env, (CK_UTF8CHAR*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        case CKA_START_DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        case CKA_END_DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            /* value CK_DATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            jValueObject = ckDatePtrToJDateObject(env, (CK_DATE*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        case CKA_MODULUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        case CKA_PUBLIC_EXPONENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        case CKA_PRIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        case CKA_SUBPRIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        case CKA_BASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            /* value big integer, i.e. CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        case CKA_AUTH_PIN_FLAGS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            /* value FLAGS, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        case CKA_VENDOR_DEFINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            /* we make a CK_BYTE[] out of this */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        // Netscape trust attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        case CKA_NETSCAPE_TRUST_SERVER_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        case CKA_NETSCAPE_TRUST_CLIENT_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        case CKA_NETSCAPE_TRUST_CODE_SIGNING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        case CKA_NETSCAPE_TRUST_EMAIL_PROTECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            /* value CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            /* we make a CK_BYTE[] out of this */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    return jValueObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
 * the following functions convert a Java mechanism parameter object to a PKCS#11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
 * mechanism parameter structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
 * CK_<Param>_PARAMS j<Param>ParamToCK<Param>Param(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
 *                                                 jobject jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
 * These functions get a Java object, that must be the right Java mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
 * object and they return the new PKCS#11 mechanism parameter structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
 * Every field of the Java object is retrieved, gets converted to a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
 * PKCS#11 type and is set in the new PKCS#11 structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
 * converts the given Java mechanism parameter to a CK mechanism parameter structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
 * and store the length in bytes in the length variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
 * The memory of *ckpParamPtr has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
 * @param jParam - the Java mechanism parameter object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
 * @param ckpParamPtr - the reference of the new pointer to the new CK mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
 *                      structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
 * @param ckpLength - the reference of the length in bytes of the new CK mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
 *                    structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
void jMechanismParameterToCKMechanismParameter(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    if (jParam == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        *ckpParamPtr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        *ckpLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    } else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *)ckpParamPtr, ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    } else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        *ckpParamPtr = jLongObjectToCKULongPtr(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        *ckpLength = sizeof(CK_ULONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    } 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
   972
        TRACE0("\nSLOW PATH jMechanismParameterToCKMechanismParameter\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        jMechanismParameterToCKMechanismParameterSlow(env, jParam, ckpParamPtr, ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    /* get all Java mechanism parameter classes */
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   980
    jclass jVersionClass, jSsl3MasterKeyDeriveParamsClass, jSsl3KeyMatParamsClass;
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   981
    jclass jTlsPrfParamsClass, jAesCtrParamsClass, jRsaPkcsOaepParamsClass;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
   982
    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
   983
    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
   984
    jclass jX942Dh1DeriveParamsClass, jX942Dh2DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    TRACE0("\nDEBUG: jMechanismParameterToCKMechanismParameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   987
    /* 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
   988
     * 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
   989
     */
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   990
    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
   991
    if (jVersionClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    if ((*env)->IsInstanceOf(env, jParam, jVersionClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
         * CK_VERSION used by CKM_SSL3_PRE_MASTER_KEY_GEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        CK_VERSION_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        ckpParam = jVersionToCKVersionPtr(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        *ckpLength = sizeof(CK_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        *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
  1004
        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
  1005
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1007
    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
  1008
    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
  1009
    if ((*env)->IsInstanceOf(env, jParam, jSsl3MasterKeyDeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
         * CK_SSL3_MASTER_KEY_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        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
  1016
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1017
            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
  1018
            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
  1019
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        *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
  1023
        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
  1024
            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
  1025
            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
  1026
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        *ckpLength = sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        *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
  1031
        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
  1032
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1034
    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
  1035
    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
  1036
    if ((*env)->IsInstanceOf(env, jParam, jSsl3KeyMatParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
         * CK_SSL3_KEY_MAT_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        CK_SSL3_KEY_MAT_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        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
  1043
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1044
            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
  1045
            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
  1046
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        *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
  1050
        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
  1051
            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
  1052
            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
  1053
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        *ckpLength = sizeof(CK_SSL3_KEY_MAT_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        *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
  1058
        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
  1059
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1061
    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
  1062
    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
  1063
    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
  1064
        /*
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1065
         * 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
  1066
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        CK_TLS_PRF_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        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
  1070
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1071
            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
  1072
            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
  1073
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1075
        /* convert jParameter to CKParameter */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        *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
  1077
        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
  1078
            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
  1079
            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
  1080
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1082
        /* get length and pointer of parameter */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        *ckpLength = sizeof(CK_TLS_PRF_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        *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
  1085
        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
  1086
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1088
    jAesCtrParamsClass = (*env)->FindClass(env, CLASS_AES_CTR_PARAMS);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1089
    if (jAesCtrParamsClass == NULL) { return; }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1090
    if ((*env)->IsInstanceOf(env, jParam, jAesCtrParamsClass)) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1091
        /*
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1092
         * CK_AES_CTR_PARAMS
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1093
         */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1094
        CK_AES_CTR_PARAMS_PTR ckpParam;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1095
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1096
        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
  1097
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1098
            throwOutOfMemoryError(env, 0);
8542
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1099
            return;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1100
        }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1101
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1102
        /* convert jParameter to CKParameter */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1103
        jAesCtrParamsToCKAesCtrParam(env, jParam, ckpParam);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1104
        if ((*env)->ExceptionCheck(env)) {
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1105
            free(ckpParam);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1106
            return;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1107
        }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1108
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1109
        /* get length and pointer of parameter */
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1110
        *ckpLength = sizeof(CK_AES_CTR_PARAMS);
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1111
        *ckpParamPtr = ckpParam;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1112
        return;
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1113
    }
62c7b10ce177 6604496: Support for CKM_AES_CTR (counter mode)
valeriep
parents: 5506
diff changeset
  1114
2180
9994f4f08a59 6812738: SSL 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
    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
  1116
    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
  1117
    if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsOaepParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
         * CK_RSA_PKCS_OAEP_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        CK_RSA_PKCS_OAEP_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        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
  1124
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1125
            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
  1126
            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
  1127
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        *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
  1131
        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
  1132
            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
  1133
            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
  1134
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        *ckpLength = sizeof(CK_RSA_PKCS_OAEP_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        *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
  1139
        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
  1140
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1142
    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
  1143
    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
  1144
    if ((*env)->IsInstanceOf(env, jParam, jPbeParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
         * CK_PBE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        CK_PBE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        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
  1151
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1152
            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
  1153
            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
  1154
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        *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
  1158
        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
  1159
            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
  1160
            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
  1161
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        *ckpLength = sizeof(CK_PBE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        *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
  1166
        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
  1167
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
2180
9994f4f08a59 6812738: SSL 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
    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
  1170
    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
  1171
    if ((*env)->IsInstanceOf(env, jParam, jPkcs5Pbkd2ParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
         * CK_PKCS5_PBKD2_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        CK_PKCS5_PBKD2_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        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
  1178
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1179
            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
  1180
            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
  1181
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        *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
  1185
        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
  1186
            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
  1187
            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
  1188
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        *ckpLength = sizeof(CK_PKCS5_PBKD2_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        *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
  1193
        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
  1194
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
2180
9994f4f08a59 6812738: SSL 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
    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
  1197
    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
  1198
    if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsPssParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
         * CK_RSA_PKCS_PSS_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        CK_RSA_PKCS_PSS_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        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
  1205
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1206
            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
  1207
            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
  1208
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        *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
  1212
        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
  1213
            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
  1214
            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
  1215
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        *ckpLength = sizeof(CK_RSA_PKCS_PSS_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        *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
  1220
        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
  1221
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1223
    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
  1224
    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
  1225
    if ((*env)->IsInstanceOf(env, jParam, jEcdh1DeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
         * CK_ECDH1_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        CK_ECDH1_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        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
  1232
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1233
            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
  1234
            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
  1235
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        *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
  1239
        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
  1240
            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
  1241
            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
  1242
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        *ckpLength = sizeof(CK_ECDH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        *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
  1247
        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
  1248
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1250
    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
  1251
    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
  1252
    if ((*env)->IsInstanceOf(env, jParam, jEcdh2DeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
         * CK_ECDH2_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        CK_ECDH2_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        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
  1259
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1260
            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
  1261
            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
  1262
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        *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
  1266
        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
  1267
            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
  1268
            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
  1269
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        *ckpLength = sizeof(CK_ECDH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        *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
  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
    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
  1278
    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
  1279
    if ((*env)->IsInstanceOf(env, jParam, jX942Dh1DeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
         * CK_X9_42_DH1_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        CK_X9_42_DH1_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        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
  1286
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1287
            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
  1288
            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
  1289
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        *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
  1293
        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
  1294
            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
  1295
            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
  1296
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        *ckpLength = sizeof(CK_X9_42_DH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        *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
  1301
        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
  1302
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1304
    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
  1305
    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
  1306
    if ((*env)->IsInstanceOf(env, jParam, jX942Dh2DeriveParamsClass)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
         * CK_X9_42_DH2_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        CK_X9_42_DH2_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        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
  1313
        if (ckpParam == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 8542
diff changeset
  1314
            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
  1315
            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
  1316
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        *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
  1320
        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
  1321
            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
  1322
            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
  1323
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        *ckpLength = sizeof(CK_X9_42_DH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        *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
  1328
        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
  1329
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1331
    /* 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
  1332
    /* 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
  1333
    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
  1334
    /* *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
  1335
    /* *ckpLength = 1; */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
/* the mechanism parameter convertion functions: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
 * converts the Java CK_RSA_PKCS_OAEP_PARAMS object to a CK_RSA_PKCS_OAEP_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
 * @param jParam - the Java CK_RSA_PKCS_OAEP_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
 * @return - the new CK_RSA_PKCS_OAEP_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
CK_RSA_PKCS_OAEP_PARAMS jRsaPkcsOaepParamToCKRsaPkcsOaepParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
{
2180
9994f4f08a59 6812738: SSL 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
    jclass jRsaPkcsOaepParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    CK_RSA_PKCS_OAEP_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    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
  1355
    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
  1356
    jobject jSourceData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    CK_BYTE_PTR ckpByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    /* 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
  1360
    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
  1361
    if (jRsaPkcsOaepParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    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
  1363
    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
  1364
    jHashAlg = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    /* get mgf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    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
  1368
    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
  1369
    jMgf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    /* get source */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    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
  1373
    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
  1374
    jSource = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    /* get sourceData and sourceDataLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    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
  1378
    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
  1379
    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
  1380
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1381
    /* 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
  1382
    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
  1383
    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
  1384
    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
  1385
    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
  1386
    if ((*env)->ExceptionCheck(env)) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    ckParam.pSourceData = (CK_VOID_PTR) ckpByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
 * converts the Java CK_PBE_PARAMS object to a CK_PBE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
 * @param jParam - the Java CK_PBE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
 * @return - the new CK_PBE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
CK_PBE_PARAMS jPbeParamToCKPbeParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
{
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1401
    jclass jPbeParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    CK_PBE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    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
  1404
    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
  1405
    jobject jInitVector, jPassword, jSalt;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    CK_ULONG ckTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    /* 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
  1409
    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
  1410
    if (jPbeParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    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
  1412
    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
  1413
    jInitVector = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    /* get pPassword and ulPasswordLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    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
  1417
    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
  1418
    jPassword = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    /* get pSalt and ulSaltLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    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
  1422
    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
  1423
    jSalt = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    /* get ulIteration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    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
  1427
    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
  1428
    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
  1429
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1430
    /* 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
  1431
    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
  1432
    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
  1433
    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
  1434
    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
  1435
    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
  1436
        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
  1437
        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
  1438
    }
9994f4f08a59 6812738: SSL 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
    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
  1440
    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
  1441
        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
  1442
        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
  1443
        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
  1444
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
 * Copy back the initialization vector from the native structure to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
 * Java object. This is only used for CKM_PBE_* mechanisms and their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
 * CK_PBE_PARAMS parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
{
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1457
    jclass jMechanismClass, jPbeParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    CK_PBE_PARAMS *ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    CK_MECHANISM_TYPE ckMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    jlong jMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    jobject jParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    jobject jInitVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    jint jInitVectorLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    CK_CHAR_PTR initVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    jchar* jInitVectorChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    /* 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
  1470
    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
  1471
    if (jMechanismClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    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
  1473
    if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
    ckMechanismType = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    if (ckMechanismType != ckMechanism->mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        /* we do not have maching types, this should not occur */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1481
    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
  1482
    if (jPbeParamsClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    ckParam = (CK_PBE_PARAMS *) ckMechanism->pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    if (ckParam != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        initVector = ckParam->pInitVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        if (initVector != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            /* get pParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            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
  1489
            if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            jParameter = (*env)->GetObjectField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            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
  1492
            if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            jInitVector = (*env)->GetObjectField(env, jParameter, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            if (jInitVector != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                jInitVectorLength = (*env)->GetArrayLength(env, jInitVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                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
  1498
                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
  1499
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                /* copy the chars to the Java buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                for (i=0; i < jInitVectorLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                    jInitVectorChars[i] = ckCharToJChar(initVector[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                /* copy back the Java buffer to the object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                (*env)->ReleaseCharArrayElements(env, jInitVector, jInitVectorChars, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
 * converts the Java CK_PKCS5_PBKD2_PARAMS object to a CK_PKCS5_PBKD2_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
 * @param jParam - the Java CK_PKCS5_PBKD2_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
 * @return - the new CK_PKCS5_PBKD2_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
CK_PKCS5_PBKD2_PARAMS jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
{
2180
9994f4f08a59 6812738: SSL 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
    jclass jPkcs5Pbkd2ParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
    CK_PKCS5_PBKD2_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    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
  1523
    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
  1524
    jobject jSaltSourceData, jPrfData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    /* 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
  1527
    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
  1528
    if (jPkcs5Pbkd2ParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    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
  1530
    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
  1531
    jSaltSource = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    /* get pSaltSourceData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    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
  1535
    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
  1536
    jSaltSourceData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
    /* get iterations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    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
  1540
    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
  1541
    jIteration = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    /* get prf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    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
  1545
    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
  1546
    jPrf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    /* get pPrfData and ulPrfDataLength in byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    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
  1550
    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
  1551
    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
  1552
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1553
    /* 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
  1554
    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
  1555
    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
  1556
    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
  1557
    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
  1558
    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
  1559
    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
  1560
    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
  1561
        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
  1562
        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
  1563
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
 * converts the Java CK_RSA_PKCS_PSS_PARAMS object to a CK_RSA_PKCS_PSS_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
 * @param jParam - the Java CK_RSA_PKCS_PSS_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
 * @return - the new CK_RSA_PKCS_PSS_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
CK_RSA_PKCS_PSS_PARAMS jRsaPkcsPssParamToCKRsaPkcsPssParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
{
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1577
    jclass jRsaPkcsPssParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    CK_RSA_PKCS_PSS_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    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
  1580
    jlong jHashAlg, jMgf, jSLen;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 11356
diff changeset
  1581
    memset(&ckParam, 0, sizeof(CK_RSA_PKCS_PSS_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    /* 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
  1584
    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
  1585
    if (jRsaPkcsPssParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    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
  1587
    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
  1588
    jHashAlg = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    /* get mgf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    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
  1592
    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
  1593
    jMgf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    /* get sLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    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
  1597
    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
  1598
    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
  1599
9994f4f08a59 6812738: SSL 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
    /* 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
  1601
    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
  1602
    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
  1603
    ckParam.sLen = jLongToCKULong(jSLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
 * converts the Java CK_ECDH1_DERIVE_PARAMS object to a CK_ECDH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
 * @param jParam - the Java CK_ECDH1_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
 * @return - the new CK_ECDH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
CK_ECDH1_DERIVE_PARAMS jEcdh1DeriveParamToCKEcdh1DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
{
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1617
    jclass jEcdh1DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
    CK_ECDH1_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    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
  1621
    jobject jSharedData, jPublicData;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 11356
diff changeset
  1622
    memset(&ckParam, 0, sizeof(CK_ECDH1_DERIVE_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
    /* 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
  1625
    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
  1626
    if (jEcdh1DeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    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
  1628
    if (fieldID == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    ckParam.kdf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    /* get pSharedData and ulSharedDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
    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
  1634
    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
  1635
    jSharedData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    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
  1639
    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
  1640
    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
  1641
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1642
    /* 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
  1643
    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
  1644
    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
  1645
    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
  1646
    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
  1647
    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
  1648
        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
  1649
        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
  1650
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
 * converts the Java CK_ECDH2_DERIVE_PARAMS object to a CK_ECDH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
 * @param jParam - the Java CK_ECDH2_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
 * @return - the new CK_ECDH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
CK_ECDH2_DERIVE_PARAMS jEcdh2DeriveParamToCKEcdh2DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
{
2180
9994f4f08a59 6812738: SSL 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
    jclass jEcdh2DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    CK_ECDH2_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
    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
  1667
    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
  1668
    jobject jSharedData, jPublicData, jPublicData2;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 11356
diff changeset
  1669
    memset(&ckParam, 0, sizeof(CK_ECDH2_DERIVE_PARAMS));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
    /* 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
  1672
    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
  1673
    if (jEcdh2DeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    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
  1675
    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
  1676
    jKdf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    /* get pSharedData and ulSharedDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
    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
  1680
    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
  1681
    jSharedData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    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
  1685
    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
  1686
    jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
    /* get ulPrivateDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    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
  1690
    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
  1691
    jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    /* get hPrivateData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    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
  1695
    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
  1696
    jPrivateData = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
    /* get pPublicData2 and ulPublicDataLen2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    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
  1700
    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
  1701
    jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1703
    /* 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
  1704
    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
  1705
    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
  1706
    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
  1707
    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
  1708
    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
  1709
        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
  1710
        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
  1711
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1712
    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
  1713
    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
  1714
    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
  1715
    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
  1716
        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
  1717
        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
  1718
        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
  1719
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
 * 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
  1725
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
 * @param jParam - the Java CK_X9_42_DH1_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
 * @return - the new CK_X9_42_DH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
CK_X9_42_DH1_DERIVE_PARAMS jX942Dh1DeriveParamToCKX942Dh1DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
{
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1732
    jclass jX942Dh1DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    CK_X9_42_DH1_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    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
  1735
    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
  1736
    jobject jOtherInfo, jPublicData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
    /* 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
  1739
    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
  1740
    if (jX942Dh1DeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
    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
  1742
    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
  1743
    jKdf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    /* get pOtherInfo and ulOtherInfoLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
    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
  1747
    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
  1748
    jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
    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
  1752
    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
  1753
    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
  1754
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1755
    /* 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
  1756
    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
  1757
    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
  1758
    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
  1759
    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
  1760
    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
  1761
        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
  1762
        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
  1763
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
 * 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
  1770
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
 * @param jParam - the Java CK_X9_42_DH2_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
 * @return - the new CK_X9_42_DH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
CK_X9_42_DH2_DERIVE_PARAMS jX942Dh2DeriveParamToCKX942Dh2DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
{
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1777
    jclass jX942Dh2DeriveParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
    CK_X9_42_DH2_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    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
  1780
    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
  1781
    jobject jOtherInfo, jPublicData, jPublicData2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    /* 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
  1784
    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
  1785
    if (jX942Dh2DeriveParamsClass == NULL) { return ckParam; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    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
  1787
    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
  1788
    jKdf = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
    /* get pOtherInfo and ulOtherInfoLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    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
  1792
    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
  1793
    jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    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
  1797
    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
  1798
    jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    /* get ulPrivateDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    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
  1802
    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
  1803
    jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    /* get hPrivateData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
    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
  1807
    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
  1808
    jPrivateData = (*env)->GetLongField(env, jParam, fieldID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
    /* get pPublicData2 and ulPublicDataLen2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
    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
  1812
    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
  1813
    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
  1814
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1815
    /* 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
  1816
    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
  1817
    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
  1818
    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
  1819
    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
  1820
    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
  1821
        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
  1822
        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
  1823
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1824
    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
  1825
    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
  1826
    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
  1827
    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
  1828
        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
  1829
        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
  1830
        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
  1831
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
}