diff options
author | Elliott Hughes <enh@google.com> | 2010-02-03 15:23:07 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-02-03 15:23:07 -0800 |
commit | 13d47bd26b04692f63ff47b0ac8a35af3a0fefa3 (patch) | |
tree | b18183ffb3a9fe17e00b610c988280d32a2407ac /openssl/src/main | |
parent | 0a807e587935a92811a2f3703caab87115363030 (diff) | |
download | libcore-13d47bd26b04692f63ff47b0ac8a35af3a0fefa3.zip libcore-13d47bd26b04692f63ff47b0ac8a35af3a0fefa3.tar.gz libcore-13d47bd26b04692f63ff47b0ac8a35af3a0fefa3.tar.bz2 |
Remove a workaround for an openssl bug that's been fixed upstream.
The >= versus > bug was fixed in openssl somewhere between .98g and .98k (we
don't have _all_ versions conveniently lying around), and our removal of
the disjunct was irrelevant. Call the now-correct upstream code instead of
manually inlining and hacking it.
Also rename BN_lshift to BN_shift, since it handles both left and right shifts.
Diffstat (limited to 'openssl/src/main')
-rw-r--r-- | openssl/src/main/java/org/openssl/NativeBN.java | 7 | ||||
-rw-r--r-- | openssl/src/main/native/BNInterface.c | 71 |
2 files changed, 8 insertions, 70 deletions
diff --git a/openssl/src/main/java/org/openssl/NativeBN.java b/openssl/src/main/java/org/openssl/NativeBN.java index fd796f8..9691204 100644 --- a/openssl/src/main/java/org/openssl/NativeBN.java +++ b/openssl/src/main/java/org/openssl/NativeBN.java @@ -96,11 +96,8 @@ public class NativeBN { // op: 0 = reset; 1 = set; -1 = flip // uses BN_set_bit(), BN_clear_bit() and BN_is_bit_set() - public static native boolean BN_lshift(int r, int a, int n); - // int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); -// public static native int BN_rshift(BigInteger r, BigInteger a, int n); - // int BN_rshift(BIGNUM *r, const BIGNUM *a, int n); - + 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. diff --git a/openssl/src/main/native/BNInterface.c b/openssl/src/main/native/BNInterface.c index ff2a2ae..8ac2395 100644 --- a/openssl/src/main/native/BNInterface.c +++ b/openssl/src/main/native/BNInterface.c @@ -509,72 +509,13 @@ static jboolean NativeBN_modifyBit(JNIEnv* env, jclass cls, BIGNUM* a, int n, in } /** - * public static native int BN_lshift(int, int, int) + * public static native int BN_shift(int, int, int) */ -static jboolean NativeBN_BN_lshift(JNIEnv* env, jclass cls, BIGNUM* r, BIGNUM* a, int n) { -// LOGD("NativeBN_BN_lshift %p %p %d", r, a, n); +static jboolean NativeBN_BN_shift(JNIEnv* env, jclass cls, BIGNUM* r, BIGNUM* a, int n) { if (!twoValidHandles(env, r, a)) return FALSE; - if (n >= 0) return BN_lshift(r, a, n); - - n = -n; -// return BN_rshift(r, a, n); -// Following code insourced from bn_shift.c in order to have bug fixed: -// FIXME: Should report to openssl team!!! - - int i,j,nw,lb,rb; - BN_ULONG *t,*f; - BN_ULONG l,tmp; - - bn_check_top(r); - bn_check_top(a); - - nw=n/BN_BITS2; - rb=n%BN_BITS2; - lb=BN_BITS2-rb; -// Changed "nw > a->top || a->top == 0" to nw >= a->top" as considering this a bug: - if (nw >= a->top) - { - BN_zero(r); - return(1); - } - if (r != a) - { - r->neg=a->neg; - if (bn_wexpand(r,a->top-nw+1) == NULL) return(0); - } - else - { - if (n == 0) - return 1; /* or the copying loop will go berserk */ - } - - f= &(a->d[nw]); - t=r->d; - j=a->top-nw; - r->top=j; - - if (rb == 0) - { - for (i=j; i != 0; i--) - *(t++)= *(f++); - } - else - { - l= *(f++); - for (i=j-1; i != 0; i--) - { - tmp =(l>>rb)&BN_MASK2; - l= *(f++); - *(t++) =(tmp|(l<<lb))&BN_MASK2; - } - *(t++) =(l>>rb)&BN_MASK2; - } - bn_correct_top(r); - bn_check_top(r); - return(1); + return (n >= 0) ? BN_lshift(r, a, n) : BN_rshift(r, a, -n); } - /** * public static native boolean BN_add_word(int, int) */ @@ -698,7 +639,7 @@ static jboolean NativeBN_BN_mod_inverse(JNIEnv* env, jclass cls, BIGNUM* ret, BI static jboolean NativeBN_BN_generate_prime_ex(JNIEnv* env, jclass cls, BIGNUM* ret, int bits, jboolean safe, BIGNUM* add, BIGNUM* rem, jint cb) { if (!oneValidHandle(env, ret)) return FALSE; - return BN_generate_prime_ex(ret, bits, safe, add, rem, cb); + return BN_generate_prime_ex(ret, bits, safe, add, rem, (BN_GENCB*) cb); } /** @@ -706,7 +647,7 @@ static jboolean NativeBN_BN_generate_prime_ex(JNIEnv* env, jclass cls, BIGNUM* r */ static jboolean NativeBN_BN_is_prime_ex(JNIEnv* env, jclass cls, BIGNUM* p, int nchecks, BN_CTX* ctx, jint cb) { if (!oneValidHandle(env, p)) return FALSE; - return BN_is_prime_ex(p, nchecks, ctx, cb); + return BN_is_prime_ex(p, nchecks, ctx, (BN_GENCB*) cb); } @@ -740,7 +681,7 @@ static JNINativeMethod METHODS[] = { { "bitLength", "(I)I", (void*)NativeBN_bitLength }, { "BN_is_bit_set", "(II)Z", (void*)NativeBN_BN_is_bit_set }, { "modifyBit", "(III)Z", (void*)NativeBN_modifyBit }, - { "BN_lshift", "(III)Z", (void*)NativeBN_BN_lshift }, + { "BN_shift", "(III)Z", (void*)NativeBN_BN_shift }, { "BN_add_word", "(II)Z", (void*)NativeBN_BN_add_word }, { "BN_sub_word", "(II)Z", (void*)NativeBN_BN_sub_word }, { "BN_mul_word", "(II)Z", (void*)NativeBN_BN_mul_word }, |