• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package java.math;
18 
19 final class NativeBN {
20 
BN_new()21     public static native long BN_new();
22     // BIGNUM *BN_new(void);
23 
BN_free(long a)24     public static native void BN_free(long a);
25     // void BN_free(BIGNUM *a);
26 
BN_cmp(long a, long b)27     public static native int BN_cmp(long a, long b);
28     // int BN_cmp(const BIGNUM *a, const BIGNUM *b);
29 
BN_copy(long to, long from)30     public static native void BN_copy(long to, long from);
31     // BIGNUM *BN_copy(BIGNUM *to, const BIGNUM *from);
32 
putLongInt(long a, long dw)33     public static native void putLongInt(long a, long dw);
putULongInt(long a, long dw, boolean neg)34     public static native void putULongInt(long a, long dw, boolean neg);
35 
BN_dec2bn(long a, String str)36     public static native int BN_dec2bn(long a, String str);
37     // int BN_dec2bn(BIGNUM **a, const char *str);
38 
BN_hex2bn(long a, String str)39     public static native int BN_hex2bn(long a, String str);
40     // int BN_hex2bn(BIGNUM **a, const char *str);
41 
BN_bin2bn(byte[] s, int len, boolean neg, long ret)42     public static native void BN_bin2bn(byte[] s, int len, boolean neg, long ret);
43     // BIGNUM * BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
44     // BN-Docu: s is taken as unsigned big endian;
45     // Additional parameter: neg.
46 
litEndInts2bn(int[] ints, int len, boolean neg, long ret)47     public static native void litEndInts2bn(int[] ints, int len, boolean neg, long ret);
48 
twosComp2bn(byte[] s, int len, long ret)49     public static native void twosComp2bn(byte[] s, int len, long ret);
50 
51 
longInt(long a)52     public static native long longInt(long a);
53     // unsigned long BN_get_word(BIGNUM *a);
54 
BN_bn2dec(long a)55     public static native String BN_bn2dec(long a);
56     // char * BN_bn2dec(const BIGNUM *a);
57 
BN_bn2hex(long a)58     public static native String BN_bn2hex(long a);
59     // char * BN_bn2hex(const BIGNUM *a);
60 
BN_bn2bin(long a)61     public static native byte[] BN_bn2bin(long a);
62     // Returns result byte[] AND NOT length.
63     // int BN_bn2bin(const BIGNUM *a, unsigned char *to);
64 
bn2litEndInts(long a)65     public static native int[] bn2litEndInts(long a);
66 
sign(long a)67     public static native int sign(long a);
68     // Returns -1, 0, 1 AND NOT boolean.
69     // #define BN_is_negative(a) ((a)->neg != 0)
70 
BN_set_negative(long b, int n)71     public static native void BN_set_negative(long b, int n);
72     // void BN_set_negative(BIGNUM *b, int n);
73 
bitLength(long a)74     public static native int bitLength(long a);
75 
BN_is_bit_set(long a, int n)76     public static native boolean BN_is_bit_set(long a, int n);
77     // int BN_is_bit_set(const BIGNUM *a, int n);
78 
BN_shift(long r, long a, int n)79     public static native void BN_shift(long r, long a, int n);
80     // int BN_shift(BIGNUM *r, const BIGNUM *a, int n);
81 
BN_add_word(long a, int w)82     public static native void BN_add_word(long a, int w);
83     // ATTENTION: w is treated as unsigned.
84     // int BN_add_word(BIGNUM *a, BN_ULONG w);
85 
BN_mul_word(long a, int w)86     public static native void BN_mul_word(long a, int w);
87     // ATTENTION: w is treated as unsigned.
88     // int BN_mul_word(BIGNUM *a, BN_ULONG w);
89 
BN_mod_word(long a, int w)90     public static native int BN_mod_word(long a, int w);
91     // ATTENTION: w is treated as unsigned.
92     // BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w);
93 
BN_add(long r, long a, long b)94     public static native void BN_add(long r, long a, long b);
95     // int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
96 
BN_sub(long r, long a, long b)97     public static native void BN_sub(long r, long a, long b);
98     // int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
99 
BN_gcd(long r, long a, long b)100     public static native void BN_gcd(long r, long a, long b);
101     // int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
102 
BN_mul(long r, long a, long b)103     public static native void BN_mul(long r, long a, long b);
104     // int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
105 
BN_exp(long r, long a, long p)106     public static native void BN_exp(long r, long a, long p);
107     // int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
108 
BN_div(long dv, long rem, long m, long d)109     public static native void BN_div(long dv, long rem, long m, long d);
110     // int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
111 
BN_nnmod(long r, long a, long m)112     public static native void BN_nnmod(long r, long a, long m);
113     // int BN_nnmod(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
114 
BN_mod_exp(long r, long a, long p, long m)115     public static native void BN_mod_exp(long r, long a, long p, long m);
116     // int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx);
117 
BN_mod_inverse(long ret, long a, long n)118     public static native void BN_mod_inverse(long ret, long a, long n);
119     // BIGNUM * BN_mod_inverse(BIGNUM *ret, const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx);
120 
121 
BN_generate_prime_ex(long ret, int bits, boolean safe, long add, long rem, long cb)122     public static native void BN_generate_prime_ex(long ret, int bits, boolean safe,
123                                                    long add, long rem, long cb);
124     // int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,
125     //         const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb);
126 
BN_is_prime_ex(long p, int nchecks, long cb)127     public static native boolean BN_is_prime_ex(long p, int nchecks, long cb);
128     // int BN_is_prime_ex(const BIGNUM *p, int nchecks, BN_CTX *ctx, BN_GENCB *cb);
129 
getNativeFinalizer()130     public static native long getNativeFinalizer();
131     // &BN_free
132 
133     /** Returns the expected size of the native allocation for a BIGNUM.
134      */
size()135     public static long size() {
136         // 36 bytes is an empirically determined approximation.
137         return 36;
138     }
139 }
140