ring-native 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +3 -0
- data/README.md +22 -0
- data/Rakefile +1 -0
- data/ext/ring/extconf.rb +29 -0
- data/lib/ring/native.rb +8 -0
- data/lib/ring/native/version.rb +5 -0
- data/ring-native.gemspec +25 -0
- data/vendor/ring/BUILDING.md +40 -0
- data/vendor/ring/Cargo.toml +43 -0
- data/vendor/ring/LICENSE +185 -0
- data/vendor/ring/Makefile +35 -0
- data/vendor/ring/PORTING.md +163 -0
- data/vendor/ring/README.md +113 -0
- data/vendor/ring/STYLE.md +197 -0
- data/vendor/ring/appveyor.yml +27 -0
- data/vendor/ring/build.rs +108 -0
- data/vendor/ring/crypto/aes/aes.c +1142 -0
- data/vendor/ring/crypto/aes/aes_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/aes/aes_test.cc +93 -0
- data/vendor/ring/crypto/aes/asm/aes-586.pl +2368 -0
- data/vendor/ring/crypto/aes/asm/aes-armv4.pl +1249 -0
- data/vendor/ring/crypto/aes/asm/aes-x86_64.pl +2246 -0
- data/vendor/ring/crypto/aes/asm/aesni-x86.pl +1318 -0
- data/vendor/ring/crypto/aes/asm/aesni-x86_64.pl +2084 -0
- data/vendor/ring/crypto/aes/asm/aesv8-armx.pl +675 -0
- data/vendor/ring/crypto/aes/asm/bsaes-armv7.pl +1364 -0
- data/vendor/ring/crypto/aes/asm/bsaes-x86_64.pl +1565 -0
- data/vendor/ring/crypto/aes/asm/vpaes-x86.pl +841 -0
- data/vendor/ring/crypto/aes/asm/vpaes-x86_64.pl +1116 -0
- data/vendor/ring/crypto/aes/internal.h +87 -0
- data/vendor/ring/crypto/aes/mode_wrappers.c +61 -0
- data/vendor/ring/crypto/bn/add.c +394 -0
- data/vendor/ring/crypto/bn/asm/armv4-mont.pl +694 -0
- data/vendor/ring/crypto/bn/asm/armv8-mont.pl +1503 -0
- data/vendor/ring/crypto/bn/asm/bn-586.pl +774 -0
- data/vendor/ring/crypto/bn/asm/co-586.pl +287 -0
- data/vendor/ring/crypto/bn/asm/rsaz-avx2.pl +1882 -0
- data/vendor/ring/crypto/bn/asm/x86-mont.pl +592 -0
- data/vendor/ring/crypto/bn/asm/x86_64-gcc.c +599 -0
- data/vendor/ring/crypto/bn/asm/x86_64-mont.pl +1393 -0
- data/vendor/ring/crypto/bn/asm/x86_64-mont5.pl +3507 -0
- data/vendor/ring/crypto/bn/bn.c +352 -0
- data/vendor/ring/crypto/bn/bn_asn1.c +74 -0
- data/vendor/ring/crypto/bn/bn_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/bn/bn_test.cc +1696 -0
- data/vendor/ring/crypto/bn/cmp.c +200 -0
- data/vendor/ring/crypto/bn/convert.c +433 -0
- data/vendor/ring/crypto/bn/ctx.c +311 -0
- data/vendor/ring/crypto/bn/div.c +594 -0
- data/vendor/ring/crypto/bn/exponentiation.c +1335 -0
- data/vendor/ring/crypto/bn/gcd.c +711 -0
- data/vendor/ring/crypto/bn/generic.c +1019 -0
- data/vendor/ring/crypto/bn/internal.h +316 -0
- data/vendor/ring/crypto/bn/montgomery.c +516 -0
- data/vendor/ring/crypto/bn/mul.c +888 -0
- data/vendor/ring/crypto/bn/prime.c +829 -0
- data/vendor/ring/crypto/bn/random.c +334 -0
- data/vendor/ring/crypto/bn/rsaz_exp.c +262 -0
- data/vendor/ring/crypto/bn/rsaz_exp.h +53 -0
- data/vendor/ring/crypto/bn/shift.c +276 -0
- data/vendor/ring/crypto/bytestring/bytestring_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/bytestring/bytestring_test.cc +421 -0
- data/vendor/ring/crypto/bytestring/cbb.c +399 -0
- data/vendor/ring/crypto/bytestring/cbs.c +227 -0
- data/vendor/ring/crypto/bytestring/internal.h +46 -0
- data/vendor/ring/crypto/chacha/chacha_generic.c +140 -0
- data/vendor/ring/crypto/chacha/chacha_vec.c +323 -0
- data/vendor/ring/crypto/chacha/chacha_vec_arm.S +1447 -0
- data/vendor/ring/crypto/chacha/chacha_vec_arm_generate.go +153 -0
- data/vendor/ring/crypto/cipher/cipher_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/cipher/e_aes.c +390 -0
- data/vendor/ring/crypto/cipher/e_chacha20poly1305.c +208 -0
- data/vendor/ring/crypto/cipher/internal.h +173 -0
- data/vendor/ring/crypto/cipher/test/aes_128_gcm_tests.txt +543 -0
- data/vendor/ring/crypto/cipher/test/aes_128_key_wrap_tests.txt +9 -0
- data/vendor/ring/crypto/cipher/test/aes_256_gcm_tests.txt +475 -0
- data/vendor/ring/crypto/cipher/test/aes_256_key_wrap_tests.txt +23 -0
- data/vendor/ring/crypto/cipher/test/chacha20_poly1305_old_tests.txt +422 -0
- data/vendor/ring/crypto/cipher/test/chacha20_poly1305_tests.txt +484 -0
- data/vendor/ring/crypto/cipher/test/cipher_test.txt +100 -0
- data/vendor/ring/crypto/constant_time_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/constant_time_test.c +304 -0
- data/vendor/ring/crypto/cpu-arm-asm.S +32 -0
- data/vendor/ring/crypto/cpu-arm.c +199 -0
- data/vendor/ring/crypto/cpu-intel.c +261 -0
- data/vendor/ring/crypto/crypto.c +151 -0
- data/vendor/ring/crypto/curve25519/asm/x25519-arm.S +2118 -0
- data/vendor/ring/crypto/curve25519/curve25519.c +4888 -0
- data/vendor/ring/crypto/curve25519/x25519_test.cc +128 -0
- data/vendor/ring/crypto/digest/md32_common.h +181 -0
- data/vendor/ring/crypto/ec/asm/p256-x86_64-asm.pl +2725 -0
- data/vendor/ring/crypto/ec/ec.c +193 -0
- data/vendor/ring/crypto/ec/ec_curves.c +61 -0
- data/vendor/ring/crypto/ec/ec_key.c +228 -0
- data/vendor/ring/crypto/ec/ec_montgomery.c +114 -0
- data/vendor/ring/crypto/ec/example_mul.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/ec/internal.h +243 -0
- data/vendor/ring/crypto/ec/oct.c +253 -0
- data/vendor/ring/crypto/ec/p256-64.c +1794 -0
- data/vendor/ring/crypto/ec/p256-x86_64-table.h +9548 -0
- data/vendor/ring/crypto/ec/p256-x86_64.c +509 -0
- data/vendor/ring/crypto/ec/simple.c +1007 -0
- data/vendor/ring/crypto/ec/util-64.c +183 -0
- data/vendor/ring/crypto/ec/wnaf.c +508 -0
- data/vendor/ring/crypto/ecdh/ecdh.c +155 -0
- data/vendor/ring/crypto/ecdsa/ecdsa.c +304 -0
- data/vendor/ring/crypto/ecdsa/ecdsa_asn1.c +193 -0
- data/vendor/ring/crypto/ecdsa/ecdsa_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/ecdsa/ecdsa_test.cc +327 -0
- data/vendor/ring/crypto/header_removed.h +17 -0
- data/vendor/ring/crypto/internal.h +495 -0
- data/vendor/ring/crypto/libring.Windows.vcxproj +101 -0
- data/vendor/ring/crypto/mem.c +98 -0
- data/vendor/ring/crypto/modes/asm/aesni-gcm-x86_64.pl +1045 -0
- data/vendor/ring/crypto/modes/asm/ghash-armv4.pl +517 -0
- data/vendor/ring/crypto/modes/asm/ghash-x86.pl +1393 -0
- data/vendor/ring/crypto/modes/asm/ghash-x86_64.pl +1741 -0
- data/vendor/ring/crypto/modes/asm/ghashv8-armx.pl +422 -0
- data/vendor/ring/crypto/modes/ctr.c +226 -0
- data/vendor/ring/crypto/modes/gcm.c +1206 -0
- data/vendor/ring/crypto/modes/gcm_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/modes/gcm_test.c +348 -0
- data/vendor/ring/crypto/modes/internal.h +299 -0
- data/vendor/ring/crypto/perlasm/arm-xlate.pl +170 -0
- data/vendor/ring/crypto/perlasm/readme +100 -0
- data/vendor/ring/crypto/perlasm/x86_64-xlate.pl +1164 -0
- data/vendor/ring/crypto/perlasm/x86asm.pl +292 -0
- data/vendor/ring/crypto/perlasm/x86gas.pl +263 -0
- data/vendor/ring/crypto/perlasm/x86masm.pl +200 -0
- data/vendor/ring/crypto/perlasm/x86nasm.pl +187 -0
- data/vendor/ring/crypto/poly1305/poly1305.c +331 -0
- data/vendor/ring/crypto/poly1305/poly1305_arm.c +301 -0
- data/vendor/ring/crypto/poly1305/poly1305_arm_asm.S +2015 -0
- data/vendor/ring/crypto/poly1305/poly1305_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/poly1305/poly1305_test.cc +80 -0
- data/vendor/ring/crypto/poly1305/poly1305_test.txt +52 -0
- data/vendor/ring/crypto/poly1305/poly1305_vec.c +892 -0
- data/vendor/ring/crypto/rand/asm/rdrand-x86_64.pl +75 -0
- data/vendor/ring/crypto/rand/internal.h +32 -0
- data/vendor/ring/crypto/rand/rand.c +189 -0
- data/vendor/ring/crypto/rand/urandom.c +219 -0
- data/vendor/ring/crypto/rand/windows.c +56 -0
- data/vendor/ring/crypto/refcount_c11.c +66 -0
- data/vendor/ring/crypto/refcount_lock.c +53 -0
- data/vendor/ring/crypto/refcount_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/refcount_test.c +58 -0
- data/vendor/ring/crypto/rsa/blinding.c +462 -0
- data/vendor/ring/crypto/rsa/internal.h +108 -0
- data/vendor/ring/crypto/rsa/padding.c +300 -0
- data/vendor/ring/crypto/rsa/rsa.c +450 -0
- data/vendor/ring/crypto/rsa/rsa_asn1.c +261 -0
- data/vendor/ring/crypto/rsa/rsa_impl.c +944 -0
- data/vendor/ring/crypto/rsa/rsa_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/rsa/rsa_test.cc +437 -0
- data/vendor/ring/crypto/sha/asm/sha-armv8.pl +436 -0
- data/vendor/ring/crypto/sha/asm/sha-x86_64.pl +2390 -0
- data/vendor/ring/crypto/sha/asm/sha256-586.pl +1275 -0
- data/vendor/ring/crypto/sha/asm/sha256-armv4.pl +735 -0
- data/vendor/ring/crypto/sha/asm/sha256-armv8.pl +14 -0
- data/vendor/ring/crypto/sha/asm/sha256-x86_64.pl +14 -0
- data/vendor/ring/crypto/sha/asm/sha512-586.pl +911 -0
- data/vendor/ring/crypto/sha/asm/sha512-armv4.pl +666 -0
- data/vendor/ring/crypto/sha/asm/sha512-armv8.pl +14 -0
- data/vendor/ring/crypto/sha/asm/sha512-x86_64.pl +14 -0
- data/vendor/ring/crypto/sha/sha1.c +271 -0
- data/vendor/ring/crypto/sha/sha256.c +204 -0
- data/vendor/ring/crypto/sha/sha512.c +355 -0
- data/vendor/ring/crypto/test/file_test.cc +326 -0
- data/vendor/ring/crypto/test/file_test.h +181 -0
- data/vendor/ring/crypto/test/malloc.cc +150 -0
- data/vendor/ring/crypto/test/scoped_types.h +95 -0
- data/vendor/ring/crypto/test/test.Windows.vcxproj +35 -0
- data/vendor/ring/crypto/test/test_util.cc +46 -0
- data/vendor/ring/crypto/test/test_util.h +41 -0
- data/vendor/ring/crypto/thread_none.c +55 -0
- data/vendor/ring/crypto/thread_pthread.c +165 -0
- data/vendor/ring/crypto/thread_test.Windows.vcxproj +25 -0
- data/vendor/ring/crypto/thread_test.c +200 -0
- data/vendor/ring/crypto/thread_win.c +282 -0
- data/vendor/ring/examples/checkdigest.rs +103 -0
- data/vendor/ring/include/openssl/aes.h +121 -0
- data/vendor/ring/include/openssl/arm_arch.h +129 -0
- data/vendor/ring/include/openssl/base.h +156 -0
- data/vendor/ring/include/openssl/bn.h +794 -0
- data/vendor/ring/include/openssl/buffer.h +18 -0
- data/vendor/ring/include/openssl/bytestring.h +235 -0
- data/vendor/ring/include/openssl/chacha.h +37 -0
- data/vendor/ring/include/openssl/cmac.h +76 -0
- data/vendor/ring/include/openssl/cpu.h +184 -0
- data/vendor/ring/include/openssl/crypto.h +43 -0
- data/vendor/ring/include/openssl/curve25519.h +88 -0
- data/vendor/ring/include/openssl/ec.h +225 -0
- data/vendor/ring/include/openssl/ec_key.h +129 -0
- data/vendor/ring/include/openssl/ecdh.h +110 -0
- data/vendor/ring/include/openssl/ecdsa.h +156 -0
- data/vendor/ring/include/openssl/err.h +201 -0
- data/vendor/ring/include/openssl/mem.h +101 -0
- data/vendor/ring/include/openssl/obj_mac.h +71 -0
- data/vendor/ring/include/openssl/opensslfeatures.h +68 -0
- data/vendor/ring/include/openssl/opensslv.h +18 -0
- data/vendor/ring/include/openssl/ossl_typ.h +18 -0
- data/vendor/ring/include/openssl/poly1305.h +51 -0
- data/vendor/ring/include/openssl/rand.h +70 -0
- data/vendor/ring/include/openssl/rsa.h +399 -0
- data/vendor/ring/include/openssl/thread.h +133 -0
- data/vendor/ring/include/openssl/type_check.h +71 -0
- data/vendor/ring/mk/Common.props +63 -0
- data/vendor/ring/mk/Windows.props +42 -0
- data/vendor/ring/mk/WindowsTest.props +18 -0
- data/vendor/ring/mk/appveyor.bat +62 -0
- data/vendor/ring/mk/bottom_of_makefile.mk +54 -0
- data/vendor/ring/mk/ring.mk +266 -0
- data/vendor/ring/mk/top_of_makefile.mk +214 -0
- data/vendor/ring/mk/travis.sh +40 -0
- data/vendor/ring/mk/update-travis-yml.py +229 -0
- data/vendor/ring/ring.sln +153 -0
- data/vendor/ring/src/aead.rs +682 -0
- data/vendor/ring/src/agreement.rs +248 -0
- data/vendor/ring/src/c.rs +129 -0
- data/vendor/ring/src/constant_time.rs +37 -0
- data/vendor/ring/src/der.rs +96 -0
- data/vendor/ring/src/digest.rs +690 -0
- data/vendor/ring/src/digest_tests.txt +57 -0
- data/vendor/ring/src/ecc.rs +28 -0
- data/vendor/ring/src/ecc_build.rs +279 -0
- data/vendor/ring/src/ecc_curves.rs +117 -0
- data/vendor/ring/src/ed25519_tests.txt +2579 -0
- data/vendor/ring/src/exe_tests.rs +46 -0
- data/vendor/ring/src/ffi.rs +29 -0
- data/vendor/ring/src/file_test.rs +187 -0
- data/vendor/ring/src/hkdf.rs +153 -0
- data/vendor/ring/src/hkdf_tests.txt +59 -0
- data/vendor/ring/src/hmac.rs +414 -0
- data/vendor/ring/src/hmac_tests.txt +97 -0
- data/vendor/ring/src/input.rs +312 -0
- data/vendor/ring/src/lib.rs +41 -0
- data/vendor/ring/src/pbkdf2.rs +265 -0
- data/vendor/ring/src/pbkdf2_tests.txt +113 -0
- data/vendor/ring/src/polyfill.rs +57 -0
- data/vendor/ring/src/rand.rs +28 -0
- data/vendor/ring/src/signature.rs +314 -0
- data/vendor/ring/third-party/NIST/README.md +9 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA1LongMsg.rsp +263 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA1Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA1ShortMsg.rsp +267 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA224LongMsg.rsp +263 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA224Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA224ShortMsg.rsp +267 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA256LongMsg.rsp +263 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA256Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA256ShortMsg.rsp +267 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA384LongMsg.rsp +519 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA384Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA384ShortMsg.rsp +523 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA512LongMsg.rsp +519 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA512Monte.rsp +309 -0
- data/vendor/ring/third-party/NIST/SHAVS/SHA512ShortMsg.rsp +523 -0
- data/vendor/ring/third-party/NIST/sha256sums.txt +1 -0
- metadata +333 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
2
|
+
* All rights reserved.
|
3
|
+
*
|
4
|
+
* This package is an SSL implementation written
|
5
|
+
* by Eric Young (eay@cryptsoft.com).
|
6
|
+
* The implementation was written so as to conform with Netscapes SSL.
|
7
|
+
*
|
8
|
+
* This library is free for commercial and non-commercial use as long as
|
9
|
+
* the following conditions are aheared to. The following conditions
|
10
|
+
* apply to all code found in this distribution, be it the RC4, RSA,
|
11
|
+
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
12
|
+
* included with this distribution is covered by the same copyright terms
|
13
|
+
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
14
|
+
*
|
15
|
+
* Copyright remains Eric Young's, and as such any Copyright notices in
|
16
|
+
* the code are not to be removed.
|
17
|
+
* If this package is used in a product, Eric Young should be given attribution
|
18
|
+
* as the author of the parts of the library used.
|
19
|
+
* This can be in the form of a textual message at program startup or
|
20
|
+
* in documentation (online or textual) provided with the package.
|
21
|
+
*
|
22
|
+
* Redistribution and use in source and binary forms, with or without
|
23
|
+
* modification, are permitted provided that the following conditions
|
24
|
+
* are met:
|
25
|
+
* 1. Redistributions of source code must retain the copyright
|
26
|
+
* notice, this list of conditions and the following disclaimer.
|
27
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
28
|
+
* notice, this list of conditions and the following disclaimer in the
|
29
|
+
* documentation and/or other materials provided with the distribution.
|
30
|
+
* 3. All advertising materials mentioning features or use of this software
|
31
|
+
* must display the following acknowledgement:
|
32
|
+
* "This product includes cryptographic software written by
|
33
|
+
* Eric Young (eay@cryptsoft.com)"
|
34
|
+
* The word 'cryptographic' can be left out if the rouines from the library
|
35
|
+
* being used are not cryptographic related :-).
|
36
|
+
* 4. If you include any Windows specific code (or a derivative thereof) from
|
37
|
+
* the apps directory (application code) you must include an acknowledgement:
|
38
|
+
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
39
|
+
*
|
40
|
+
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
41
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
43
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
44
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
45
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
46
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
48
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
49
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
50
|
+
* SUCH DAMAGE.
|
51
|
+
*
|
52
|
+
* The licence and distribution terms for any publically available version or
|
53
|
+
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
54
|
+
* copied and put under another distribution licence
|
55
|
+
* [including the GNU Public Licence.] */
|
56
|
+
|
57
|
+
#include <openssl/bn.h>
|
58
|
+
|
59
|
+
#include "internal.h"
|
60
|
+
|
61
|
+
|
62
|
+
int BN_ucmp(const BIGNUM *a, const BIGNUM *b) {
|
63
|
+
int i;
|
64
|
+
BN_ULONG t1, t2, *ap, *bp;
|
65
|
+
|
66
|
+
i = a->top - b->top;
|
67
|
+
if (i != 0) {
|
68
|
+
return i;
|
69
|
+
}
|
70
|
+
|
71
|
+
ap = a->d;
|
72
|
+
bp = b->d;
|
73
|
+
for (i = a->top - 1; i >= 0; i--) {
|
74
|
+
t1 = ap[i];
|
75
|
+
t2 = bp[i];
|
76
|
+
if (t1 != t2) {
|
77
|
+
return (t1 > t2) ? 1 : -1;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
return 0;
|
82
|
+
}
|
83
|
+
|
84
|
+
int BN_cmp(const BIGNUM *a, const BIGNUM *b) {
|
85
|
+
int i;
|
86
|
+
int gt, lt;
|
87
|
+
BN_ULONG t1, t2;
|
88
|
+
|
89
|
+
if ((a == NULL) || (b == NULL)) {
|
90
|
+
if (a != NULL) {
|
91
|
+
return -1;
|
92
|
+
} else if (b != NULL) {
|
93
|
+
return 1;
|
94
|
+
} else {
|
95
|
+
return 0;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
if (a->neg != b->neg) {
|
100
|
+
if (a->neg) {
|
101
|
+
return -1;
|
102
|
+
}
|
103
|
+
return 1;
|
104
|
+
}
|
105
|
+
if (a->neg == 0) {
|
106
|
+
gt = 1;
|
107
|
+
lt = -1;
|
108
|
+
} else {
|
109
|
+
gt = -1;
|
110
|
+
lt = 1;
|
111
|
+
}
|
112
|
+
|
113
|
+
if (a->top > b->top) {
|
114
|
+
return gt;
|
115
|
+
}
|
116
|
+
if (a->top < b->top) {
|
117
|
+
return lt;
|
118
|
+
}
|
119
|
+
|
120
|
+
for (i = a->top - 1; i >= 0; i--) {
|
121
|
+
t1 = a->d[i];
|
122
|
+
t2 = b->d[i];
|
123
|
+
if (t1 > t2) {
|
124
|
+
return gt;
|
125
|
+
} if (t1 < t2) {
|
126
|
+
return lt;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
return 0;
|
131
|
+
}
|
132
|
+
|
133
|
+
int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n) {
|
134
|
+
int i;
|
135
|
+
BN_ULONG aa, bb;
|
136
|
+
|
137
|
+
aa = a[n - 1];
|
138
|
+
bb = b[n - 1];
|
139
|
+
if (aa != bb) {
|
140
|
+
return (aa > bb) ? 1 : -1;
|
141
|
+
}
|
142
|
+
|
143
|
+
for (i = n - 2; i >= 0; i--) {
|
144
|
+
aa = a[i];
|
145
|
+
bb = b[i];
|
146
|
+
if (aa != bb) {
|
147
|
+
return (aa > bb) ? 1 : -1;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
return 0;
|
151
|
+
}
|
152
|
+
|
153
|
+
int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl) {
|
154
|
+
int n, i;
|
155
|
+
n = cl - 1;
|
156
|
+
|
157
|
+
if (dl < 0) {
|
158
|
+
for (i = dl; i < 0; i++) {
|
159
|
+
if (b[n - i] != 0) {
|
160
|
+
return -1; /* a < b */
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
if (dl > 0) {
|
165
|
+
for (i = dl; i > 0; i--) {
|
166
|
+
if (a[n + i] != 0) {
|
167
|
+
return 1; /* a > b */
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
return bn_cmp_words(a, b, cl);
|
173
|
+
}
|
174
|
+
|
175
|
+
int BN_abs_is_word(const BIGNUM *bn, BN_ULONG w) {
|
176
|
+
switch (bn->top) {
|
177
|
+
case 1:
|
178
|
+
return bn->d[0] == w;
|
179
|
+
case 0:
|
180
|
+
return w == 0;
|
181
|
+
default:
|
182
|
+
return 0;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
int BN_is_zero(const BIGNUM *bn) {
|
187
|
+
return bn->top == 0;
|
188
|
+
}
|
189
|
+
|
190
|
+
int BN_is_one(const BIGNUM *bn) {
|
191
|
+
return bn->neg == 0 && BN_abs_is_word(bn, 1);
|
192
|
+
}
|
193
|
+
|
194
|
+
int BN_is_word(const BIGNUM *bn, BN_ULONG w) {
|
195
|
+
return BN_abs_is_word(bn, w) && (w == 0 || bn->neg == 0);
|
196
|
+
}
|
197
|
+
|
198
|
+
int BN_is_odd(const BIGNUM *bn) {
|
199
|
+
return bn->top > 0 && (bn->d[0] & 1) == 1;
|
200
|
+
}
|
@@ -0,0 +1,433 @@
|
|
1
|
+
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
2
|
+
* All rights reserved.
|
3
|
+
*
|
4
|
+
* This package is an SSL implementation written
|
5
|
+
* by Eric Young (eay@cryptsoft.com).
|
6
|
+
* The implementation was written so as to conform with Netscapes SSL.
|
7
|
+
*
|
8
|
+
* This library is free for commercial and non-commercial use as long as
|
9
|
+
* the following conditions are aheared to. The following conditions
|
10
|
+
* apply to all code found in this distribution, be it the RC4, RSA,
|
11
|
+
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
12
|
+
* included with this distribution is covered by the same copyright terms
|
13
|
+
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
14
|
+
*
|
15
|
+
* Copyright remains Eric Young's, and as such any Copyright notices in
|
16
|
+
* the code are not to be removed.
|
17
|
+
* If this package is used in a product, Eric Young should be given attribution
|
18
|
+
* as the author of the parts of the library used.
|
19
|
+
* This can be in the form of a textual message at program startup or
|
20
|
+
* in documentation (online or textual) provided with the package.
|
21
|
+
*
|
22
|
+
* Redistribution and use in source and binary forms, with or without
|
23
|
+
* modification, are permitted provided that the following conditions
|
24
|
+
* are met:
|
25
|
+
* 1. Redistributions of source code must retain the copyright
|
26
|
+
* notice, this list of conditions and the following disclaimer.
|
27
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
28
|
+
* notice, this list of conditions and the following disclaimer in the
|
29
|
+
* documentation and/or other materials provided with the distribution.
|
30
|
+
* 3. All advertising materials mentioning features or use of this software
|
31
|
+
* must display the following acknowledgement:
|
32
|
+
* "This product includes cryptographic software written by
|
33
|
+
* Eric Young (eay@cryptsoft.com)"
|
34
|
+
* The word 'cryptographic' can be left out if the rouines from the library
|
35
|
+
* being used are not cryptographic related :-).
|
36
|
+
* 4. If you include any Windows specific code (or a derivative thereof) from
|
37
|
+
* the apps directory (application code) you must include an acknowledgement:
|
38
|
+
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
39
|
+
*
|
40
|
+
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
41
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
42
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
43
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
44
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
45
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
46
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
48
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
49
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
50
|
+
* SUCH DAMAGE.
|
51
|
+
*
|
52
|
+
* The licence and distribution terms for any publically available version or
|
53
|
+
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
54
|
+
* copied and put under another distribution licence
|
55
|
+
* [including the GNU Public Licence.] */
|
56
|
+
|
57
|
+
#include <openssl/bn.h>
|
58
|
+
|
59
|
+
#include <assert.h>
|
60
|
+
#include <ctype.h>
|
61
|
+
#include <limits.h>
|
62
|
+
#include <stdio.h>
|
63
|
+
#include <string.h>
|
64
|
+
|
65
|
+
#include <openssl/err.h>
|
66
|
+
#include <openssl/mem.h>
|
67
|
+
|
68
|
+
#include "internal.h"
|
69
|
+
|
70
|
+
BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
|
71
|
+
size_t num_words;
|
72
|
+
unsigned m;
|
73
|
+
BN_ULONG word = 0;
|
74
|
+
BIGNUM *bn = NULL;
|
75
|
+
|
76
|
+
if (ret == NULL) {
|
77
|
+
ret = bn = BN_new();
|
78
|
+
}
|
79
|
+
|
80
|
+
if (ret == NULL) {
|
81
|
+
return NULL;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (len == 0) {
|
85
|
+
ret->top = 0;
|
86
|
+
return ret;
|
87
|
+
}
|
88
|
+
|
89
|
+
num_words = ((len - 1) / BN_BYTES) + 1;
|
90
|
+
m = (len - 1) % BN_BYTES;
|
91
|
+
if (bn_wexpand(ret, num_words) == NULL) {
|
92
|
+
if (bn) {
|
93
|
+
BN_free(bn);
|
94
|
+
}
|
95
|
+
return NULL;
|
96
|
+
}
|
97
|
+
|
98
|
+
/* |bn_wexpand| must check bounds on |num_words| to write it into
|
99
|
+
* |ret->dmax|. */
|
100
|
+
assert(num_words <= INT_MAX);
|
101
|
+
ret->top = (int)num_words;
|
102
|
+
ret->neg = 0;
|
103
|
+
|
104
|
+
while (len--) {
|
105
|
+
word = (word << 8) | *(in++);
|
106
|
+
if (m-- == 0) {
|
107
|
+
ret->d[--num_words] = word;
|
108
|
+
word = 0;
|
109
|
+
m = BN_BYTES - 1;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
/* need to call this due to clear byte at top if avoiding having the top bit
|
114
|
+
* set (-ve number) */
|
115
|
+
bn_correct_top(ret);
|
116
|
+
return ret;
|
117
|
+
}
|
118
|
+
|
119
|
+
size_t BN_bn2bin(const BIGNUM *in, uint8_t *out) {
|
120
|
+
size_t n, i;
|
121
|
+
BN_ULONG l;
|
122
|
+
|
123
|
+
n = i = BN_num_bytes(in);
|
124
|
+
while (i--) {
|
125
|
+
l = in->d[i / BN_BYTES];
|
126
|
+
*(out++) = (unsigned char)(l >> (8 * (i % BN_BYTES))) & 0xff;
|
127
|
+
}
|
128
|
+
return n;
|
129
|
+
}
|
130
|
+
|
131
|
+
/* constant_time_select_ulong returns |x| if |v| is 1 and |y| if |v| is 0. Its
|
132
|
+
* behavior is undefined if |v| takes any other value. */
|
133
|
+
static BN_ULONG constant_time_select_ulong(int v, BN_ULONG x, BN_ULONG y) {
|
134
|
+
BN_ULONG mask = v;
|
135
|
+
mask--;
|
136
|
+
|
137
|
+
return (~mask & x) | (mask & y);
|
138
|
+
}
|
139
|
+
|
140
|
+
/* constant_time_le_size_t returns 1 if |x| <= |y| and 0 otherwise. |x| and |y|
|
141
|
+
* must not have their MSBs set. */
|
142
|
+
static int constant_time_le_size_t(size_t x, size_t y) {
|
143
|
+
return ((x - y - 1) >> (sizeof(size_t) * 8 - 1)) & 1;
|
144
|
+
}
|
145
|
+
|
146
|
+
/* read_word_padded returns the |i|'th word of |in|, if it is not out of
|
147
|
+
* bounds. Otherwise, it returns 0. It does so without branches on the size of
|
148
|
+
* |in|, however it necessarily does not have the same memory access pattern. If
|
149
|
+
* the access would be out of bounds, it reads the last word of |in|. |in| must
|
150
|
+
* not be zero. */
|
151
|
+
static BN_ULONG read_word_padded(const BIGNUM *in, size_t i) {
|
152
|
+
/* Read |in->d[i]| if valid. Otherwise, read the last word. */
|
153
|
+
BN_ULONG l = in->d[constant_time_select_ulong(
|
154
|
+
constant_time_le_size_t(in->dmax, i), in->dmax - 1, i)];
|
155
|
+
|
156
|
+
/* Clamp to zero if above |d->top|. */
|
157
|
+
return constant_time_select_ulong(constant_time_le_size_t(in->top, i), 0, l);
|
158
|
+
}
|
159
|
+
|
160
|
+
int BN_bn2bin_padded(uint8_t *out, size_t len, const BIGNUM *in) {
|
161
|
+
size_t i;
|
162
|
+
BN_ULONG l;
|
163
|
+
|
164
|
+
/* Special case for |in| = 0. Just branch as the probability is negligible. */
|
165
|
+
if (BN_is_zero(in)) {
|
166
|
+
memset(out, 0, len);
|
167
|
+
return 1;
|
168
|
+
}
|
169
|
+
|
170
|
+
/* Check if the integer is too big. This case can exit early in non-constant
|
171
|
+
* time. */
|
172
|
+
if ((size_t)in->top > (len + (BN_BYTES - 1)) / BN_BYTES) {
|
173
|
+
return 0;
|
174
|
+
}
|
175
|
+
if ((len % BN_BYTES) != 0) {
|
176
|
+
l = read_word_padded(in, len / BN_BYTES);
|
177
|
+
if (l >> (8 * (len % BN_BYTES)) != 0) {
|
178
|
+
return 0;
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
/* Write the bytes out one by one. Serialization is done without branching on
|
183
|
+
* the bits of |in| or on |in->top|, but if the routine would otherwise read
|
184
|
+
* out of bounds, the memory access pattern can't be fixed. However, for an
|
185
|
+
* RSA key of size a multiple of the word size, the probability of BN_BYTES
|
186
|
+
* leading zero octets is low.
|
187
|
+
*
|
188
|
+
* See Falko Stenzke, "Manger's Attack revisited", ICICS 2010. */
|
189
|
+
i = len;
|
190
|
+
while (i--) {
|
191
|
+
l = read_word_padded(in, i / BN_BYTES);
|
192
|
+
*(out++) = (uint8_t)(l >> (8 * (i % BN_BYTES))) & 0xff;
|
193
|
+
}
|
194
|
+
return 1;
|
195
|
+
}
|
196
|
+
|
197
|
+
static const char hextable[] = "0123456789abcdef";
|
198
|
+
|
199
|
+
char *BN_bn2hex(const BIGNUM *bn) {
|
200
|
+
int i, j, v, z = 0;
|
201
|
+
char *buf;
|
202
|
+
char *p;
|
203
|
+
|
204
|
+
buf = (char *)OPENSSL_malloc(bn->top * BN_BYTES * 2 + 2);
|
205
|
+
if (buf == NULL) {
|
206
|
+
OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
|
207
|
+
return NULL;
|
208
|
+
}
|
209
|
+
|
210
|
+
p = buf;
|
211
|
+
if (bn->neg) {
|
212
|
+
*(p++) = '-';
|
213
|
+
}
|
214
|
+
|
215
|
+
if (BN_is_zero(bn)) {
|
216
|
+
*(p++) = '0';
|
217
|
+
}
|
218
|
+
|
219
|
+
for (i = bn->top - 1; i >= 0; i--) {
|
220
|
+
for (j = BN_BITS2 - 8; j >= 0; j -= 8) {
|
221
|
+
/* strip leading zeros */
|
222
|
+
v = ((int)(bn->d[i] >> (long)j)) & 0xff;
|
223
|
+
if (z || v != 0) {
|
224
|
+
*(p++) = hextable[v >> 4];
|
225
|
+
*(p++) = hextable[v & 0x0f];
|
226
|
+
z = 1;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
}
|
230
|
+
*p = '\0';
|
231
|
+
|
232
|
+
return buf;
|
233
|
+
}
|
234
|
+
|
235
|
+
/* decode_hex decodes |in_len| bytes of hex data from |in| and updates |bn|. */
|
236
|
+
static int decode_hex(BIGNUM *bn, const char *in, int in_len) {
|
237
|
+
if (in_len > INT_MAX/4) {
|
238
|
+
OPENSSL_PUT_ERROR(BN, BN_R_BIGNUM_TOO_LONG);
|
239
|
+
return 0;
|
240
|
+
}
|
241
|
+
/* |in_len| is the number of hex digits. */
|
242
|
+
if (bn_expand(bn, in_len * 4) == NULL) {
|
243
|
+
return 0;
|
244
|
+
}
|
245
|
+
|
246
|
+
int i = 0;
|
247
|
+
while (in_len > 0) {
|
248
|
+
/* Decode one |BN_ULONG| at a time. */
|
249
|
+
int todo = BN_BYTES * 2;
|
250
|
+
if (todo > in_len) {
|
251
|
+
todo = in_len;
|
252
|
+
}
|
253
|
+
|
254
|
+
BN_ULONG word = 0;
|
255
|
+
int j;
|
256
|
+
for (j = todo; j > 0; j--) {
|
257
|
+
char c = in[in_len - j];
|
258
|
+
|
259
|
+
BN_ULONG hex;
|
260
|
+
if (c >= '0' && c <= '9') {
|
261
|
+
hex = c - '0';
|
262
|
+
} else if (c >= 'a' && c <= 'f') {
|
263
|
+
hex = c - 'a' + 10;
|
264
|
+
} else if (c >= 'A' && c <= 'F') {
|
265
|
+
hex = c - 'A' + 10;
|
266
|
+
} else {
|
267
|
+
hex = 0;
|
268
|
+
/* This shouldn't happen. The caller checks |isxdigit|. */
|
269
|
+
assert(0);
|
270
|
+
}
|
271
|
+
word = (word << 4) | hex;
|
272
|
+
}
|
273
|
+
|
274
|
+
bn->d[i++] = word;
|
275
|
+
in_len -= todo;
|
276
|
+
}
|
277
|
+
assert(i <= bn->dmax);
|
278
|
+
bn->top = i;
|
279
|
+
return 1;
|
280
|
+
}
|
281
|
+
|
282
|
+
/* decode_dec decodes |in_len| bytes of decimal data from |in| and updates |bn|. */
|
283
|
+
static int decode_dec(BIGNUM *bn, const char *in, int in_len) {
|
284
|
+
int i, j;
|
285
|
+
BN_ULONG l = 0;
|
286
|
+
|
287
|
+
/* Decode |BN_DEC_NUM| digits at a time. */
|
288
|
+
j = BN_DEC_NUM - (in_len % BN_DEC_NUM);
|
289
|
+
if (j == BN_DEC_NUM) {
|
290
|
+
j = 0;
|
291
|
+
}
|
292
|
+
l = 0;
|
293
|
+
for (i = 0; i < in_len; i++) {
|
294
|
+
l *= 10;
|
295
|
+
l += in[i] - '0';
|
296
|
+
if (++j == BN_DEC_NUM) {
|
297
|
+
if (!BN_mul_word(bn, BN_DEC_CONV) ||
|
298
|
+
!BN_add_word(bn, l)) {
|
299
|
+
return 0;
|
300
|
+
}
|
301
|
+
l = 0;
|
302
|
+
j = 0;
|
303
|
+
}
|
304
|
+
}
|
305
|
+
return 1;
|
306
|
+
}
|
307
|
+
|
308
|
+
typedef int (*decode_func) (BIGNUM *bn, const char *in, int in_len);
|
309
|
+
typedef int (*char_test_func) (int c);
|
310
|
+
|
311
|
+
static int bn_x2bn(BIGNUM **outp, const char *in, decode_func decode, char_test_func want_char) {
|
312
|
+
BIGNUM *ret = NULL;
|
313
|
+
int neg = 0, i;
|
314
|
+
int num;
|
315
|
+
|
316
|
+
if (in == NULL || *in == 0) {
|
317
|
+
return 0;
|
318
|
+
}
|
319
|
+
|
320
|
+
if (*in == '-') {
|
321
|
+
neg = 1;
|
322
|
+
in++;
|
323
|
+
}
|
324
|
+
|
325
|
+
for (i = 0; want_char((unsigned char)in[i]) && i + neg < INT_MAX; i++) {}
|
326
|
+
|
327
|
+
num = i + neg;
|
328
|
+
if (outp == NULL) {
|
329
|
+
return num;
|
330
|
+
}
|
331
|
+
|
332
|
+
/* in is the start of the hex digits, and it is 'i' long */
|
333
|
+
if (*outp == NULL) {
|
334
|
+
ret = BN_new();
|
335
|
+
if (ret == NULL) {
|
336
|
+
return 0;
|
337
|
+
}
|
338
|
+
} else {
|
339
|
+
ret = *outp;
|
340
|
+
BN_zero(ret);
|
341
|
+
}
|
342
|
+
|
343
|
+
if (!decode(ret, in, i)) {
|
344
|
+
goto err;
|
345
|
+
}
|
346
|
+
|
347
|
+
bn_correct_top(ret);
|
348
|
+
if (!BN_is_zero(ret)) {
|
349
|
+
ret->neg = neg;
|
350
|
+
}
|
351
|
+
|
352
|
+
*outp = ret;
|
353
|
+
return num;
|
354
|
+
|
355
|
+
err:
|
356
|
+
if (*outp == NULL) {
|
357
|
+
BN_free(ret);
|
358
|
+
}
|
359
|
+
|
360
|
+
return 0;
|
361
|
+
}
|
362
|
+
|
363
|
+
int BN_hex2bn(BIGNUM **outp, const char *in) {
|
364
|
+
return bn_x2bn(outp, in, decode_hex, isxdigit);
|
365
|
+
}
|
366
|
+
|
367
|
+
int BN_dec2bn(BIGNUM **outp, const char *in) {
|
368
|
+
return bn_x2bn(outp, in, decode_dec, isdigit);
|
369
|
+
}
|
370
|
+
|
371
|
+
int BN_asc2bn(BIGNUM **outp, const char *in) {
|
372
|
+
const char *const orig_in = in;
|
373
|
+
if (*in == '-') {
|
374
|
+
in++;
|
375
|
+
}
|
376
|
+
|
377
|
+
if (in[0] == '0' && (in[1] == 'X' || in[1] == 'x')) {
|
378
|
+
if (!BN_hex2bn(outp, in+2)) {
|
379
|
+
return 0;
|
380
|
+
}
|
381
|
+
} else {
|
382
|
+
if (!BN_dec2bn(outp, in)) {
|
383
|
+
return 0;
|
384
|
+
}
|
385
|
+
}
|
386
|
+
|
387
|
+
if (*orig_in == '-' && !BN_is_zero(*outp)) {
|
388
|
+
(*outp)->neg = 1;
|
389
|
+
}
|
390
|
+
|
391
|
+
return 1;
|
392
|
+
}
|
393
|
+
|
394
|
+
int BN_print_fp(FILE *fp, const BIGNUM *a) {
|
395
|
+
int i, j, v, z = 0;
|
396
|
+
int ret = 0;
|
397
|
+
|
398
|
+
if (a->neg && fputc('-', fp) != 1) {
|
399
|
+
goto end;
|
400
|
+
}
|
401
|
+
|
402
|
+
if (BN_is_zero(a) && fputc('0', fp) != 1) {
|
403
|
+
goto end;
|
404
|
+
}
|
405
|
+
|
406
|
+
for (i = a->top - 1; i >= 0; i--) {
|
407
|
+
for (j = BN_BITS2 - 4; j >= 0; j -= 4) {
|
408
|
+
/* strip leading zeros */
|
409
|
+
v = ((int)(a->d[i] >> (long)j)) & 0x0f;
|
410
|
+
if (z || v != 0) {
|
411
|
+
if (fputc(hextable[v], fp) != 1) {
|
412
|
+
goto end;
|
413
|
+
}
|
414
|
+
z = 1;
|
415
|
+
}
|
416
|
+
}
|
417
|
+
}
|
418
|
+
ret = 1;
|
419
|
+
|
420
|
+
end:
|
421
|
+
return ret;
|
422
|
+
}
|
423
|
+
|
424
|
+
BN_ULONG BN_get_word(const BIGNUM *bn) {
|
425
|
+
switch (bn->top) {
|
426
|
+
case 0:
|
427
|
+
return 0;
|
428
|
+
case 1:
|
429
|
+
return bn->d[0];
|
430
|
+
default:
|
431
|
+
return BN_MASK2;
|
432
|
+
}
|
433
|
+
}
|