ring-native 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGES.md +7 -0
  4. data/Makefile +5 -0
  5. data/README.md +12 -5
  6. data/Rakefile +4 -0
  7. data/ext/ring/extconf.rb +4 -5
  8. data/lib/ring/native.rb +3 -1
  9. data/lib/ring/native/version.rb +5 -1
  10. data/ring-native.gemspec +6 -6
  11. data/vendor/ring-ffi/Cargo.lock +26 -0
  12. data/vendor/ring-ffi/Cargo.toml +45 -0
  13. data/vendor/ring-ffi/LICENSE +16 -0
  14. data/vendor/ring-ffi/README.md +59 -0
  15. data/vendor/ring-ffi/src/lib.rs +79 -0
  16. metadata +10 -255
  17. data/vendor/ring/BUILDING.md +0 -40
  18. data/vendor/ring/Cargo.toml +0 -43
  19. data/vendor/ring/LICENSE +0 -185
  20. data/vendor/ring/Makefile +0 -35
  21. data/vendor/ring/PORTING.md +0 -163
  22. data/vendor/ring/README.md +0 -113
  23. data/vendor/ring/STYLE.md +0 -197
  24. data/vendor/ring/appveyor.yml +0 -27
  25. data/vendor/ring/build.rs +0 -108
  26. data/vendor/ring/crypto/aes/aes.c +0 -1142
  27. data/vendor/ring/crypto/aes/aes_test.Windows.vcxproj +0 -25
  28. data/vendor/ring/crypto/aes/aes_test.cc +0 -93
  29. data/vendor/ring/crypto/aes/asm/aes-586.pl +0 -2368
  30. data/vendor/ring/crypto/aes/asm/aes-armv4.pl +0 -1249
  31. data/vendor/ring/crypto/aes/asm/aes-x86_64.pl +0 -2246
  32. data/vendor/ring/crypto/aes/asm/aesni-x86.pl +0 -1318
  33. data/vendor/ring/crypto/aes/asm/aesni-x86_64.pl +0 -2084
  34. data/vendor/ring/crypto/aes/asm/aesv8-armx.pl +0 -675
  35. data/vendor/ring/crypto/aes/asm/bsaes-armv7.pl +0 -1364
  36. data/vendor/ring/crypto/aes/asm/bsaes-x86_64.pl +0 -1565
  37. data/vendor/ring/crypto/aes/asm/vpaes-x86.pl +0 -841
  38. data/vendor/ring/crypto/aes/asm/vpaes-x86_64.pl +0 -1116
  39. data/vendor/ring/crypto/aes/internal.h +0 -87
  40. data/vendor/ring/crypto/aes/mode_wrappers.c +0 -61
  41. data/vendor/ring/crypto/bn/add.c +0 -394
  42. data/vendor/ring/crypto/bn/asm/armv4-mont.pl +0 -694
  43. data/vendor/ring/crypto/bn/asm/armv8-mont.pl +0 -1503
  44. data/vendor/ring/crypto/bn/asm/bn-586.pl +0 -774
  45. data/vendor/ring/crypto/bn/asm/co-586.pl +0 -287
  46. data/vendor/ring/crypto/bn/asm/rsaz-avx2.pl +0 -1882
  47. data/vendor/ring/crypto/bn/asm/x86-mont.pl +0 -592
  48. data/vendor/ring/crypto/bn/asm/x86_64-gcc.c +0 -599
  49. data/vendor/ring/crypto/bn/asm/x86_64-mont.pl +0 -1393
  50. data/vendor/ring/crypto/bn/asm/x86_64-mont5.pl +0 -3507
  51. data/vendor/ring/crypto/bn/bn.c +0 -352
  52. data/vendor/ring/crypto/bn/bn_asn1.c +0 -74
  53. data/vendor/ring/crypto/bn/bn_test.Windows.vcxproj +0 -25
  54. data/vendor/ring/crypto/bn/bn_test.cc +0 -1696
  55. data/vendor/ring/crypto/bn/cmp.c +0 -200
  56. data/vendor/ring/crypto/bn/convert.c +0 -433
  57. data/vendor/ring/crypto/bn/ctx.c +0 -311
  58. data/vendor/ring/crypto/bn/div.c +0 -594
  59. data/vendor/ring/crypto/bn/exponentiation.c +0 -1335
  60. data/vendor/ring/crypto/bn/gcd.c +0 -711
  61. data/vendor/ring/crypto/bn/generic.c +0 -1019
  62. data/vendor/ring/crypto/bn/internal.h +0 -316
  63. data/vendor/ring/crypto/bn/montgomery.c +0 -516
  64. data/vendor/ring/crypto/bn/mul.c +0 -888
  65. data/vendor/ring/crypto/bn/prime.c +0 -829
  66. data/vendor/ring/crypto/bn/random.c +0 -334
  67. data/vendor/ring/crypto/bn/rsaz_exp.c +0 -262
  68. data/vendor/ring/crypto/bn/rsaz_exp.h +0 -53
  69. data/vendor/ring/crypto/bn/shift.c +0 -276
  70. data/vendor/ring/crypto/bytestring/bytestring_test.Windows.vcxproj +0 -25
  71. data/vendor/ring/crypto/bytestring/bytestring_test.cc +0 -421
  72. data/vendor/ring/crypto/bytestring/cbb.c +0 -399
  73. data/vendor/ring/crypto/bytestring/cbs.c +0 -227
  74. data/vendor/ring/crypto/bytestring/internal.h +0 -46
  75. data/vendor/ring/crypto/chacha/chacha_generic.c +0 -140
  76. data/vendor/ring/crypto/chacha/chacha_vec.c +0 -323
  77. data/vendor/ring/crypto/chacha/chacha_vec_arm.S +0 -1447
  78. data/vendor/ring/crypto/chacha/chacha_vec_arm_generate.go +0 -153
  79. data/vendor/ring/crypto/cipher/cipher_test.Windows.vcxproj +0 -25
  80. data/vendor/ring/crypto/cipher/e_aes.c +0 -390
  81. data/vendor/ring/crypto/cipher/e_chacha20poly1305.c +0 -208
  82. data/vendor/ring/crypto/cipher/internal.h +0 -173
  83. data/vendor/ring/crypto/cipher/test/aes_128_gcm_tests.txt +0 -543
  84. data/vendor/ring/crypto/cipher/test/aes_128_key_wrap_tests.txt +0 -9
  85. data/vendor/ring/crypto/cipher/test/aes_256_gcm_tests.txt +0 -475
  86. data/vendor/ring/crypto/cipher/test/aes_256_key_wrap_tests.txt +0 -23
  87. data/vendor/ring/crypto/cipher/test/chacha20_poly1305_old_tests.txt +0 -422
  88. data/vendor/ring/crypto/cipher/test/chacha20_poly1305_tests.txt +0 -484
  89. data/vendor/ring/crypto/cipher/test/cipher_test.txt +0 -100
  90. data/vendor/ring/crypto/constant_time_test.Windows.vcxproj +0 -25
  91. data/vendor/ring/crypto/constant_time_test.c +0 -304
  92. data/vendor/ring/crypto/cpu-arm-asm.S +0 -32
  93. data/vendor/ring/crypto/cpu-arm.c +0 -199
  94. data/vendor/ring/crypto/cpu-intel.c +0 -261
  95. data/vendor/ring/crypto/crypto.c +0 -151
  96. data/vendor/ring/crypto/curve25519/asm/x25519-arm.S +0 -2118
  97. data/vendor/ring/crypto/curve25519/curve25519.c +0 -4888
  98. data/vendor/ring/crypto/curve25519/x25519_test.cc +0 -128
  99. data/vendor/ring/crypto/digest/md32_common.h +0 -181
  100. data/vendor/ring/crypto/ec/asm/p256-x86_64-asm.pl +0 -2725
  101. data/vendor/ring/crypto/ec/ec.c +0 -193
  102. data/vendor/ring/crypto/ec/ec_curves.c +0 -61
  103. data/vendor/ring/crypto/ec/ec_key.c +0 -228
  104. data/vendor/ring/crypto/ec/ec_montgomery.c +0 -114
  105. data/vendor/ring/crypto/ec/example_mul.Windows.vcxproj +0 -25
  106. data/vendor/ring/crypto/ec/internal.h +0 -243
  107. data/vendor/ring/crypto/ec/oct.c +0 -253
  108. data/vendor/ring/crypto/ec/p256-64.c +0 -1794
  109. data/vendor/ring/crypto/ec/p256-x86_64-table.h +0 -9548
  110. data/vendor/ring/crypto/ec/p256-x86_64.c +0 -509
  111. data/vendor/ring/crypto/ec/simple.c +0 -1007
  112. data/vendor/ring/crypto/ec/util-64.c +0 -183
  113. data/vendor/ring/crypto/ec/wnaf.c +0 -508
  114. data/vendor/ring/crypto/ecdh/ecdh.c +0 -155
  115. data/vendor/ring/crypto/ecdsa/ecdsa.c +0 -304
  116. data/vendor/ring/crypto/ecdsa/ecdsa_asn1.c +0 -193
  117. data/vendor/ring/crypto/ecdsa/ecdsa_test.Windows.vcxproj +0 -25
  118. data/vendor/ring/crypto/ecdsa/ecdsa_test.cc +0 -327
  119. data/vendor/ring/crypto/header_removed.h +0 -17
  120. data/vendor/ring/crypto/internal.h +0 -495
  121. data/vendor/ring/crypto/libring.Windows.vcxproj +0 -101
  122. data/vendor/ring/crypto/mem.c +0 -98
  123. data/vendor/ring/crypto/modes/asm/aesni-gcm-x86_64.pl +0 -1045
  124. data/vendor/ring/crypto/modes/asm/ghash-armv4.pl +0 -517
  125. data/vendor/ring/crypto/modes/asm/ghash-x86.pl +0 -1393
  126. data/vendor/ring/crypto/modes/asm/ghash-x86_64.pl +0 -1741
  127. data/vendor/ring/crypto/modes/asm/ghashv8-armx.pl +0 -422
  128. data/vendor/ring/crypto/modes/ctr.c +0 -226
  129. data/vendor/ring/crypto/modes/gcm.c +0 -1206
  130. data/vendor/ring/crypto/modes/gcm_test.Windows.vcxproj +0 -25
  131. data/vendor/ring/crypto/modes/gcm_test.c +0 -348
  132. data/vendor/ring/crypto/modes/internal.h +0 -299
  133. data/vendor/ring/crypto/perlasm/arm-xlate.pl +0 -170
  134. data/vendor/ring/crypto/perlasm/readme +0 -100
  135. data/vendor/ring/crypto/perlasm/x86_64-xlate.pl +0 -1164
  136. data/vendor/ring/crypto/perlasm/x86asm.pl +0 -292
  137. data/vendor/ring/crypto/perlasm/x86gas.pl +0 -263
  138. data/vendor/ring/crypto/perlasm/x86masm.pl +0 -200
  139. data/vendor/ring/crypto/perlasm/x86nasm.pl +0 -187
  140. data/vendor/ring/crypto/poly1305/poly1305.c +0 -331
  141. data/vendor/ring/crypto/poly1305/poly1305_arm.c +0 -301
  142. data/vendor/ring/crypto/poly1305/poly1305_arm_asm.S +0 -2015
  143. data/vendor/ring/crypto/poly1305/poly1305_test.Windows.vcxproj +0 -25
  144. data/vendor/ring/crypto/poly1305/poly1305_test.cc +0 -80
  145. data/vendor/ring/crypto/poly1305/poly1305_test.txt +0 -52
  146. data/vendor/ring/crypto/poly1305/poly1305_vec.c +0 -892
  147. data/vendor/ring/crypto/rand/asm/rdrand-x86_64.pl +0 -75
  148. data/vendor/ring/crypto/rand/internal.h +0 -32
  149. data/vendor/ring/crypto/rand/rand.c +0 -189
  150. data/vendor/ring/crypto/rand/urandom.c +0 -219
  151. data/vendor/ring/crypto/rand/windows.c +0 -56
  152. data/vendor/ring/crypto/refcount_c11.c +0 -66
  153. data/vendor/ring/crypto/refcount_lock.c +0 -53
  154. data/vendor/ring/crypto/refcount_test.Windows.vcxproj +0 -25
  155. data/vendor/ring/crypto/refcount_test.c +0 -58
  156. data/vendor/ring/crypto/rsa/blinding.c +0 -462
  157. data/vendor/ring/crypto/rsa/internal.h +0 -108
  158. data/vendor/ring/crypto/rsa/padding.c +0 -300
  159. data/vendor/ring/crypto/rsa/rsa.c +0 -450
  160. data/vendor/ring/crypto/rsa/rsa_asn1.c +0 -261
  161. data/vendor/ring/crypto/rsa/rsa_impl.c +0 -944
  162. data/vendor/ring/crypto/rsa/rsa_test.Windows.vcxproj +0 -25
  163. data/vendor/ring/crypto/rsa/rsa_test.cc +0 -437
  164. data/vendor/ring/crypto/sha/asm/sha-armv8.pl +0 -436
  165. data/vendor/ring/crypto/sha/asm/sha-x86_64.pl +0 -2390
  166. data/vendor/ring/crypto/sha/asm/sha256-586.pl +0 -1275
  167. data/vendor/ring/crypto/sha/asm/sha256-armv4.pl +0 -735
  168. data/vendor/ring/crypto/sha/asm/sha256-armv8.pl +0 -14
  169. data/vendor/ring/crypto/sha/asm/sha256-x86_64.pl +0 -14
  170. data/vendor/ring/crypto/sha/asm/sha512-586.pl +0 -911
  171. data/vendor/ring/crypto/sha/asm/sha512-armv4.pl +0 -666
  172. data/vendor/ring/crypto/sha/asm/sha512-armv8.pl +0 -14
  173. data/vendor/ring/crypto/sha/asm/sha512-x86_64.pl +0 -14
  174. data/vendor/ring/crypto/sha/sha1.c +0 -271
  175. data/vendor/ring/crypto/sha/sha256.c +0 -204
  176. data/vendor/ring/crypto/sha/sha512.c +0 -355
  177. data/vendor/ring/crypto/test/file_test.cc +0 -326
  178. data/vendor/ring/crypto/test/file_test.h +0 -181
  179. data/vendor/ring/crypto/test/malloc.cc +0 -150
  180. data/vendor/ring/crypto/test/scoped_types.h +0 -95
  181. data/vendor/ring/crypto/test/test.Windows.vcxproj +0 -35
  182. data/vendor/ring/crypto/test/test_util.cc +0 -46
  183. data/vendor/ring/crypto/test/test_util.h +0 -41
  184. data/vendor/ring/crypto/thread_none.c +0 -55
  185. data/vendor/ring/crypto/thread_pthread.c +0 -165
  186. data/vendor/ring/crypto/thread_test.Windows.vcxproj +0 -25
  187. data/vendor/ring/crypto/thread_test.c +0 -200
  188. data/vendor/ring/crypto/thread_win.c +0 -282
  189. data/vendor/ring/examples/checkdigest.rs +0 -103
  190. data/vendor/ring/include/openssl/aes.h +0 -121
  191. data/vendor/ring/include/openssl/arm_arch.h +0 -129
  192. data/vendor/ring/include/openssl/base.h +0 -156
  193. data/vendor/ring/include/openssl/bn.h +0 -794
  194. data/vendor/ring/include/openssl/buffer.h +0 -18
  195. data/vendor/ring/include/openssl/bytestring.h +0 -235
  196. data/vendor/ring/include/openssl/chacha.h +0 -37
  197. data/vendor/ring/include/openssl/cmac.h +0 -76
  198. data/vendor/ring/include/openssl/cpu.h +0 -184
  199. data/vendor/ring/include/openssl/crypto.h +0 -43
  200. data/vendor/ring/include/openssl/curve25519.h +0 -88
  201. data/vendor/ring/include/openssl/ec.h +0 -225
  202. data/vendor/ring/include/openssl/ec_key.h +0 -129
  203. data/vendor/ring/include/openssl/ecdh.h +0 -110
  204. data/vendor/ring/include/openssl/ecdsa.h +0 -156
  205. data/vendor/ring/include/openssl/err.h +0 -201
  206. data/vendor/ring/include/openssl/mem.h +0 -101
  207. data/vendor/ring/include/openssl/obj_mac.h +0 -71
  208. data/vendor/ring/include/openssl/opensslfeatures.h +0 -68
  209. data/vendor/ring/include/openssl/opensslv.h +0 -18
  210. data/vendor/ring/include/openssl/ossl_typ.h +0 -18
  211. data/vendor/ring/include/openssl/poly1305.h +0 -51
  212. data/vendor/ring/include/openssl/rand.h +0 -70
  213. data/vendor/ring/include/openssl/rsa.h +0 -399
  214. data/vendor/ring/include/openssl/thread.h +0 -133
  215. data/vendor/ring/include/openssl/type_check.h +0 -71
  216. data/vendor/ring/mk/Common.props +0 -63
  217. data/vendor/ring/mk/Windows.props +0 -42
  218. data/vendor/ring/mk/WindowsTest.props +0 -18
  219. data/vendor/ring/mk/appveyor.bat +0 -62
  220. data/vendor/ring/mk/bottom_of_makefile.mk +0 -54
  221. data/vendor/ring/mk/ring.mk +0 -266
  222. data/vendor/ring/mk/top_of_makefile.mk +0 -214
  223. data/vendor/ring/mk/travis.sh +0 -40
  224. data/vendor/ring/mk/update-travis-yml.py +0 -229
  225. data/vendor/ring/ring.sln +0 -153
  226. data/vendor/ring/src/aead.rs +0 -682
  227. data/vendor/ring/src/agreement.rs +0 -248
  228. data/vendor/ring/src/c.rs +0 -129
  229. data/vendor/ring/src/constant_time.rs +0 -37
  230. data/vendor/ring/src/der.rs +0 -96
  231. data/vendor/ring/src/digest.rs +0 -690
  232. data/vendor/ring/src/digest_tests.txt +0 -57
  233. data/vendor/ring/src/ecc.rs +0 -28
  234. data/vendor/ring/src/ecc_build.rs +0 -279
  235. data/vendor/ring/src/ecc_curves.rs +0 -117
  236. data/vendor/ring/src/ed25519_tests.txt +0 -2579
  237. data/vendor/ring/src/exe_tests.rs +0 -46
  238. data/vendor/ring/src/ffi.rs +0 -29
  239. data/vendor/ring/src/file_test.rs +0 -187
  240. data/vendor/ring/src/hkdf.rs +0 -153
  241. data/vendor/ring/src/hkdf_tests.txt +0 -59
  242. data/vendor/ring/src/hmac.rs +0 -414
  243. data/vendor/ring/src/hmac_tests.txt +0 -97
  244. data/vendor/ring/src/input.rs +0 -312
  245. data/vendor/ring/src/lib.rs +0 -41
  246. data/vendor/ring/src/pbkdf2.rs +0 -265
  247. data/vendor/ring/src/pbkdf2_tests.txt +0 -113
  248. data/vendor/ring/src/polyfill.rs +0 -57
  249. data/vendor/ring/src/rand.rs +0 -28
  250. data/vendor/ring/src/signature.rs +0 -314
  251. data/vendor/ring/third-party/NIST/README.md +0 -9
  252. data/vendor/ring/third-party/NIST/SHAVS/SHA1LongMsg.rsp +0 -263
  253. data/vendor/ring/third-party/NIST/SHAVS/SHA1Monte.rsp +0 -309
  254. data/vendor/ring/third-party/NIST/SHAVS/SHA1ShortMsg.rsp +0 -267
  255. data/vendor/ring/third-party/NIST/SHAVS/SHA224LongMsg.rsp +0 -263
  256. data/vendor/ring/third-party/NIST/SHAVS/SHA224Monte.rsp +0 -309
  257. data/vendor/ring/third-party/NIST/SHAVS/SHA224ShortMsg.rsp +0 -267
  258. data/vendor/ring/third-party/NIST/SHAVS/SHA256LongMsg.rsp +0 -263
  259. data/vendor/ring/third-party/NIST/SHAVS/SHA256Monte.rsp +0 -309
  260. data/vendor/ring/third-party/NIST/SHAVS/SHA256ShortMsg.rsp +0 -267
  261. data/vendor/ring/third-party/NIST/SHAVS/SHA384LongMsg.rsp +0 -519
  262. data/vendor/ring/third-party/NIST/SHAVS/SHA384Monte.rsp +0 -309
  263. data/vendor/ring/third-party/NIST/SHAVS/SHA384ShortMsg.rsp +0 -523
  264. data/vendor/ring/third-party/NIST/SHAVS/SHA512LongMsg.rsp +0 -519
  265. data/vendor/ring/third-party/NIST/SHAVS/SHA512Monte.rsp +0 -309
  266. data/vendor/ring/third-party/NIST/SHAVS/SHA512ShortMsg.rsp +0 -523
  267. data/vendor/ring/third-party/NIST/sha256sums.txt +0 -1
@@ -1,200 +0,0 @@
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
- }
@@ -1,433 +0,0 @@
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
- }