jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 2180 9994f4f08a59
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Portions Copyright 2003-2005 Sun Microsystems, Inc.  All Rights Reserved.
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);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    assert(jDateClass != 0);
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");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    assert(jCtrId != 0);
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);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    jMonth = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->month), 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jDay = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->day), 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /* create new CK_DATE object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    jDateObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      (*env)->NewObject(env, jDateClass, jCtrId, jYear, jMonth, jDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    assert(jDateObject != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    (*env)->DeleteLocalRef(env, jDateClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    (*env)->DeleteLocalRef(env, jYear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    (*env)->DeleteLocalRef(env, jMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    (*env)->DeleteLocalRef(env, jDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    return jDateObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * converts a pointer to a CK_VERSION structure into a Java CK_VERSION Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @param ckpVersion - the pointer to the CK_VERSION structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @return - the new Java CK_VERSION object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    jclass jVersionClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    jobject jVersionObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    jint jMajor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    jint jMinor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /* load CK_VERSION class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    jVersionClass = (*env)->FindClass(env, CLASS_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    assert(jVersionClass != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /* load CK_VERSION constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    jCtrId = (*env)->GetMethodID(env, jVersionClass, "<init>", "(II)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    assert(jCtrId != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /* prep both fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    jMajor = ckpVersion->major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    jMinor = ckpVersion->minor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /* create new CK_VERSION object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    jVersionObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      (*env)->NewObject(env, jVersionClass, jCtrId, jMajor, jMinor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    assert(jVersionObject != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    (*env)->DeleteLocalRef(env, jVersionClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    return jVersionObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * converts a pointer to a CK_SESSION_INFO structure into a Java CK_SESSION_INFO Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * @param ckpSessionInfo - the pointer to the CK_SESSION_INFO structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * @return - the new Java CK_SESSION_INFO object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    jclass jSessionInfoClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    jobject jSessionInfoObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    jlong jSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    jlong jState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    jlong jFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    jlong jDeviceError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /* load CK_SESSION_INFO class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    jSessionInfoClass = (*env)->FindClass(env, CLASS_SESSION_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    assert(jSessionInfoClass != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /* load CK_SESSION_INFO constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    jCtrId = (*env)->GetMethodID(env, jSessionInfoClass, "<init>", "(JJJJ)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    assert(jCtrId != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /* prep all fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    jSlotID = ckULongToJLong(ckpSessionInfo->slotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    jState = ckULongToJLong(ckpSessionInfo->state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    jFlags = ckULongToJLong(ckpSessionInfo->flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    jDeviceError = ckULongToJLong(ckpSessionInfo->ulDeviceError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /* create new CK_SESSION_INFO object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    jSessionInfoObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      (*env)->NewObject(env, jSessionInfoClass, jCtrId, jSlotID, jState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        jFlags, jDeviceError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    assert(jSessionInfoObject != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    (*env)->DeleteLocalRef(env, jSessionInfoClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    return jSessionInfoObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * converts a pointer to a CK_ATTRIBUTE structure into a Java CK_ATTRIBUTE Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * @return - the new Java CK_ATTRIBUTE object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    jclass jAttributeClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    jmethodID jCtrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    jobject jAttributeObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    jlong jType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    jobject jPValue = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    jAttributeClass = (*env)->FindClass(env, CLASS_ATTRIBUTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    assert(jAttributeClass != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /* load CK_INFO constructor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    jCtrId = (*env)->GetMethodID(env, jAttributeClass, "<init>", "(JLjava/lang/Object;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    assert(jCtrId != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /* prep both fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    jType = ckULongToJLong(ckpAttribute->type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jPValue = ckAttributeValueToJObject(env, ckpAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /* create new CK_ATTRIBUTE object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    jAttributeObject =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
      (*env)->NewObject(env, jAttributeClass, jCtrId, jType, jPValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    assert(jAttributeObject != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /* free local references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    (*env)->DeleteLocalRef(env, jAttributeClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    (*env)->DeleteLocalRef(env, jPValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    return jAttributeObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * converts a Java CK_VERSION object into a pointer to a CK_VERSION structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * @param jVersion - the Java CK_VERSION object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * @return - the pointer to the new CK_VERSION structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    CK_VERSION_PTR ckpVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    jclass jVersionClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    jfieldID jFieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    jbyte jMajor, jMinor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    if (jVersion == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /* allocate memory for CK_VERSION pointer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    ckpVersion = (CK_VERSION_PTR) malloc(sizeof(CK_VERSION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /* get CK_VERSION class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    jVersionClass = (*env)->GetObjectClass(env, jVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    assert(jVersionClass != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /* get Major */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    jFieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    assert(jFieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    jMajor = (*env)->GetByteField(env, jVersion, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    ckpVersion->major = jByteToCKByte(jMajor);
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");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    assert(jFieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    jMinor = (*env)->GetByteField(env, jVersion, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    ckpVersion->minor = jByteToCKByte(jMinor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    return ckpVersion ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * converts a Java CK_DATE object into a pointer to a CK_DATE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * @param jVersion - the Java CK_DATE object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * @return - the pointer to the new CK_DATE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    CK_DATE * ckpDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    CK_ULONG ckLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    jclass jDateClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    jfieldID jFieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    jobject jYear, jMonth, jDay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    jchar *jTempChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    CK_ULONG i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /* allocate memory for CK_DATE pointer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    ckpDate = (CK_DATE *) malloc(sizeof(CK_DATE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /* get CK_DATE class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    jDateClass = (*env)->FindClass(env, CLASS_DATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    assert(jDateClass != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /* get Year */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    jFieldID = (*env)->GetFieldID(env, jDateClass, "year", "[C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    assert(jFieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    jYear = (*env)->GetObjectField(env, jDate, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    if (jYear == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        ckpDate->year[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        ckpDate->year[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        ckpDate->year[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        ckpDate->year[3] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        ckLength = (*env)->GetArrayLength(env, jYear);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        (*env)->GetCharArrayRegion(env, jYear, 0, ckLength, jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        for (i = 0; (i < ckLength) && (i < 4) ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            ckpDate->year[i] = jCharToCKChar(jTempChars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        free(jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /* get Month */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    jFieldID = (*env)->GetFieldID(env, jDateClass, "month", "[C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    assert(jFieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    jMonth = (*env)->GetObjectField(env, jDate, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    if (jMonth == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        ckpDate->month[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        ckpDate->month[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        ckLength = (*env)->GetArrayLength(env, jMonth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        (*env)->GetCharArrayRegion(env, jMonth, 0, ckLength, jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        for (i = 0; (i < ckLength) && (i < 4) ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            ckpDate->month[i] = jCharToCKChar(jTempChars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        free(jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /* get Day */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    jFieldID = (*env)->GetFieldID(env, jDateClass, "day", "[C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    assert(jFieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    jDay = (*env)->GetObjectField(env, jDate, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    if (jDay == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        ckpDate->day[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        ckpDate->day[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        ckLength = (*env)->GetArrayLength(env, jDay);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        (*env)->GetCharArrayRegion(env, jDay, 0, ckLength, jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        for (i = 0; (i < ckLength) && (i < 4) ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            ckpDate->day[i] = jCharToCKChar(jTempChars[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        free(jTempChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    return ckpDate ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 * converts a Java CK_ATTRIBUTE object into a CK_ATTRIBUTE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * @param jAttribute - the Java CK_ATTRIBUTE object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * @return - the new CK_ATTRIBUTE structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    CK_ATTRIBUTE ckAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    jclass jAttributeClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    jfieldID jFieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    jlong jType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    jobject jPValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    TRACE0("\nDEBUG: jAttributeToCKAttribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /* get CK_ATTRIBUTE class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    TRACE0(", getting attribute object class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    jAttributeClass = (*env)->GetObjectClass(env, jAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    assert(jAttributeClass != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /* get type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    TRACE0(", getting type field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    jFieldID = (*env)->GetFieldID(env, jAttributeClass, "type", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    assert(jFieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    jType = (*env)->GetLongField(env, jAttribute, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    TRACE1(", type=0x%X", jType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /* get pValue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    TRACE0(", getting pValue field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    jFieldID = (*env)->GetFieldID(env, jAttributeClass, "pValue", "Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    assert(jFieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    jPValue = (*env)->GetObjectField(env, jAttribute, jFieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    TRACE1(", pValue=%p", jPValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    ckAttribute.type = jLongToCKULong(jType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    TRACE0(", converting pValue to primitive object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /* convert the Java pValue object to a CK-type pValue pointer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    jObjectToPrimitiveCKObjectPtrPtr(env, jPValue, &(ckAttribute.pValue), &(ckAttribute.ulValueLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    TRACE0("\nFINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    return ckAttribute ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
 * converts the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
 * CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
 * @param jParam - the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
 * @return - the new CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
CK_SSL3_MASTER_KEY_DERIVE_PARAMS jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    // XXX don't return structs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    // XXX prefetch class and field ids
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    jclass jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    CK_SSL3_MASTER_KEY_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    jclass jSsl3RandomDataClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    jobject jRandomInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /* get RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    fieldID = (*env)->GetFieldID(env, jSsl3MasterKeyDeriveParamsClass, "RandomInfo", "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /* get pClientRandom and ulClientRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /* get pServerRandom and ulServerRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /* get pVersion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    fieldID = (*env)->GetFieldID(env, jSsl3MasterKeyDeriveParamsClass, "pVersion",  "Lsun/security/pkcs11/wrapper/CK_VERSION;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    ckParam.pVersion = jVersionToCKVersionPtr(env, jObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
 * converts the Java CK_TLS_PRF_PARAMS object to a CK_TLS_PRF_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
CK_TLS_PRF_PARAMS jTlsPrfParamsToCKTlsPrfParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    jclass jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    CK_TLS_PRF_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pSeed", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pSeed), &(ckParam.ulSeedLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pLabel", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pLabel), &(ckParam.ulLabelLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    ckParam.pulOutputLen = malloc(sizeof(CK_ULONG));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pOutput", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pOutput), ckParam.pulOutputLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
 * converts the Java CK_SSL3_KEY_MAT_PARAMS object to a CK_SSL3_KEY_MAT_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
 * @param jParam - the Java CK_SSL3_KEY_MAT_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
 * @return - the new CK_SSL3_KEY_MAT_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    // XXX don't return structs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    // XXX prefetch class and field ids
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    jclass jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    CK_SSL3_KEY_MAT_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    jboolean jBoolean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    jobject jRandomInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    jobject jReturnedKeyMaterial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    jclass jSsl3RandomDataClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    jclass jSsl3KeyMatOutClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    CK_ULONG ckTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /* get ulMacSizeInBits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulMacSizeInBits", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    ckParam.ulMacSizeInBits = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /* get ulKeySizeInBits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulKeySizeInBits", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    ckParam.ulKeySizeInBits = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /* get ulIVSizeInBits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulIVSizeInBits", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    ckParam.ulIVSizeInBits = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /* get bIsExport */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "bIsExport", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    jBoolean = (*env)->GetBooleanField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    ckParam.bIsExport = jBooleanToCKBBool(jBoolean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /* get RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "RandomInfo",  "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /* get pClientRandom and ulClientRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    /* get pServerRandom and ulServerRandomLength out of RandomInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /* get pReturnedKeyMaterial */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    jSsl3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "pReturnedKeyMaterial",  "Lsun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    jReturnedKeyMaterial = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /* allocate memory for pRetrunedKeyMaterial */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    ckParam.pReturnedKeyMaterial = (CK_SSL3_KEY_MAT_OUT_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_OUT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    // the handles are output params only, no need to fetch them from Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    ckParam.pReturnedKeyMaterial->hClientMacSecret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    ckParam.pReturnedKeyMaterial->hServerMacSecret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    ckParam.pReturnedKeyMaterial->hClientKey = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    ckParam.pReturnedKeyMaterial->hServerKey = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /* get pIVClient out of pReturnedKeyMaterial */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVClient", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    jObject = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pReturnedKeyMaterial->pIVClient), &ckTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /* get pIVServer out of pReturnedKeyMaterial */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVServer", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    jObject = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pReturnedKeyMaterial->pIVServer), &ckTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
 * converts a Java CK_MECHANISM object into a CK_MECHANISM structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
 * @param env - used to call JNI funktions to get the values out of the Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
 * @param jMechanism - the Java CK_MECHANISM object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
 * @return - the new CK_MECHANISM structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
void jMechanismToCKMechanism(JNIEnv *env, jobject jMechanism, CK_MECHANISM_PTR ckMechanismPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    jlong jMechanismType = (*env)->GetLongField(env, jMechanism, mech_mechanismID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    jobject jParameter = (*env)->GetObjectField(env, jMechanism, mech_pParameterID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    (*ckMechanismPtr).mechanism = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /* convert the specific Java mechanism parameter object to a pointer to a CK-type mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    if (jParameter == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        (*ckMechanismPtr).pParameter = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        (*ckMechanismPtr).ulParameterLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        jMechanismParameterToCKMechanismParameter(env, jParameter, &(*ckMechanismPtr).pParameter, &(*ckMechanismPtr).ulParameterLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
 * the following functions convert Attribute and Mechanism value pointers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
 * jobject ckAttributeValueToJObject(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
 *                                   const CK_ATTRIBUTE_PTR ckpAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
 * void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
 *                                       jobject jObject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
 *                                       CK_VOID_PTR *ckpObjectPtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
 *                                       CK_ULONG *pLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
 * void jMechanismParameterToCKMechanismParameter(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
 *                                                jobject jParam,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
 *                                                CK_VOID_PTR *ckpParamPtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
 *                                                CK_ULONG *ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
 * These functions are used if a PKCS#11 mechanism or attribute structure gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
 * convertet to a Java attribute or mechanism object or vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
 * ckAttributeValueToJObject converts a PKCS#11 attribute value pointer to a Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
 * object depending on the type of the Attribute. A PKCS#11 attribute value can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 * be a CK_ULONG, CK_BYTE[], CK_CHAR[], big integer, CK_BBOOL, CK_UTF8CHAR[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
 * CK_DATE or CK_FLAGS that gets converted to a corresponding Java object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
 * jObjectToPrimitiveCKObjectPtrPtr is used by jAttributeToCKAttributePtr for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
 * converting the Java attribute value to a PKCS#11 attribute value pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
 * For now only primitive datatypes and arrays of primitive datatypes can get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
 * converted. Otherwise this function throws a PKCS#11Exception with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
 * errorcode CKR_VENDOR_DEFINED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
 * jMechanismParameterToCKMechanismParameter converts a Java mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
 * to a PKCS#11 mechanism parameter. First this function determines what mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
 * parameter the Java object is, then it allocates the memory for the new PKCS#11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
 * structure and calls the corresponding function to convert the Java object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
 * a PKCS#11 mechanism parameter structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
 * converts the pValue of a CK_ATTRIBUTE structure into a Java Object by checking the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
 * of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
 * @param env - used to call JNI funktions to create the new Java object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
 * @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure that contains the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
 *                       and the pValue to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
 * @return - the new Java object of the CK-type pValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    jint jValueLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    jobject jValueObject = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    jValueLength = ckULongToJInt(ckpAttribute->ulValueLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    if ((jValueLength <= 0) || (ckpAttribute->pValue == NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        return NULL ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    switch(ckpAttribute->type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        case CKA_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            /* value CK_OBJECT_CLASS, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        case CKA_KEY_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            /* value CK_KEY_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        case CKA_CERTIFICATE_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            /* value CK_CERTIFICATE_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        case CKA_HW_FEATURE_TYPE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            /* value CK_HW_FEATURE_TYPE, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        case CKA_MODULUS_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        case CKA_VALUE_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        case CKA_VALUE_LEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        case CKA_KEY_GEN_MECHANISM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        case CKA_PRIME_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        case CKA_SUB_PRIME_BITS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            /* value CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            /* can be CK_BYTE[],CK_CHAR[] or big integer; defacto always CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        case CKA_VALUE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        case CKA_OBJECT_ID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        case CKA_SUBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        case CKA_ID:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        case CKA_ISSUER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        case CKA_SERIAL_NUMBER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        case CKA_OWNER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        case CKA_AC_ISSUER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        case CKA_ATTR_TYPES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        case CKA_ECDSA_PARAMS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            /* CKA_EC_PARAMS is the same, these two are equivalent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        case CKA_EC_POINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        case CKA_PRIVATE_EXPONENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        case CKA_PRIME_1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        case CKA_PRIME_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        case CKA_EXPONENT_1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        case CKA_EXPONENT_2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        case CKA_COEFFICIENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            /* value CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        case CKA_RESET_ON_INIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        case CKA_HAS_RESET:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        case CKA_TOKEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        case CKA_PRIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        case CKA_MODIFIABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        case CKA_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        case CKA_LOCAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        case CKA_ENCRYPT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        case CKA_VERIFY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        case CKA_VERIFY_RECOVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        case CKA_WRAP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        case CKA_SENSITIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        case CKA_SECONDARY_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        case CKA_DECRYPT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        case CKA_SIGN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        case CKA_SIGN_RECOVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        case CKA_UNWRAP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        case CKA_EXTRACTABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        case CKA_ALWAYS_SENSITIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        case CKA_NEVER_EXTRACTABLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        case CKA_TRUSTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            /* value CK_BBOOL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            jValueObject = ckBBoolPtrToJBooleanObject(env, (CK_BBOOL*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        case CKA_LABEL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        case CKA_APPLICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            /* value RFC 2279 (UTF-8) string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            jValueObject = ckUTF8CharArrayToJCharArray(env, (CK_UTF8CHAR*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        case CKA_START_DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        case CKA_END_DATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            /* value CK_DATE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            jValueObject = ckDatePtrToJDateObject(env, (CK_DATE*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        case CKA_MODULUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        case CKA_PUBLIC_EXPONENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        case CKA_PRIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        case CKA_SUBPRIME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        case CKA_BASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            /* value big integer, i.e. CK_BYTE[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        case CKA_AUTH_PIN_FLAGS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            /* value FLAGS, defacto a CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        case CKA_VENDOR_DEFINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            /* we make a CK_BYTE[] out of this */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        // Netscape trust attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        case CKA_NETSCAPE_TRUST_SERVER_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        case CKA_NETSCAPE_TRUST_CLIENT_AUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        case CKA_NETSCAPE_TRUST_CODE_SIGNING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        case CKA_NETSCAPE_TRUST_EMAIL_PROTECTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            /* value CK_ULONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            /* we make a CK_BYTE[] out of this */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    return jValueObject ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
 * the following functions convert a Java mechanism parameter object to a PKCS#11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
 * mechanism parameter structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
 * CK_<Param>_PARAMS j<Param>ParamToCK<Param>Param(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
 *                                                 jobject jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
 * These functions get a Java object, that must be the right Java mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
 * object and they return the new PKCS#11 mechanism parameter structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
 * Every field of the Java object is retrieved, gets converted to a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
 * PKCS#11 type and is set in the new PKCS#11 structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
 * converts the given Java mechanism parameter to a CK mechanism parameter structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
 * and store the length in bytes in the length variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
 * The memory of *ckpParamPtr has to be freed after use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
 * @param jParam - the Java mechanism parameter object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
 * @param ckpParamPtr - the reference of the new pointer to the new CK mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
 *                      structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
 * @param ckpLength - the reference of the length in bytes of the new CK mechanism parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
 *                    structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
void jMechanismParameterToCKMechanismParameter(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    if (jParam == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        *ckpParamPtr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        *ckpLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    } else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *)ckpParamPtr, ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    } else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        *ckpParamPtr = jLongObjectToCKULongPtr(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        *ckpLength = sizeof(CK_ULONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        /* printf("slow path jMechanismParameterToCKMechanismParameter\n"); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        jMechanismParameterToCKMechanismParameterSlow(env, jParam, ckpParamPtr, ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /* get all Java mechanism parameter classes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    jclass jVersionClass    = (*env)->FindClass(env, CLASS_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    jclass jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    jclass jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    jclass jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    jclass jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    jclass jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    jclass jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    jclass jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    jclass jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    jclass jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    jclass jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    TRACE0("\nDEBUG: jMechanismParameterToCKMechanismParameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    /* first check the most common cases */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    if (jParam == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        *ckpParamPtr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        *ckpLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    } else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *)ckpParamPtr, ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    } else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        *ckpParamPtr = jLongObjectToCKULongPtr(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        *ckpLength = sizeof(CK_ULONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    } else if ((*env)->IsInstanceOf(env, jParam, jVersionClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    if ((*env)->IsInstanceOf(env, jParam, jVersionClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * CK_VERSION used by CKM_SSL3_PRE_MASTER_KEY_GEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        CK_VERSION_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        ckpParam = jVersionToCKVersionPtr(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        *ckpLength = sizeof(CK_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    } else if ((*env)->IsInstanceOf(env, jParam, jSsl3MasterKeyDeriveParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
         * CK_SSL3_MASTER_KEY_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        ckpParam = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR) malloc(sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        *ckpParam = jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        *ckpLength = sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    } else if ((*env)->IsInstanceOf(env, jParam, jSsl3KeyMatParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * CK_SSL3_KEY_MAT_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        CK_SSL3_KEY_MAT_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        ckpParam = (CK_SSL3_KEY_MAT_PARAMS_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        *ckpParam = jSsl3KeyMatParamToCKSsl3KeyMatParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        *ckpLength = sizeof(CK_SSL3_KEY_MAT_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    } else if ((*env)->IsInstanceOf(env, jParam, jTlsPrfParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        // CK_TLS_PRF_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        CK_TLS_PRF_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        ckpParam = (CK_TLS_PRF_PARAMS_PTR) malloc(sizeof(CK_TLS_PRF_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        // convert jParameter to CKParameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        *ckpParam = jTlsPrfParamsToCKTlsPrfParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        // get length and pointer of parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        *ckpLength = sizeof(CK_TLS_PRF_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    } else if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsOaepParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
         * CK_RSA_PKCS_OAEP_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        CK_RSA_PKCS_OAEP_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        ckpParam = (CK_RSA_PKCS_OAEP_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_OAEP_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        *ckpParam = jRsaPkcsOaepParamToCKRsaPkcsOaepParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        *ckpLength = sizeof(CK_RSA_PKCS_OAEP_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    } else if ((*env)->IsInstanceOf(env, jParam, jPbeParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
         * CK_PBE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        CK_PBE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        ckpParam = (CK_PBE_PARAMS_PTR) malloc(sizeof(CK_PBE_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        *ckpParam = jPbeParamToCKPbeParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        *ckpLength = sizeof(CK_PBE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    } else if ((*env)->IsInstanceOf(env, jParam, jPkcs5Pbkd2ParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
         * CK_PKCS5_PBKD2_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        CK_PKCS5_PBKD2_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        ckpParam = (CK_PKCS5_PBKD2_PARAMS_PTR) malloc(sizeof(CK_PKCS5_PBKD2_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        *ckpParam = jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        *ckpLength = sizeof(CK_PKCS5_PBKD2_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    } else if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsPssParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
         * CK_RSA_PKCS_PSS_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        CK_RSA_PKCS_PSS_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        ckpParam = (CK_RSA_PKCS_PSS_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_PSS_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        *ckpParam = jRsaPkcsPssParamToCKRsaPkcsPssParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        *ckpLength = sizeof(CK_RSA_PKCS_PSS_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    } else if ((*env)->IsInstanceOf(env, jParam, jEcdh1DeriveParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
         * CK_ECDH1_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        CK_ECDH1_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        ckpParam = (CK_ECDH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH1_DERIVE_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        *ckpParam = jEcdh1DeriveParamToCKEcdh1DeriveParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        *ckpLength = sizeof(CK_ECDH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    } else if ((*env)->IsInstanceOf(env, jParam, jEcdh2DeriveParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
         * CK_ECDH2_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        CK_ECDH2_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        ckpParam = (CK_ECDH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH2_DERIVE_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        *ckpParam = jEcdh2DeriveParamToCKEcdh2DeriveParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        *ckpLength = sizeof(CK_ECDH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    } else if ((*env)->IsInstanceOf(env, jParam, jX942Dh1DeriveParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
         * CK_X9_42_DH1_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        CK_X9_42_DH1_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        ckpParam = (CK_X9_42_DH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH1_DERIVE_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        *ckpParam = jX942Dh1DeriveParamToCKX942Dh1DeriveParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        *ckpLength = sizeof(CK_X9_42_DH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    } else if ((*env)->IsInstanceOf(env, jParam, jX942Dh2DeriveParamsClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
         * CK_X9_42_DH2_DERIVE_PARAMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        CK_X9_42_DH2_DERIVE_PARAMS_PTR ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        ckpParam = (CK_X9_42_DH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH2_DERIVE_PARAMS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        /* convert jParameter to CKParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        *ckpParam = jX942Dh2DeriveParamToCKX942Dh2DeriveParam(env, jParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        /* get length and pointer of parameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        *ckpLength = sizeof(CK_X9_42_DH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        *ckpParamPtr = ckpParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        /* if everything faild up to here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        /* try if the parameter is a primitive Java type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        jObjectToPrimitiveCKObjectPtrPtr(env, jParam, ckpParamPtr, ckpLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        /* *ckpParamPtr = jObjectToCKVoidPtr(jParam); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        /* *ckpLength = 1; */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
/* the mechanism parameter convertion functions: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
 * converts the Java CK_RSA_PKCS_OAEP_PARAMS object to a CK_RSA_PKCS_OAEP_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
 * @param jParam - the Java CK_RSA_PKCS_OAEP_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
 * @return - the new CK_RSA_PKCS_OAEP_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
CK_RSA_PKCS_OAEP_PARAMS jRsaPkcsOaepParamToCKRsaPkcsOaepParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    jclass jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    CK_RSA_PKCS_OAEP_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    CK_BYTE_PTR ckpByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    /* get hashAlg */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "hashAlg", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    ckParam.hashAlg = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    /* get mgf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "mgf", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    ckParam.mgf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    /* get source */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "source", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    ckParam.source = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    /* get sourceData and sourceDataLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "pSourceData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    jByteArrayToCKByteArray(env, jObject, &ckpByte, &(ckParam.ulSourceDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    ckParam.pSourceData = (CK_VOID_PTR) ckpByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
 * converts the Java CK_PBE_PARAMS object to a CK_PBE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
 * @param jParam - the Java CK_PBE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
 * @return - the new CK_PBE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
CK_PBE_PARAMS jPbeParamToCKPbeParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    CK_PBE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    CK_ULONG ckTemp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    /* get pInitVector */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVector", "[C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    jCharArrayToCKCharArray(env, jObject, &(ckParam.pInitVector), &ckTemp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    /* get pPassword and ulPasswordLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pPassword", "[C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    jCharArrayToCKCharArray(env, jObject, &(ckParam.pPassword), &(ckParam.ulPasswordLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    /* get pSalt and ulSaltLength */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pSalt", "[C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    jCharArrayToCKCharArray(env, jObject, &(ckParam.pSalt), &(ckParam.ulSaltLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    /* get ulIteration */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "ulIteration", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    ckParam.ulIteration = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
 * Copy back the initialization vector from the native structure to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
 * Java object. This is only used for CKM_PBE_* mechanisms and their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
 * CK_PBE_PARAMS parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    jclass jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    CK_PBE_PARAMS *ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    CK_MECHANISM_TYPE ckMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    jlong jMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    jobject jParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    jobject jInitVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    jint jInitVectorLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    CK_CHAR_PTR initVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    jchar* jInitVectorChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    /* get mechanism */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    ckMechanismType = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    if (ckMechanismType != ckMechanism->mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        /* we do not have maching types, this should not occur */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    ckParam = (CK_PBE_PARAMS *) ckMechanism->pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    if (ckParam != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        initVector = ckParam->pInitVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        if (initVector != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            /* get pParameter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            jParameter = (*env)->GetObjectField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVektor", "[C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            jInitVector = (*env)->GetObjectField(env, jParameter, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            if (jInitVector != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                jInitVectorLength = (*env)->GetArrayLength(env, jInitVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                jInitVectorChars = (*env)->GetCharArrayElements(env, jInitVector, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                /* copy the chars to the Java buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                for (i=0; i < jInitVectorLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                    jInitVectorChars[i] = ckCharToJChar(initVector[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                /* copy back the Java buffer to the object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                (*env)->ReleaseCharArrayElements(env, jInitVector, jInitVectorChars, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
 * converts the Java CK_PKCS5_PBKD2_PARAMS object to a CK_PKCS5_PBKD2_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
 * @param jParam - the Java CK_PKCS5_PBKD2_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
 * @return - the new CK_PKCS5_PBKD2_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
CK_PKCS5_PBKD2_PARAMS jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    jclass jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    CK_PKCS5_PBKD2_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    /* get saltSource */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "saltSource", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    ckParam.saltSource = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    /* get pSaltSourceData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pSaltSourceData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR *) &(ckParam.pSaltSourceData), &(ckParam.ulSaltSourceDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    /* get iterations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "iterations", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    ckParam.iterations = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    /* get prf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "prf", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    ckParam.prf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    /* get pPrfData and ulPrfDataLength in byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pPrfData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR *) &(ckParam.pPrfData), &(ckParam.ulPrfDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
 * converts the Java CK_RSA_PKCS_PSS_PARAMS object to a CK_RSA_PKCS_PSS_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
 * @param jParam - the Java CK_RSA_PKCS_PSS_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
 * @return - the new CK_RSA_PKCS_PSS_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
CK_RSA_PKCS_PSS_PARAMS jRsaPkcsPssParamToCKRsaPkcsPssParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    jclass jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    CK_RSA_PKCS_PSS_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    /* get hashAlg */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "hashAlg", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    ckParam.hashAlg = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    /* get mgf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "mgf", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    ckParam.mgf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    /* get sLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "sLen", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    ckParam.sLen = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
 * converts the Java CK_ECDH1_DERIVE_PARAMS object to a CK_ECDH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
 * @param jParam - the Java CK_ECDH1_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
 * @return - the new CK_ECDH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
CK_ECDH1_DERIVE_PARAMS jEcdh1DeriveParamToCKEcdh1DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    jclass jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    CK_ECDH1_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    /* get kdf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "kdf", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    ckParam.kdf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    /* get pSharedData and ulSharedDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pSharedData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pPublicData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
 * converts the Java CK_ECDH2_DERIVE_PARAMS object to a CK_ECDH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
 * @param jParam - the Java CK_ECDH2_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
 * @return - the new CK_ECDH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
CK_ECDH2_DERIVE_PARAMS jEcdh2DeriveParamToCKEcdh2DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    jclass jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    CK_ECDH2_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    /* get kdf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "kdf", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    ckParam.kdf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    /* get pSharedData and ulSharedDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pSharedData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    /* get ulPrivateDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "ulPrivateDataLen", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    ckParam.ulPrivateDataLen = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    /* get hPrivateData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "hPrivateData", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    ckParam.hPrivateData = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    /* get pPublicData2 and ulPublicDataLen2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData2", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
 * 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
  1374
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
 * @param jParam - the Java CK_X9_42_DH1_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
 * @return - the new CK_X9_42_DH1_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
CK_X9_42_DH1_DERIVE_PARAMS jX942Dh1DeriveParamToCKX942Dh1DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    jclass jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    CK_X9_42_DH1_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    /* get kdf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "kdf", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    ckParam.kdf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    /* get pOtherInfo and ulOtherInfoLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pOtherInfo", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pPublicData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
 * 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
  1410
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
 * @param env - used to call JNI funktions to get the Java classes and objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
 * @param jParam - the Java CK_X9_42_DH2_DERIVE_PARAMS object to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
 * @return - the new CK_X9_42_DH2_DERIVE_PARAMS structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
CK_X9_42_DH2_DERIVE_PARAMS jX942Dh2DeriveParamToCKX942Dh2DeriveParam(JNIEnv *env, jobject jParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    jclass jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    CK_X9_42_DH2_DERIVE_PARAMS ckParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    jlong jLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    jobject jObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    /* get kdf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "kdf", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    ckParam.kdf = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    /* get pOtherInfo and ulOtherInfoLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pOtherInfo", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    /* get pPublicData and ulPublicDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    /* get ulPrivateDataLen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "ulPrivateDataLen", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    ckParam.ulPrivateDataLen = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    /* get hPrivateData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "hPrivateData", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    jLong = (*env)->GetLongField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    ckParam.hPrivateData = jLongToCKULong(jLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    /* get pPublicData2 and ulPublicDataLen2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData2", "[B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    assert(fieldID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    jObject = (*env)->GetObjectField(env, jParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    return ckParam ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
}