summaryrefslogtreecommitdiffstats
path: root/openssl/src/main
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2010-06-22 23:43:20 -0700
committerBrian Carlstrom <bdc@google.com>2010-06-26 11:36:33 -0700
commit12cd1f00c2fa1a7f37bf644cecdf7588bdc0b0a9 (patch)
tree30b0a7b661f472721e9daab349d93ae835901923 /openssl/src/main
parent6f39ada8cbbc0823f8e8c91e8f3cbfb78d7df114 (diff)
downloadlibcore-12cd1f00c2fa1a7f37bf644cecdf7588bdc0b0a9.zip
libcore-12cd1f00c2fa1a7f37bf644cecdf7588bdc0b0a9.tar.gz
libcore-12cd1f00c2fa1a7f37bf644cecdf7588bdc0b0a9.tar.bz2
Remove libcore's dependency on bouncycastle
external/bouncycastle - Change to be the primary build for bouncycastle sources (as opposed to part of libcore) - Moved OpenSSLMessageDigest from libcore to OpenSSLDigest It uses NativeCrypto API from core, but implements a bouncycastle specific interface - restored registration of bouncycastle MessageDigests for SHA-1, SHA-256, MD5 OpenSSLProvider versions take precedence, but explicit provider of "BC" allows choice - enabled native versions of SHA-384 and SHA-512 - pruned MD4 implementation frameworks/base - frameworks and CoreTests modules now depend on bouncycastle - update preloades classes for NativeBN package change - moved CryptoTest to libcore libcore - core now builds without bouncycastle sources - core-tests, core-tests-support, core-tests-supportlib now depend on bouncycastle - removed libcore/openssl directory, moving NativeBN to java/math - minor cleanup of Provider, Security, Services style while working on ProviderTest - added new OpenSSLProvider registered as first provider to have priority over the others to ensure our native implementations are used - moved BouncyCastle to have priority as a provider over Harmony - JarVerifier and JarUtils now implicitly use OpenSSLMessageDigest - Cleanedup OpenSSLSignature, implementation needs to be finished to move to OpenSSLProvider - To avoid using PEMWriter from BouncyCastle, NativeCrypto now takes binary encoded certs and keys This is more efficient as well avoiding the base64 decode/encode of the binary data - removed SHA-224 to match the RI packages/apps/CertInstaller - CertificateInstaller module now depends on bouncycastle this is the only app to depend on bouncycastle system/core - updated BOOTCLASSPATH Change-Id: I6205366b12baec4331b4a76e2c85d8324bf64b2c
Diffstat (limited to 'openssl/src/main')
-rw-r--r--openssl/src/main/java/org/openssl/NativeBN.java171
-rw-r--r--openssl/src/main/native/NativeBN.cpp551
-rw-r--r--openssl/src/main/native/sub.mk18
3 files changed, 0 insertions, 740 deletions
diff --git a/openssl/src/main/java/org/openssl/NativeBN.java b/openssl/src/main/java/org/openssl/NativeBN.java
deleted file mode 100644
index 7653cba..0000000
--- a/openssl/src/main/java/org/openssl/NativeBN.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openssl;
-
-public class NativeBN {
-
- public static native int ERR_get_error();
- // unsigned long ERR_get_error(void);
-
- public static native String ERR_error_string(int e);
- // char *ERR_error_string(unsigned long e, char *buf);
-
- public static native int BN_new();
- // BIGNUM *BN_new(void);
-
- public static native void BN_free(int a);
- // void BN_free(BIGNUM *a);
-
- public static native int BN_cmp(int a, int b);
- // int BN_cmp(const BIGNUM *a, const BIGNUM *b);
-
- public static native boolean BN_copy(int to, int from);
- // Returns boolean success AND NOT result BIGNUM handle!
- // BIGNUM *BN_copy(BIGNUM *to, const BIGNUM *from);
-// public static native int BN_dup(int from);
- // BIGNUM *BN_dup(const BIGNUM *a);
-
-
- public static native boolean putLongInt(int a, long dw);
-
- public static native boolean putULongInt(int a, long dw, boolean neg);
-
- public static native int BN_dec2bn(int a, String str);
- // int BN_dec2bn(BIGNUM **a, const char *str);
-
- public static native int BN_hex2bn(int a, String str);
- // int BN_hex2bn(BIGNUM **a, const char *str);
-
- public static native boolean BN_bin2bn(byte[] s, int len, boolean neg, int ret);
- // Returns boolean success AND NOT result BIGNUM handle!
- // BIGNUM * BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
- // BN-Docu: s is taken as unsigned big endian;
- // Additional parameter: neg.
-
- public static native boolean litEndInts2bn(int[] ints, int len, boolean neg, int ret);
-
- public static native boolean twosComp2bn(byte[] s, int len, int ret);
-
-
- public static native long longInt(int a);
- // unsigned long BN_get_word(BIGNUM *a);
-
- public static native String BN_bn2dec(int a);
- // char * BN_bn2dec(const BIGNUM *a);
-
- public static native String BN_bn2hex(int a);
- // char * BN_bn2hex(const BIGNUM *a);
-
- 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);
-
- public static native int sign(int a);
- // Returns -1, 0, 1 AND NOT boolean.
- // #define BN_is_negative(a) ((a)->neg != 0)
-
- public static native void BN_set_negative(int b, int n);
- // void BN_set_negative(BIGNUM *b, int n);
-
- public static native int bitLength(int a);
-
- public static native boolean BN_is_bit_set(int a, int n);
- // int BN_is_bit_set(const BIGNUM *a, int n);
-
- public static native boolean modifyBit(int a, int n, int op);
- // Returns boolean success.
- // op: 0 = reset; 1 = set; -1 = flip
- // uses BN_set_bit(), BN_clear_bit() and BN_is_bit_set()
-
- public static native boolean BN_shift(int r, int a, int n);
- // int BN_shift(BIGNUM *r, const BIGNUM *a, int n);
-
- public static native boolean BN_add_word(int a, int w);
- // ATTENTION: w is treated as unsigned.
- // int BN_add_word(BIGNUM *a, BN_ULONG w);
-
- public static native boolean BN_sub_word(int a, int w);
- // ATTENTION: w is treated as unsigned.
- // int BN_sub_word(BIGNUM *a, BN_ULONG w);
-
- public static native boolean BN_mul_word(int a, int w);
- // ATTENTION: w is treated as unsigned.
- // int BN_mul_word(BIGNUM *a, BN_ULONG w);
-
- public static native int BN_div_word(int a, int w);
- // ATTENTION: w is treated as unsigned.
- // BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
-
- public static native int BN_mod_word(int a, int w);
- // ATTENTION: w is treated as unsigned.
- // BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w);
-
- public static native boolean BN_add(int r, int a, int b);
- // int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
-
- public static native boolean BN_sub(int r, int a, int b);
- // int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
-
- public static native boolean BN_gcd(int r, int a, int b);
- // int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
-
- public static native boolean BN_mul(int r, int a, int b);
- // int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
-
- public static native boolean BN_exp(int r, int a, int p);
- // int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
-
- // OPTIONAL:
-// public static native int BN_sqr(BigInteger r, BigInteger a, BN_CTX ctx);
- // int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);
-
- public static native boolean BN_div(int dv, int rem, int m, int d);
- // int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
-
- public static native boolean BN_nnmod(int r, int a, int m);
- // int BN_nnmod(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
-
- public static native boolean BN_mod_exp(int r, int a, int p, int m);
- // int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx);
-
- // OPTIONAL:
-// public static native boolean BN_mod_sqr(BigInteger r, BigInteger a, BigInteger m, BN_CTX ctx);
- // int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
-
-
- public static native boolean BN_mod_inverse(int ret, int a, int n);
- // Returns boolean success AND NOT result BIGNUM handle!
- // BIGNUM * BN_mod_inverse(BIGNUM *ret, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx);
-
-
- public static native boolean BN_generate_prime_ex(int ret, int bits, boolean safe,
- int add, int rem, int cb);
- // int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,
- // const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb);
-
- public static native boolean BN_is_prime_ex(int p, int nchecks, int cb);
- // int BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, BN_GENCB *cb);
-
- // OPTIONAL:
- // int BN_is_prime_fasttest_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx,
- // int do_trial_division, BN_GENCB *cb);
-
-// RAND_add(rnd);
-
-}
diff --git a/openssl/src/main/native/NativeBN.cpp b/openssl/src/main/native/NativeBN.cpp
deleted file mode 100644
index 3d129c8..0000000
--- a/openssl/src/main/native/NativeBN.cpp
+++ /dev/null
@@ -1,551 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Native glue for Java class org.openssl.NativeBN
- */
-
-#define LOG_TAG "NativeBN"
-
-#include "JNIHelp.h"
-#include "ScopedPrimitiveArray.h"
-#include "ScopedUtfChars.h"
-#include "UniquePtr.h"
-#include "jni.h"
-#include <assert.h>
-#include <openssl/bn.h>
-#include <openssl/crypto.h>
-#include <openssl/err.h>
-#include <stdio.h>
-
-struct BN_CTX_Deleter {
- void operator()(BN_CTX* p) const {
- BN_CTX_free(p);
- }
-};
-typedef UniquePtr<BN_CTX, BN_CTX_Deleter> Unique_BN_CTX;
-
-static int isValidHandle (JNIEnv* env, void* handle, const char *message) {
- if (handle == NULL) {
- jniThrowNullPointerException(env, message);
- return JNI_FALSE;
- }
- return JNI_TRUE;
-}
-
-static int oneValidHandle (JNIEnv* env, void* a)
-{
- return isValidHandle(env, a, "Mandatory handle (first) passed as null");
-}
-
-static int twoValidHandles (JNIEnv* env, void* a, void *b)
-{
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- return isValidHandle(env, b, "Mandatory handle (second) passed as null");
-}
-
-static int threeValidHandles (JNIEnv* env, void* a, void *b, void* c)
-{
- if (!twoValidHandles(env, a, b)) return JNI_FALSE;
- return isValidHandle(env, c, "Mandatory handle (third) passed as null");
-}
-
-static int fourValidHandles (JNIEnv* env, void* a, void *b, void* c, void* d)
-{
- if (!threeValidHandles(env, a, b, c)) return JNI_FALSE;
- return isValidHandle(env, d, "Mandatory handle (fourth) passed as null");
-}
-
-static unsigned long NativeBN_ERR_get_error(JNIEnv*, jclass) {
- return ERR_get_error();
-}
-
-static jstring NativeBN_ERR_error_string(JNIEnv* env, jclass, unsigned long e) {
- char* errStr = ERR_error_string(e, NULL);
- return env->NewStringUTF(errStr);
-}
-
-static BIGNUM* NativeBN_BN_new(JNIEnv*, jclass) {
- return BN_new();
-}
-
-static void NativeBN_BN_free(JNIEnv* env, jclass, BIGNUM* a) {
- if (!oneValidHandle(env, a)) return;
- BN_free(a);
-}
-
-static int NativeBN_BN_cmp(JNIEnv* env, jclass, BIGNUM* a, BIGNUM* b) {
- if (!twoValidHandles(env, a, b)) return 1;
- return BN_cmp(a, b);
-}
-
-static jboolean NativeBN_BN_copy(JNIEnv* env, jclass, BIGNUM* to, BIGNUM* from) {
- if (!twoValidHandles(env, to, from)) return JNI_FALSE;
- return (BN_copy(to, from) != NULL);
-}
-
-static jboolean NativeBN_putULongInt(JNIEnv* env, jclass, BIGNUM* a, unsigned long long dw, jboolean neg) {
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- unsigned int hi = dw >> 32; // This shifts without sign extension.
- int lo = (int)dw; // This truncates implicitely.
-
- // cf. litEndInts2bn:
- bn_check_top(a);
- if (bn_wexpand(a, 2) != NULL) {
- a->d[0] = lo;
- a->d[1] = hi;
- a->top = 2;
- a->neg = neg;
- bn_correct_top(a);
- return JNI_TRUE;
- }
- else return JNI_FALSE;
-}
-
-static jboolean NativeBN_putLongInt(JNIEnv* env, jclass cls, BIGNUM* a, long long dw) {
- if (dw >= 0) return NativeBN_putULongInt(env, cls, a, dw, JNI_FALSE);
- else return NativeBN_putULongInt(env, cls, a, -dw, JNI_TRUE);
-}
-
-static int NativeBN_BN_dec2bn(JNIEnv* env, jclass, BIGNUM* a, jstring str) {
- if (!oneValidHandle(env, a)) return -1;
- ScopedUtfChars chars(env, str);
- if (chars.c_str() == NULL) {
- return -1;
- }
- return BN_dec2bn(&a, chars.c_str());
-}
-
-static int NativeBN_BN_hex2bn(JNIEnv* env, jclass, BIGNUM* a, jstring str) {
- if (!oneValidHandle(env, a)) return -1;
- ScopedUtfChars chars(env, str);
- if (chars.c_str() == NULL) {
- return -1;
- }
- return BN_hex2bn(&a, chars.c_str());
-}
-
-static jboolean NativeBN_BN_bin2bn(JNIEnv* env, jclass, jbyteArray arr, int len, jboolean neg, BIGNUM* ret) {
- if (!oneValidHandle(env, ret)) return JNI_FALSE;
- ScopedByteArrayRO bytes(env, arr);
- if (bytes.get() == NULL) {
- return -1;
- }
- jboolean success = (BN_bin2bn(reinterpret_cast<const unsigned char*>(bytes.get()), len, ret) != NULL);
- if (success && neg) {
- BN_set_negative(ret, 1);
- }
- return success;
-}
-
-/**
- * public static native boolean litEndInts2bn(int[], int, int, int)
- * Note:
- * This procedure directly writes the internal representation of BIGNUMs.
- * We do so as there is no direct interface based on Little Endian Integer Arrays.
- * Also note that the same representation is used in the Cordoba Java Implementation of BigIntegers,
- * whereof certain functionality is still being used.
- */
-static jboolean NativeBN_litEndInts2bn(JNIEnv* env, jclass, jintArray arr, int len, jboolean neg, BIGNUM* ret) {
- if (!oneValidHandle(env, ret)) return JNI_FALSE;
- bn_check_top(ret);
- if (len > 0) {
- ScopedIntArrayRO scopedArray(env, arr);
- assert(sizeof(BN_ULONG) == sizeof(jint));
- const BN_ULONG* tmpInts = reinterpret_cast<const BN_ULONG*>(scopedArray.get());
- if ((tmpInts != NULL) && (bn_wexpand(ret, len) != NULL)) {
- int i = len; do { i--; ret->d[i] = tmpInts[i]; } while (i > 0);
- ret->top = len;
- ret->neg = neg;
- // need to call this due to clear byte at top if avoiding
- // having the top bit set (-ve number)
- // Basically get rid of top zero ints:
- bn_correct_top(ret);
- return JNI_TRUE;
- } else {
- return JNI_FALSE;
- }
- } else { // (len = 0) means value = 0 and sign will be 0, too.
- ret->top = 0;
- return JNI_TRUE;
- }
-}
-
-
-#define BYTES2INT(bytes, k) \
- ( (bytes[k + 3] & 0xFF) \
- | (bytes[k + 2] & 0xFF) << 8 \
- | (bytes[k + 1] & 0xFF) << 16 \
- | (bytes[k + 0] & 0xFF) << 24 )
-
-static jboolean negBigEndianBytes2bn(JNIEnv*, jclass, const unsigned char* bytes, int bytesLen, BIGNUM* ret) {
-// We rely on: (BN_BITS2 == 32), i.e. BN_ULONG is unsigned int and has 4 bytes:
-//
- bn_check_top(ret);
-// FIXME: ASSERT (bytesLen > 0);
- int intLen = (bytesLen + 3) / 4;
- int firstNonzeroDigit = -2;
- if (bn_wexpand(ret, intLen) != NULL) {
- BN_ULONG* d = ret->d;
- BN_ULONG di;
- ret->top = intLen;
- int highBytes = bytesLen % 4;
- int k = bytesLen;
- // Put bytes to the int array starting from the end of the byte array
- int i = 0;
- while (k > highBytes) {
- k -= 4;
- di = BYTES2INT(bytes, k);
- if (di != 0) {
- d[i] = -di;
- firstNonzeroDigit = i;
- i++;
- while (k > highBytes) {
- k -= 4;
- d[i] = ~BYTES2INT(bytes, k);
- i++;
- }
- break;
- } else {
- d[i] = 0;
- i++;
- }
- }
- if (highBytes != 0) {
- di = -1;
- // Put the first bytes in the highest element of the int array
- if (firstNonzeroDigit != -2) {
- for (k = 0; k < highBytes; k++) {
- di = (di << 8) | (bytes[k] & 0xFF);
- }
- d[i] = ~di;
- } else {
- for (k = 0; k < highBytes; k++) {
- di = (di << 8) | (bytes[k] & 0xFF);
- }
- d[i] = -di;
- }
- }
- return JNI_TRUE;
- }
- else return JNI_FALSE;
-}
-
-static jboolean NativeBN_twosComp2bn(JNIEnv* env, jclass cls, jbyteArray arr, int bytesLen, BIGNUM* ret) {
- if (!oneValidHandle(env, ret)) return JNI_FALSE;
- ScopedByteArrayRO bytes(env, arr);
- if (bytes.get() == NULL) {
- return -1;
- }
- jboolean success;
- const unsigned char* s = reinterpret_cast<const unsigned char*>(bytes.get());
- if ((bytes[0] & 0X80) == 0) { // Positive value!
- //
- // We can use the existing BN implementation for unsigned big endian bytes:
- //
- success = (BN_bin2bn(s, bytesLen, ret) != NULL);
- BN_set_negative(ret, JNI_FALSE);
- } else { // Negative value!
- //
- // We need to apply two's complement:
- //
- success = negBigEndianBytes2bn(env, cls, s, bytesLen, ret);
- BN_set_negative(ret, JNI_TRUE);
- }
- return success;
-}
-
-static long long NativeBN_longInt(JNIEnv* env, jclass, BIGNUM* a) {
- if (!oneValidHandle(env, a)) return -1;
- bn_check_top(a);
- int intLen = a->top;
- BN_ULONG* d = a->d;
- switch (intLen) {
- case 0:
- return 0;
- case 1:
- if (!a->neg) return d[0] & 0X00000000FFFFFFFFLL;
- else return -(d[0] & 0X00000000FFFFFFFFLL);
- default:
- if (!a->neg) return ((long long)d[1] << 32) | (d[0] & 0XFFFFFFFFLL);
- else return -(((long long)d[1] << 32) | (d[0] & 0XFFFFFFFFLL));
- }
-}
-
-static char* leadingZerosTrimmed(char* s) {
- char* p = s;
- if (*p == '-') {
- p++;
- while ((*p == '0') && (*(p + 1) != 0)) { p++; }
- p--;
- *p = '-';
- } else {
- while ((*p == '0') && (*(p + 1) != 0)) { p++; }
- }
- return p;
-}
-
-static jstring NativeBN_BN_bn2dec(JNIEnv* env, jclass, BIGNUM* a) {
- if (!oneValidHandle(env, a)) return NULL;
- char* tmpStr;
- char* retStr;
- tmpStr = BN_bn2dec(a);
- if (tmpStr != NULL) {
- retStr = leadingZerosTrimmed(tmpStr);
- jstring returnJString = env->NewStringUTF(retStr);
- OPENSSL_free(tmpStr);
- return returnJString;
- }
- else return NULL;
-}
-
-static jstring NativeBN_BN_bn2hex(JNIEnv* env, jclass, BIGNUM* a) {
- if (!oneValidHandle(env, a)) return NULL;
- char* tmpStr;
- char* retStr;
- tmpStr = BN_bn2hex(a);
- if (tmpStr != NULL) {
- retStr = leadingZerosTrimmed(tmpStr);
- jstring returnJString = env->NewStringUTF(retStr);
- OPENSSL_free(tmpStr);
- return returnJString;
- }
- else return NULL;
-}
-
-static jbyteArray NativeBN_BN_bn2bin(JNIEnv* env, jclass, BIGNUM* a) {
- if (!oneValidHandle(env, a)) return NULL;
- jbyteArray result = env->NewByteArray(BN_num_bytes(a));
- if (result == NULL) {
- return NULL;
- }
- ScopedByteArrayRW bytes(env, result);
- if (bytes.get() == NULL) {
- return NULL;
- }
- BN_bn2bin(a, reinterpret_cast<unsigned char*>(bytes.get()));
- return result;
-}
-
-static jintArray NativeBN_bn2litEndInts(JNIEnv* env, jclass, BIGNUM* a) {
- if (!oneValidHandle(env, a)) return NULL;
- bn_check_top(a);
- int len = a->top;
- if (len == 0) {
- return NULL;
- }
- jintArray result = env->NewIntArray(len);
- if (result == NULL) {
- return NULL;
- }
- ScopedIntArrayRW ints(env, result);
- BN_ULONG* ulongs = reinterpret_cast<BN_ULONG*>(ints.get());
- if (ulongs == NULL) {
- return NULL;
- }
- int i = len; do { i--; ulongs[i] = a->d[i]; } while (i > 0);
- return result;
-}
-
-static int NativeBN_sign(JNIEnv* env, jclass, BIGNUM* a) {
- if (!oneValidHandle(env, a)) return -2;
- if (BN_is_zero(a)) return 0;
- else if (BN_is_negative(a)) return -1;
- else return 1;
-}
-
-static void NativeBN_BN_set_negative(JNIEnv* env, jclass, BIGNUM* b, int n) {
- if (!oneValidHandle(env, b)) return;
- BN_set_negative(b, n);
-}
-
-static int NativeBN_bitLength(JNIEnv* env, jclass, BIGNUM* a) {
-// We rely on: (BN_BITS2 == 32), i.e. BN_ULONG is unsigned int and has 4 bytes:
-//
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- bn_check_top(a);
- int intLen = a->top;
- if (intLen == 0) return 0;
- BN_ULONG* d = a->d;
- int i = intLen - 1;
- BN_ULONG msd = d[i]; // most significant digit
- if (a->neg) {
- // Handle negative values correctly:
- // i.e. decrement the msd if all other digits are 0:
- // while ((i > 0) && (d[i] != 0)) { i--; }
- do { i--; } while (!((i < 0) || (d[i] != 0)));
- if (i < 0) msd--; // Only if all lower significant digits are 0 we decrement the most significant one.
- }
- return (intLen - 1) * 32 + BN_num_bits_word(msd);
-}
-
-static jboolean NativeBN_BN_is_bit_set(JNIEnv* env, jclass, BIGNUM* a, int n) {
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- return (jboolean)BN_is_bit_set(a, n);
-}
-
-static jboolean NativeBN_modifyBit(JNIEnv* env, jclass, BIGNUM* a, int n, int op) {
-// LOGD("NativeBN_BN_modifyBit");
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- switch (op) {
- case 1: return BN_set_bit(a, n);
- case 0: return BN_clear_bit(a, n);
- case -1:
- if (BN_is_bit_set(a, n)) return BN_clear_bit(a, n);
- else return BN_set_bit(a, n);
- }
- return JNI_FALSE;
-}
-
-static jboolean NativeBN_BN_shift(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, int n) {
- if (!twoValidHandles(env, r, a)) return JNI_FALSE;
- return (n >= 0) ? BN_lshift(r, a, n) : BN_rshift(r, a, -n);
-}
-
-static jboolean NativeBN_BN_add_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- return BN_add_word(a, w);
-}
-
-static jboolean NativeBN_BN_sub_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- return BN_sub_word(a, w);
-}
-
-static jboolean NativeBN_BN_mul_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- return BN_mul_word(a, w);
-}
-
-static BN_ULONG NativeBN_BN_div_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- return BN_div_word(a, w);
-}
-
-static BN_ULONG NativeBN_BN_mod_word(JNIEnv* env, jclass, BIGNUM *a, BN_ULONG w) {
- if (!oneValidHandle(env, a)) return JNI_FALSE;
- return BN_mod_word(a, w);
-}
-
-static jboolean NativeBN_BN_add(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* b) {
- if (!threeValidHandles(env, r, a, b)) return JNI_FALSE;
- return BN_add(r, a, b);
-}
-
-static jboolean NativeBN_BN_sub(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* b) {
- if (!threeValidHandles(env, r, a, b)) return JNI_FALSE;
- return BN_sub(r, a, b);
-}
-
-static jboolean NativeBN_BN_gcd(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* b) {
- if (!threeValidHandles(env, r, a, b)) return JNI_FALSE;
- Unique_BN_CTX ctx(BN_CTX_new());
- return BN_gcd(r, a, b, ctx.get());
-}
-
-static jboolean NativeBN_BN_mul(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* b) {
- if (!threeValidHandles(env, r, a, b)) return JNI_FALSE;
- Unique_BN_CTX ctx(BN_CTX_new());
- return BN_mul(r, a, b, ctx.get());
-}
-
-static jboolean NativeBN_BN_exp(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* p) {
- if (!threeValidHandles(env, r, a, p)) return JNI_FALSE;
- Unique_BN_CTX ctx(BN_CTX_new());
- return BN_exp(r, a, p, ctx.get());
-}
-
-static jboolean NativeBN_BN_div(JNIEnv* env, jclass, BIGNUM* dv, BIGNUM* rem, BIGNUM* m, BIGNUM* d) {
- if (!fourValidHandles(env, (rem ? rem : dv), (dv ? dv : rem), m, d)) return JNI_FALSE;
- Unique_BN_CTX ctx(BN_CTX_new());
- return BN_div(dv, rem, m, d, ctx.get());
-}
-
-static jboolean NativeBN_BN_nnmod(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* m) {
- if (!threeValidHandles(env, r, a, m)) return JNI_FALSE;
- Unique_BN_CTX ctx(BN_CTX_new());
- return BN_nnmod(r, a, m, ctx.get());
-}
-
-static jboolean NativeBN_BN_mod_exp(JNIEnv* env, jclass, BIGNUM* r, BIGNUM* a, BIGNUM* p, BIGNUM* m) {
- if (!fourValidHandles(env, r, a, p, m)) return JNI_FALSE;
- Unique_BN_CTX ctx(BN_CTX_new());
- return BN_mod_exp(r, a, p, m, ctx.get());
-}
-
-static jboolean NativeBN_BN_mod_inverse(JNIEnv* env, jclass, BIGNUM* ret, BIGNUM* a, BIGNUM* n) {
- if (!threeValidHandles(env, ret, a, n)) return JNI_FALSE;
- Unique_BN_CTX ctx(BN_CTX_new());
- return (BN_mod_inverse(ret, a, n, ctx.get()) != NULL);
-}
-
-static jboolean NativeBN_BN_generate_prime_ex(JNIEnv* env, jclass, BIGNUM* ret, int bits, jboolean safe,
- BIGNUM* add, BIGNUM* rem, jint cb) {
- if (!oneValidHandle(env, ret)) return JNI_FALSE;
- return BN_generate_prime_ex(ret, bits, safe, add, rem, (BN_GENCB*) cb);
-}
-
-static jboolean NativeBN_BN_is_prime_ex(JNIEnv* env, jclass, BIGNUM* p, int nchecks, jint cb) {
- if (!oneValidHandle(env, p)) return JNI_FALSE;
- Unique_BN_CTX ctx(BN_CTX_new());
- return BN_is_prime_ex(p, nchecks, ctx.get(), (BN_GENCB*) cb);
-}
-
-static JNINativeMethod gMethods[] = {
- { "BN_add", "(III)Z", (void*)NativeBN_BN_add },
- { "BN_add_word", "(II)Z", (void*)NativeBN_BN_add_word },
- { "BN_bin2bn", "([BIZI)Z", (void*)NativeBN_BN_bin2bn },
- { "BN_bn2bin", "(I)[B", (void*)NativeBN_BN_bn2bin },
- { "BN_bn2dec", "(I)Ljava/lang/String;", (void*)NativeBN_BN_bn2dec },
- { "BN_bn2hex", "(I)Ljava/lang/String;", (void*)NativeBN_BN_bn2hex },
- { "BN_cmp", "(II)I", (void*)NativeBN_BN_cmp },
- { "BN_copy", "(II)Z", (void*)NativeBN_BN_copy },
- { "BN_dec2bn", "(ILjava/lang/String;)I", (void*)NativeBN_BN_dec2bn },
- { "BN_div", "(IIII)Z", (void*)NativeBN_BN_div },
- { "BN_div_word", "(II)I", (void*)NativeBN_BN_div_word },
- { "BN_exp", "(III)Z", (void*)NativeBN_BN_exp },
- { "BN_free", "(I)V", (void*)NativeBN_BN_free },
- { "BN_gcd", "(III)Z", (void*)NativeBN_BN_gcd },
- { "BN_generate_prime_ex", "(IIZIII)Z", (void*)NativeBN_BN_generate_prime_ex },
- { "BN_hex2bn", "(ILjava/lang/String;)I", (void*)NativeBN_BN_hex2bn },
- { "BN_is_bit_set", "(II)Z", (void*)NativeBN_BN_is_bit_set },
- { "BN_is_prime_ex", "(III)Z", (void*)NativeBN_BN_is_prime_ex },
- { "BN_mod_exp", "(IIII)Z", (void*)NativeBN_BN_mod_exp },
- { "BN_mod_inverse", "(III)Z", (void*)NativeBN_BN_mod_inverse },
- { "BN_mod_word", "(II)I", (void*)NativeBN_BN_mod_word },
- { "BN_mul", "(III)Z", (void*)NativeBN_BN_mul },
- { "BN_mul_word", "(II)Z", (void*)NativeBN_BN_mul_word },
- { "BN_new", "()I", (void*)NativeBN_BN_new },
- { "BN_nnmod", "(III)Z", (void*)NativeBN_BN_nnmod },
- { "BN_set_negative", "(II)V", (void*)NativeBN_BN_set_negative },
- { "BN_shift", "(III)Z", (void*)NativeBN_BN_shift },
- { "BN_sub", "(III)Z", (void*)NativeBN_BN_sub },
- { "BN_sub_word", "(II)Z", (void*)NativeBN_BN_sub_word },
- { "ERR_error_string", "(I)Ljava/lang/String;", (void*)NativeBN_ERR_error_string },
- { "ERR_get_error", "()I", (void*)NativeBN_ERR_get_error },
- { "bitLength", "(I)I", (void*)NativeBN_bitLength },
- { "bn2litEndInts", "(I)[I", (void*)NativeBN_bn2litEndInts },
- { "litEndInts2bn", "([IIZI)Z", (void*)NativeBN_litEndInts2bn },
- { "longInt", "(I)J", (void*)NativeBN_longInt },
- { "modifyBit", "(III)Z", (void*)NativeBN_modifyBit },
- { "putLongInt", "(IJ)Z", (void*)NativeBN_putLongInt },
- { "putULongInt", "(IJZ)Z", (void*)NativeBN_putULongInt },
- { "sign", "(I)I", (void*)NativeBN_sign },
- { "twosComp2bn", "([BII)Z", (void*)NativeBN_twosComp2bn },
-};
-int register_org_openssl_NativeBN(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "org/openssl/NativeBN", gMethods, NELEM(gMethods));
-}
diff --git a/openssl/src/main/native/sub.mk b/openssl/src/main/native/sub.mk
deleted file mode 100644
index ce4d4d4..0000000
--- a/openssl/src/main/native/sub.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-# This file is included by the top-level libcore Makefile.
-# It's not a normal makefile, so we don't include CLEAR_VARS
-# or BUILD_*_LIBRARY.
-
-LOCAL_SRC_FILES := \
- NativeBN.cpp
-
-LOCAL_C_INCLUDES += \
- external/openssl/include
-
-# Any shared/static libs that are listed here must also
-# be listed in libs/nativehelper/Makefile.
-# TODO: fix this requirement
-
-LOCAL_SHARED_LIBRARIES += \
- libcrypto
-
-LOCAL_STATIC_LIBRARIES +=