summaryrefslogtreecommitdiff
path: root/luni/src
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/main/java/libcore/math/NativeBN.java10
-rw-r--r--luni/src/main/native/libcore_math_NativeBN.cpp26
2 files changed, 6 insertions, 30 deletions
diff --git a/luni/src/main/java/libcore/math/NativeBN.java b/luni/src/main/java/libcore/math/NativeBN.java
index fb1cb78a50..8b2ea0f1ee 100644
--- a/luni/src/main/java/libcore/math/NativeBN.java
+++ b/luni/src/main/java/libcore/math/NativeBN.java
@@ -14,9 +14,6 @@
* limitations under the License.
*/
-// TODO: Prune out the methods we no longer need after replacing the BigInteger
-// code.
-
package libcore.math;
/**
@@ -36,13 +33,6 @@ public final class NativeBN {
// word at index 0.
public static native int[] bn2litEndInts(long a);
- public static native int sign(long a);
- // Returns -1, 0, 1 AND NOT boolean.
- // #define BN_is_negative(a) ((a)->neg != 0)
-
- public static native void BN_set_negative(long b, int n);
- // void BN_set_negative(BIGNUM *b, int n);
-
public static native void BN_mul(long r, long a, long b);
// int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
diff --git a/luni/src/main/native/libcore_math_NativeBN.cpp b/luni/src/main/native/libcore_math_NativeBN.cpp
index a123014bc5..dc4b947358 100644
--- a/luni/src/main/native/libcore_math_NativeBN.cpp
+++ b/luni/src/main/native/libcore_math_NativeBN.cpp
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-// TODO: Check that we handle context allocation failures correctly.
-
#define LOG_TAG "NativeBN"
#include <stdio.h>
@@ -142,36 +140,26 @@ static jintArray NativeBN_bn2litEndInts(JNIEnv* env, jclass, jlong a0) {
return result;
}
-static int NativeBN_sign(JNIEnv*, jclass, jlong a) {
- if (BN_is_zero(toBigNum(a))) {
- return 0;
- } else if (BN_is_negative(toBigNum(a))) {
- return -1;
- }
- return 1;
-}
-
-static void NativeBN_BN_set_negative(JNIEnv*, jclass, jlong b, int n) {
- BN_set_negative(toBigNum(b), n);
-}
-
static void NativeBN_BN_mul(JNIEnv* env, jclass, jlong r, jlong a, jlong b) {
Unique_BN_CTX ctx(BN_CTX_new());
- if (!BN_mul(toBigNum(r), toBigNum(a), toBigNum(b), ctx.get())) {
+ BN_CTX* ctxp = ctx.get();
+ if (!ctxp || !BN_mul(toBigNum(r), toBigNum(a), toBigNum(b), ctxp)) {
throwException(env);
}
}
static void NativeBN_BN_div(JNIEnv* env, jclass, jlong q, jlong rem, jlong num, jlong divisor) {
Unique_BN_CTX ctx(BN_CTX_new());
- if (!BN_div(toBigNum(q), toBigNum(rem), toBigNum(num), toBigNum(divisor), ctx.get())) {
+ BN_CTX* ctxp = ctx.get();
+ if (!ctxp || !BN_div(toBigNum(q), toBigNum(rem), toBigNum(num), toBigNum(divisor), ctxp)) {
throwException(env);
}
}
static void NativeBN_BN_mod_exp(JNIEnv* env, jclass, jlong r, jlong a, jlong p, jlong m) {
Unique_BN_CTX ctx(BN_CTX_new());
- if (!BN_mod_exp(toBigNum(r), toBigNum(a), toBigNum(p), toBigNum(m), ctx.get())) {
+ BN_CTX* ctxp = ctx.get();
+ if (!ctxp || !BN_mod_exp(toBigNum(r), toBigNum(a), toBigNum(p), toBigNum(m), ctxp)) {
throwException(env);
}
}
@@ -182,10 +170,8 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeBN, BN_mod_exp, "(JJJJ)V"),
NATIVE_METHOD(NativeBN, BN_mul, "(JJJ)V"),
NATIVE_METHOD(NativeBN, BN_new, "()J"),
- NATIVE_METHOD(NativeBN, BN_set_negative, "(JI)V"),
NATIVE_METHOD(NativeBN, bn2litEndInts, "(J)[I"),
NATIVE_METHOD(NativeBN, litEndInts2bn, "([IIZJ)V"),
- NATIVE_METHOD(NativeBN, sign, "(J)I"),
};
void register_libcore_math_NativeBN(JNIEnv* env) {
jniRegisterNativeMethods(env, "libcore/math/NativeBN", gMethods, NELEM(gMethods));