diff options
author | Elliott Hughes <enh@google.com> | 2010-05-18 15:06:16 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-05-18 15:06:16 -0700 |
commit | 4e2163262dcdd279f442d5d2b1cdacf4adf3b446 (patch) | |
tree | 598440e133f9007239934695ef22f8a15e64208a /openssl/src/main | |
parent | e38b310627d785e7052e5aabea85bcfacb2fc991 (diff) | |
download | libcore-4e2163262dcdd279f442d5d2b1cdacf4adf3b446.zip libcore-4e2163262dcdd279f442d5d2b1cdacf4adf3b446.tar.gz libcore-4e2163262dcdd279f442d5d2b1cdacf4adf3b446.tar.bz2 |
Remove more uses of Get/Release Critical.
Bug: 2663177
Change-Id: I87325ca8bb064b6be6c3cc3c885a8b18cceaa36c
Diffstat (limited to 'openssl/src/main')
-rw-r--r-- | openssl/src/main/java/org/openssl/NativeBN.java | 4 | ||||
-rw-r--r-- | openssl/src/main/native/BNInterface.cpp | 65 |
2 files changed, 28 insertions, 41 deletions
diff --git a/openssl/src/main/java/org/openssl/NativeBN.java b/openssl/src/main/java/org/openssl/NativeBN.java index 9691204..0650425 100644 --- a/openssl/src/main/java/org/openssl/NativeBN.java +++ b/openssl/src/main/java/org/openssl/NativeBN.java @@ -73,11 +73,11 @@ public class NativeBN { public static native String BN_bn2hex(int a); // char * BN_bn2hex(const BIGNUM *a); - public static native byte[] BN_bn2bin(int a, byte[] to); + public static native byte[] BN_bn2bin(int a); // Returns result byte[] AND NOT length. // int BN_bn2bin(const BIGNUM *a, unsigned char *to); - public static native int[] bn2litEndInts(int a, int[] to); + public static native int[] bn2litEndInts(int a); public static native int sign(int a); // Returns -1, 0, 1 AND NOT boolean. diff --git a/openssl/src/main/native/BNInterface.cpp b/openssl/src/main/native/BNInterface.cpp index 44dd38a..bf3195a 100644 --- a/openssl/src/main/native/BNInterface.cpp +++ b/openssl/src/main/native/BNInterface.cpp @@ -378,54 +378,41 @@ static jstring NativeBN_BN_bn2hex(JNIEnv* env, jclass, BIGNUM* a) { else return NULL; } -/** - * public static native byte[] BN_bn2bin(int, byte[]) - */ -static jbyteArray NativeBN_BN_bn2bin(JNIEnv* env, jclass, BIGNUM* a, jbyteArray to) { +static jbyteArray NativeBN_BN_bn2bin(JNIEnv* env, jclass, BIGNUM* a) { if (!oneValidHandle(env, a)) return NULL; - jbyteArray returnJBytes = to; - unsigned char * tmpBytes; - int len, byteCnt; - byteCnt = BN_num_bytes(a); -// FIXME: Currently ignoring array passed in to: - returnJBytes = env->NewByteArray(byteCnt); -// FIXME: is it neccessary to check for returnJBytes != NULL? - tmpBytes = (unsigned char *)env->GetPrimitiveArrayCritical(returnJBytes, NULL); - if (tmpBytes != NULL) { - len = BN_bn2bin(a, tmpBytes); - env->ReleasePrimitiveArrayCritical(returnJBytes, tmpBytes, 0); - return returnJBytes; + jbyteArray result = env->NewByteArray(BN_num_bytes(a)); + if (result == NULL) { + return NULL; } - else return NULL; + jbyte* bytes = env->GetByteArrayElements(result, NULL); + if (bytes == NULL) { + return NULL; + } + BN_bn2bin(a, reinterpret_cast<unsigned char*>(bytes)); + env->ReleaseByteArrayElements(result, bytes, 0); + return result; } -/** - * public static native int[] bn2litEndInts(int, int[]) - * cf. litEndInts2bn - */ -static jintArray NativeBN_bn2litEndInts(JNIEnv* env, jclass, BIGNUM* a, jintArray to) { +static jintArray NativeBN_bn2litEndInts(JNIEnv* env, jclass, BIGNUM* a) { if (!oneValidHandle(env, a)) return NULL; - jintArray returnJInts = to; bn_check_top(a); int len = a->top; - if (len > 0) { -// FIXME: Currently ignoring array passed in to: - returnJInts = env->NewIntArray(len); -// FIXME: is it neccessary to check for returnJBytes != NULL? - BN_ULONG* tmpInts = (BN_ULONG*)env->GetPrimitiveArrayCritical(returnJInts, NULL); - if (tmpInts != NULL) { - int i = len; do { i--; tmpInts[i] = a->d[i]; } while (i > 0); - env->ReleasePrimitiveArrayCritical(returnJInts, tmpInts, 0); - return returnJInts; - } - else return NULL; + if (len == 0) { + return NULL; } - else { // value = 0 - return NULL; // Client should not call when sign = 0! + jintArray result = env->NewIntArray(len); + if (result == NULL) { + return NULL; } + BN_ULONG* longs = reinterpret_cast<BN_ULONG*>(env->GetIntArrayElements(result, NULL)); + if (longs == NULL) { + return NULL; + } + int i = len; do { i--; longs[i] = a->d[i]; } while (i > 0); + env->ReleaseIntArrayElements(result, reinterpret_cast<jint*>(longs), 0); + return result; } - /** * public static native int sign(int) */ @@ -651,8 +638,8 @@ static JNINativeMethod METHODS[] = { { "longInt", "(I)J", (void*)NativeBN_longInt }, { "BN_bn2dec", "(I)Ljava/lang/String;", (void*)NativeBN_BN_bn2dec }, { "BN_bn2hex", "(I)Ljava/lang/String;", (void*)NativeBN_BN_bn2hex }, - { "BN_bn2bin", "(I[B)[B", (void*)NativeBN_BN_bn2bin }, - { "bn2litEndInts", "(I[I)[I", (void*)NativeBN_bn2litEndInts }, + { "BN_bn2bin", "(I)[B", (void*)NativeBN_BN_bn2bin }, + { "bn2litEndInts", "(I)[I", (void*)NativeBN_bn2litEndInts }, { "sign", "(I)I", (void*)NativeBN_sign }, { "BN_set_negative", "(II)V", (void*)NativeBN_BN_set_negative }, { "bitLength", "(I)I", (void*)NativeBN_bitLength }, |