ring-native 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/Gemfile +3 -0
  4. data/README.md +22 -0
  5. data/Rakefile +1 -0
  6. data/ext/ring/extconf.rb +29 -0
  7. data/lib/ring/native.rb +8 -0
  8. data/lib/ring/native/version.rb +5 -0
  9. data/ring-native.gemspec +25 -0
  10. data/vendor/ring/BUILDING.md +40 -0
  11. data/vendor/ring/Cargo.toml +43 -0
  12. data/vendor/ring/LICENSE +185 -0
  13. data/vendor/ring/Makefile +35 -0
  14. data/vendor/ring/PORTING.md +163 -0
  15. data/vendor/ring/README.md +113 -0
  16. data/vendor/ring/STYLE.md +197 -0
  17. data/vendor/ring/appveyor.yml +27 -0
  18. data/vendor/ring/build.rs +108 -0
  19. data/vendor/ring/crypto/aes/aes.c +1142 -0
  20. data/vendor/ring/crypto/aes/aes_test.Windows.vcxproj +25 -0
  21. data/vendor/ring/crypto/aes/aes_test.cc +93 -0
  22. data/vendor/ring/crypto/aes/asm/aes-586.pl +2368 -0
  23. data/vendor/ring/crypto/aes/asm/aes-armv4.pl +1249 -0
  24. data/vendor/ring/crypto/aes/asm/aes-x86_64.pl +2246 -0
  25. data/vendor/ring/crypto/aes/asm/aesni-x86.pl +1318 -0
  26. data/vendor/ring/crypto/aes/asm/aesni-x86_64.pl +2084 -0
  27. data/vendor/ring/crypto/aes/asm/aesv8-armx.pl +675 -0
  28. data/vendor/ring/crypto/aes/asm/bsaes-armv7.pl +1364 -0
  29. data/vendor/ring/crypto/aes/asm/bsaes-x86_64.pl +1565 -0
  30. data/vendor/ring/crypto/aes/asm/vpaes-x86.pl +841 -0
  31. data/vendor/ring/crypto/aes/asm/vpaes-x86_64.pl +1116 -0
  32. data/vendor/ring/crypto/aes/internal.h +87 -0
  33. data/vendor/ring/crypto/aes/mode_wrappers.c +61 -0
  34. data/vendor/ring/crypto/bn/add.c +394 -0
  35. data/vendor/ring/crypto/bn/asm/armv4-mont.pl +694 -0
  36. data/vendor/ring/crypto/bn/asm/armv8-mont.pl +1503 -0
  37. data/vendor/ring/crypto/bn/asm/bn-586.pl +774 -0
  38. data/vendor/ring/crypto/bn/asm/co-586.pl +287 -0
  39. data/vendor/ring/crypto/bn/asm/rsaz-avx2.pl +1882 -0
  40. data/vendor/ring/crypto/bn/asm/x86-mont.pl +592 -0
  41. data/vendor/ring/crypto/bn/asm/x86_64-gcc.c +599 -0
  42. data/vendor/ring/crypto/bn/asm/x86_64-mont.pl +1393 -0
  43. data/vendor/ring/crypto/bn/asm/x86_64-mont5.pl +3507 -0
  44. data/vendor/ring/crypto/bn/bn.c +352 -0
  45. data/vendor/ring/crypto/bn/bn_asn1.c +74 -0
  46. data/vendor/ring/crypto/bn/bn_test.Windows.vcxproj +25 -0
  47. data/vendor/ring/crypto/bn/bn_test.cc +1696 -0
  48. data/vendor/ring/crypto/bn/cmp.c +200 -0
  49. data/vendor/ring/crypto/bn/convert.c +433 -0
  50. data/vendor/ring/crypto/bn/ctx.c +311 -0
  51. data/vendor/ring/crypto/bn/div.c +594 -0
  52. data/vendor/ring/crypto/bn/exponentiation.c +1335 -0
  53. data/vendor/ring/crypto/bn/gcd.c +711 -0
  54. data/vendor/ring/crypto/bn/generic.c +1019 -0
  55. data/vendor/ring/crypto/bn/internal.h +316 -0
  56. data/vendor/ring/crypto/bn/montgomery.c +516 -0
  57. data/vendor/ring/crypto/bn/mul.c +888 -0
  58. data/vendor/ring/crypto/bn/prime.c +829 -0
  59. data/vendor/ring/crypto/bn/random.c +334 -0
  60. data/vendor/ring/crypto/bn/rsaz_exp.c +262 -0
  61. data/vendor/ring/crypto/bn/rsaz_exp.h +53 -0
  62. data/vendor/ring/crypto/bn/shift.c +276 -0
  63. data/vendor/ring/crypto/bytestring/bytestring_test.Windows.vcxproj +25 -0
  64. data/vendor/ring/crypto/bytestring/bytestring_test.cc +421 -0
  65. data/vendor/ring/crypto/bytestring/cbb.c +399 -0
  66. data/vendor/ring/crypto/bytestring/cbs.c +227 -0
  67. data/vendor/ring/crypto/bytestring/internal.h +46 -0
  68. data/vendor/ring/crypto/chacha/chacha_generic.c +140 -0
  69. data/vendor/ring/crypto/chacha/chacha_vec.c +323 -0
  70. data/vendor/ring/crypto/chacha/chacha_vec_arm.S +1447 -0
  71. data/vendor/ring/crypto/chacha/chacha_vec_arm_generate.go +153 -0
  72. data/vendor/ring/crypto/cipher/cipher_test.Windows.vcxproj +25 -0
  73. data/vendor/ring/crypto/cipher/e_aes.c +390 -0
  74. data/vendor/ring/crypto/cipher/e_chacha20poly1305.c +208 -0
  75. data/vendor/ring/crypto/cipher/internal.h +173 -0
  76. data/vendor/ring/crypto/cipher/test/aes_128_gcm_tests.txt +543 -0
  77. data/vendor/ring/crypto/cipher/test/aes_128_key_wrap_tests.txt +9 -0
  78. data/vendor/ring/crypto/cipher/test/aes_256_gcm_tests.txt +475 -0
  79. data/vendor/ring/crypto/cipher/test/aes_256_key_wrap_tests.txt +23 -0
  80. data/vendor/ring/crypto/cipher/test/chacha20_poly1305_old_tests.txt +422 -0
  81. data/vendor/ring/crypto/cipher/test/chacha20_poly1305_tests.txt +484 -0
  82. data/vendor/ring/crypto/cipher/test/cipher_test.txt +100 -0
  83. data/vendor/ring/crypto/constant_time_test.Windows.vcxproj +25 -0
  84. data/vendor/ring/crypto/constant_time_test.c +304 -0
  85. data/vendor/ring/crypto/cpu-arm-asm.S +32 -0
  86. data/vendor/ring/crypto/cpu-arm.c +199 -0
  87. data/vendor/ring/crypto/cpu-intel.c +261 -0
  88. data/vendor/ring/crypto/crypto.c +151 -0
  89. data/vendor/ring/crypto/curve25519/asm/x25519-arm.S +2118 -0
  90. data/vendor/ring/crypto/curve25519/curve25519.c +4888 -0
  91. data/vendor/ring/crypto/curve25519/x25519_test.cc +128 -0
  92. data/vendor/ring/crypto/digest/md32_common.h +181 -0
  93. data/vendor/ring/crypto/ec/asm/p256-x86_64-asm.pl +2725 -0
  94. data/vendor/ring/crypto/ec/ec.c +193 -0
  95. data/vendor/ring/crypto/ec/ec_curves.c +61 -0
  96. data/vendor/ring/crypto/ec/ec_key.c +228 -0
  97. data/vendor/ring/crypto/ec/ec_montgomery.c +114 -0
  98. data/vendor/ring/crypto/ec/example_mul.Windows.vcxproj +25 -0
  99. data/vendor/ring/crypto/ec/internal.h +243 -0
  100. data/vendor/ring/crypto/ec/oct.c +253 -0
  101. data/vendor/ring/crypto/ec/p256-64.c +1794 -0
  102. data/vendor/ring/crypto/ec/p256-x86_64-table.h +9548 -0
  103. data/vendor/ring/crypto/ec/p256-x86_64.c +509 -0
  104. data/vendor/ring/crypto/ec/simple.c +1007 -0
  105. data/vendor/ring/crypto/ec/util-64.c +183 -0
  106. data/vendor/ring/crypto/ec/wnaf.c +508 -0
  107. data/vendor/ring/crypto/ecdh/ecdh.c +155 -0
  108. data/vendor/ring/crypto/ecdsa/ecdsa.c +304 -0
  109. data/vendor/ring/crypto/ecdsa/ecdsa_asn1.c +193 -0
  110. data/vendor/ring/crypto/ecdsa/ecdsa_test.Windows.vcxproj +25 -0
  111. data/vendor/ring/crypto/ecdsa/ecdsa_test.cc +327 -0
  112. data/vendor/ring/crypto/header_removed.h +17 -0
  113. data/vendor/ring/crypto/internal.h +495 -0
  114. data/vendor/ring/crypto/libring.Windows.vcxproj +101 -0
  115. data/vendor/ring/crypto/mem.c +98 -0
  116. data/vendor/ring/crypto/modes/asm/aesni-gcm-x86_64.pl +1045 -0
  117. data/vendor/ring/crypto/modes/asm/ghash-armv4.pl +517 -0
  118. data/vendor/ring/crypto/modes/asm/ghash-x86.pl +1393 -0
  119. data/vendor/ring/crypto/modes/asm/ghash-x86_64.pl +1741 -0
  120. data/vendor/ring/crypto/modes/asm/ghashv8-armx.pl +422 -0
  121. data/vendor/ring/crypto/modes/ctr.c +226 -0
  122. data/vendor/ring/crypto/modes/gcm.c +1206 -0
  123. data/vendor/ring/crypto/modes/gcm_test.Windows.vcxproj +25 -0
  124. data/vendor/ring/crypto/modes/gcm_test.c +348 -0
  125. data/vendor/ring/crypto/modes/internal.h +299 -0
  126. data/vendor/ring/crypto/perlasm/arm-xlate.pl +170 -0
  127. data/vendor/ring/crypto/perlasm/readme +100 -0
  128. data/vendor/ring/crypto/perlasm/x86_64-xlate.pl +1164 -0
  129. data/vendor/ring/crypto/perlasm/x86asm.pl +292 -0
  130. data/vendor/ring/crypto/perlasm/x86gas.pl +263 -0
  131. data/vendor/ring/crypto/perlasm/x86masm.pl +200 -0
  132. data/vendor/ring/crypto/perlasm/x86nasm.pl +187 -0
  133. data/vendor/ring/crypto/poly1305/poly1305.c +331 -0
  134. data/vendor/ring/crypto/poly1305/poly1305_arm.c +301 -0
  135. data/vendor/ring/crypto/poly1305/poly1305_arm_asm.S +2015 -0
  136. data/vendor/ring/crypto/poly1305/poly1305_test.Windows.vcxproj +25 -0
  137. data/vendor/ring/crypto/poly1305/poly1305_test.cc +80 -0
  138. data/vendor/ring/crypto/poly1305/poly1305_test.txt +52 -0
  139. data/vendor/ring/crypto/poly1305/poly1305_vec.c +892 -0
  140. data/vendor/ring/crypto/rand/asm/rdrand-x86_64.pl +75 -0
  141. data/vendor/ring/crypto/rand/internal.h +32 -0
  142. data/vendor/ring/crypto/rand/rand.c +189 -0
  143. data/vendor/ring/crypto/rand/urandom.c +219 -0
  144. data/vendor/ring/crypto/rand/windows.c +56 -0
  145. data/vendor/ring/crypto/refcount_c11.c +66 -0
  146. data/vendor/ring/crypto/refcount_lock.c +53 -0
  147. data/vendor/ring/crypto/refcount_test.Windows.vcxproj +25 -0
  148. data/vendor/ring/crypto/refcount_test.c +58 -0
  149. data/vendor/ring/crypto/rsa/blinding.c +462 -0
  150. data/vendor/ring/crypto/rsa/internal.h +108 -0
  151. data/vendor/ring/crypto/rsa/padding.c +300 -0
  152. data/vendor/ring/crypto/rsa/rsa.c +450 -0
  153. data/vendor/ring/crypto/rsa/rsa_asn1.c +261 -0
  154. data/vendor/ring/crypto/rsa/rsa_impl.c +944 -0
  155. data/vendor/ring/crypto/rsa/rsa_test.Windows.vcxproj +25 -0
  156. data/vendor/ring/crypto/rsa/rsa_test.cc +437 -0
  157. data/vendor/ring/crypto/sha/asm/sha-armv8.pl +436 -0
  158. data/vendor/ring/crypto/sha/asm/sha-x86_64.pl +2390 -0
  159. data/vendor/ring/crypto/sha/asm/sha256-586.pl +1275 -0
  160. data/vendor/ring/crypto/sha/asm/sha256-armv4.pl +735 -0
  161. data/vendor/ring/crypto/sha/asm/sha256-armv8.pl +14 -0
  162. data/vendor/ring/crypto/sha/asm/sha256-x86_64.pl +14 -0
  163. data/vendor/ring/crypto/sha/asm/sha512-586.pl +911 -0
  164. data/vendor/ring/crypto/sha/asm/sha512-armv4.pl +666 -0
  165. data/vendor/ring/crypto/sha/asm/sha512-armv8.pl +14 -0
  166. data/vendor/ring/crypto/sha/asm/sha512-x86_64.pl +14 -0
  167. data/vendor/ring/crypto/sha/sha1.c +271 -0
  168. data/vendor/ring/crypto/sha/sha256.c +204 -0
  169. data/vendor/ring/crypto/sha/sha512.c +355 -0
  170. data/vendor/ring/crypto/test/file_test.cc +326 -0
  171. data/vendor/ring/crypto/test/file_test.h +181 -0
  172. data/vendor/ring/crypto/test/malloc.cc +150 -0
  173. data/vendor/ring/crypto/test/scoped_types.h +95 -0
  174. data/vendor/ring/crypto/test/test.Windows.vcxproj +35 -0
  175. data/vendor/ring/crypto/test/test_util.cc +46 -0
  176. data/vendor/ring/crypto/test/test_util.h +41 -0
  177. data/vendor/ring/crypto/thread_none.c +55 -0
  178. data/vendor/ring/crypto/thread_pthread.c +165 -0
  179. data/vendor/ring/crypto/thread_test.Windows.vcxproj +25 -0
  180. data/vendor/ring/crypto/thread_test.c +200 -0
  181. data/vendor/ring/crypto/thread_win.c +282 -0
  182. data/vendor/ring/examples/checkdigest.rs +103 -0
  183. data/vendor/ring/include/openssl/aes.h +121 -0
  184. data/vendor/ring/include/openssl/arm_arch.h +129 -0
  185. data/vendor/ring/include/openssl/base.h +156 -0
  186. data/vendor/ring/include/openssl/bn.h +794 -0
  187. data/vendor/ring/include/openssl/buffer.h +18 -0
  188. data/vendor/ring/include/openssl/bytestring.h +235 -0
  189. data/vendor/ring/include/openssl/chacha.h +37 -0
  190. data/vendor/ring/include/openssl/cmac.h +76 -0
  191. data/vendor/ring/include/openssl/cpu.h +184 -0
  192. data/vendor/ring/include/openssl/crypto.h +43 -0
  193. data/vendor/ring/include/openssl/curve25519.h +88 -0
  194. data/vendor/ring/include/openssl/ec.h +225 -0
  195. data/vendor/ring/include/openssl/ec_key.h +129 -0
  196. data/vendor/ring/include/openssl/ecdh.h +110 -0
  197. data/vendor/ring/include/openssl/ecdsa.h +156 -0
  198. data/vendor/ring/include/openssl/err.h +201 -0
  199. data/vendor/ring/include/openssl/mem.h +101 -0
  200. data/vendor/ring/include/openssl/obj_mac.h +71 -0
  201. data/vendor/ring/include/openssl/opensslfeatures.h +68 -0
  202. data/vendor/ring/include/openssl/opensslv.h +18 -0
  203. data/vendor/ring/include/openssl/ossl_typ.h +18 -0
  204. data/vendor/ring/include/openssl/poly1305.h +51 -0
  205. data/vendor/ring/include/openssl/rand.h +70 -0
  206. data/vendor/ring/include/openssl/rsa.h +399 -0
  207. data/vendor/ring/include/openssl/thread.h +133 -0
  208. data/vendor/ring/include/openssl/type_check.h +71 -0
  209. data/vendor/ring/mk/Common.props +63 -0
  210. data/vendor/ring/mk/Windows.props +42 -0
  211. data/vendor/ring/mk/WindowsTest.props +18 -0
  212. data/vendor/ring/mk/appveyor.bat +62 -0
  213. data/vendor/ring/mk/bottom_of_makefile.mk +54 -0
  214. data/vendor/ring/mk/ring.mk +266 -0
  215. data/vendor/ring/mk/top_of_makefile.mk +214 -0
  216. data/vendor/ring/mk/travis.sh +40 -0
  217. data/vendor/ring/mk/update-travis-yml.py +229 -0
  218. data/vendor/ring/ring.sln +153 -0
  219. data/vendor/ring/src/aead.rs +682 -0
  220. data/vendor/ring/src/agreement.rs +248 -0
  221. data/vendor/ring/src/c.rs +129 -0
  222. data/vendor/ring/src/constant_time.rs +37 -0
  223. data/vendor/ring/src/der.rs +96 -0
  224. data/vendor/ring/src/digest.rs +690 -0
  225. data/vendor/ring/src/digest_tests.txt +57 -0
  226. data/vendor/ring/src/ecc.rs +28 -0
  227. data/vendor/ring/src/ecc_build.rs +279 -0
  228. data/vendor/ring/src/ecc_curves.rs +117 -0
  229. data/vendor/ring/src/ed25519_tests.txt +2579 -0
  230. data/vendor/ring/src/exe_tests.rs +46 -0
  231. data/vendor/ring/src/ffi.rs +29 -0
  232. data/vendor/ring/src/file_test.rs +187 -0
  233. data/vendor/ring/src/hkdf.rs +153 -0
  234. data/vendor/ring/src/hkdf_tests.txt +59 -0
  235. data/vendor/ring/src/hmac.rs +414 -0
  236. data/vendor/ring/src/hmac_tests.txt +97 -0
  237. data/vendor/ring/src/input.rs +312 -0
  238. data/vendor/ring/src/lib.rs +41 -0
  239. data/vendor/ring/src/pbkdf2.rs +265 -0
  240. data/vendor/ring/src/pbkdf2_tests.txt +113 -0
  241. data/vendor/ring/src/polyfill.rs +57 -0
  242. data/vendor/ring/src/rand.rs +28 -0
  243. data/vendor/ring/src/signature.rs +314 -0
  244. data/vendor/ring/third-party/NIST/README.md +9 -0
  245. data/vendor/ring/third-party/NIST/SHAVS/SHA1LongMsg.rsp +263 -0
  246. data/vendor/ring/third-party/NIST/SHAVS/SHA1Monte.rsp +309 -0
  247. data/vendor/ring/third-party/NIST/SHAVS/SHA1ShortMsg.rsp +267 -0
  248. data/vendor/ring/third-party/NIST/SHAVS/SHA224LongMsg.rsp +263 -0
  249. data/vendor/ring/third-party/NIST/SHAVS/SHA224Monte.rsp +309 -0
  250. data/vendor/ring/third-party/NIST/SHAVS/SHA224ShortMsg.rsp +267 -0
  251. data/vendor/ring/third-party/NIST/SHAVS/SHA256LongMsg.rsp +263 -0
  252. data/vendor/ring/third-party/NIST/SHAVS/SHA256Monte.rsp +309 -0
  253. data/vendor/ring/third-party/NIST/SHAVS/SHA256ShortMsg.rsp +267 -0
  254. data/vendor/ring/third-party/NIST/SHAVS/SHA384LongMsg.rsp +519 -0
  255. data/vendor/ring/third-party/NIST/SHAVS/SHA384Monte.rsp +309 -0
  256. data/vendor/ring/third-party/NIST/SHAVS/SHA384ShortMsg.rsp +523 -0
  257. data/vendor/ring/third-party/NIST/SHAVS/SHA512LongMsg.rsp +519 -0
  258. data/vendor/ring/third-party/NIST/SHAVS/SHA512Monte.rsp +309 -0
  259. data/vendor/ring/third-party/NIST/SHAVS/SHA512ShortMsg.rsp +523 -0
  260. data/vendor/ring/third-party/NIST/sha256sums.txt +1 -0
  261. metadata +333 -0
@@ -0,0 +1,57 @@
1
+ # SHA-1 tests from RFC 3174.
2
+
3
+ Hash = SHA1
4
+ Input = "abc"
5
+ Repeat = 1
6
+ Output = a9993e364706816aba3e25717850c26c9cd0d89d
7
+
8
+ Hash = SHA1
9
+ Input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
10
+ Repeat = 1
11
+ Output = 84983e441c3bd26ebaae4aa1f95129e5e54670f1
12
+
13
+ Hash = SHA1
14
+ Input = "a"
15
+ Repeat = 1000000
16
+ Output = 34aa973cd4c4daa4f61eeb2bdbad27316534016f
17
+
18
+ Hash = SHA1
19
+ Input = "0123456701234567012345670123456701234567012345670123456701234567"
20
+ Repeat = 10
21
+ Output = dea356a2cddd90c7a7ecedc5ebb563934f460452
22
+
23
+ # SHA-256 tests from NIST.
24
+
25
+ Hash = SHA256
26
+ Input = "abc"
27
+ Repeat = 1
28
+ Output = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
29
+
30
+ Hash = SHA256
31
+ Input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
32
+ Repeat = 1
33
+ Output = 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1
34
+
35
+ # SHA-384 tests from NIST.
36
+
37
+ Hash = SHA384
38
+ Input = "abc"
39
+ Repeat = 1
40
+ Output = cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
41
+
42
+ Hash = SHA384
43
+ Input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
44
+ Repeat = 1
45
+ Output = 09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039
46
+
47
+ # SHA-512 tests from NIST
48
+
49
+ Hash = SHA512
50
+ Input = "abc"
51
+ Repeat = 1
52
+ Output = ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
53
+
54
+ Hash = SHA512
55
+ Input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
56
+ Repeat = 1
57
+ Output = 8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909
@@ -0,0 +1,28 @@
1
+ // Copyright 2015 Brian Smith.
2
+ //
3
+ // Permission to use, copy, modify, and/or distribute this software for any
4
+ // purpose with or without fee is hereby granted, provided that the above
5
+ // copyright notice and this permission notice appear in all copies.
6
+ //
7
+ // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8
+ // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10
+ // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
+ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
+ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ #[allow(non_camel_case_types)]
16
+ #[doc(hidden)]
17
+ pub enum EC_GROUP { }
18
+
19
+ extern {
20
+ #[doc(hidden)]
21
+ pub fn EC_GROUP_P256() -> *const EC_GROUP;
22
+
23
+ #[doc(hidden)]
24
+ pub fn EC_GROUP_P384() -> *const EC_GROUP;
25
+
26
+ #[doc(hidden)]
27
+ pub fn EC_GROUP_P521() -> *const EC_GROUP;
28
+ }
@@ -0,0 +1,279 @@
1
+ // Copyright 2015 Brian Smith.
2
+ //
3
+ // Permission to use, copy, modify, and/or distribute this software for any
4
+ // purpose with or without fee is hereby granted, provided that the above
5
+ // copyright notice and this permission notice appear in all copies.
6
+ //
7
+ // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8
+ // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10
+ // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
+ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
+ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ use num;
16
+ use num::integer::Integer as Integral;
17
+ use num::traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero};
18
+ use std;
19
+ use super::ecc_curves::*;
20
+
21
+ pub fn generate_code(out_dir: &str) -> std::io::Result<()> {
22
+ generate_ec_groups(out_dir)
23
+ }
24
+
25
+ // The math
26
+
27
+ type Integer = num::bigint::BigInt;
28
+
29
+ fn mod_inv(a: &Integer, m: &Integer)
30
+ -> Result<Integer, ()> {
31
+ fn extended_gcd(aa: &Integer, bb: &Integer) -> (Integer, Integer, Integer) {
32
+ let mut last_rem = aa.abs();
33
+ let mut rem = bb.abs();
34
+ let mut x = Integer::zero();
35
+ let mut last_x = Integer::one();
36
+ let mut y = Integer::one();
37
+ let mut last_y = Integer::zero();
38
+ while !rem.is_zero() {
39
+ let (quotient, new_rem) = last_rem.div_rem(&rem);
40
+ last_rem = rem;
41
+ rem = new_rem;
42
+
43
+ let new_x = last_x - &quotient * &x;
44
+ last_x = x;
45
+ x = new_x;
46
+
47
+ let new_y = last_y - &quotient * &y;
48
+ last_y = y;
49
+ y = new_y;
50
+ }
51
+ println!("last_rem: {}, aa: {}, bb: {}, last_x: {}, last_y: {}",
52
+ last_rem, aa, bb, last_x, last_y);
53
+ (last_rem,
54
+ if aa.is_negative() { -last_x } else { last_x },
55
+ if bb.is_negative() { -last_y } else { last_y })
56
+ }
57
+
58
+ let (g, x, _) = extended_gcd(a, m);
59
+ if g != Integer::one() {
60
+ return Err(());
61
+ }
62
+ println!("x: {}, x % m: {}", &x, &x % m);
63
+ Ok(x % m)
64
+ }
65
+
66
+ struct ModP {
67
+ rr: Integer,
68
+ r: Integer,
69
+ p: Integer,
70
+ k: u64,
71
+ }
72
+
73
+ #[cfg(target_pointer_width = "64")]
74
+ const LIMB_BITS: usize = 64;
75
+
76
+ #[cfg(target_pointer_width = "32")]
77
+ const LIMB_BITS: usize = 32;
78
+
79
+ impl ModP {
80
+ fn new(p_hex_str: &str) -> Result<ModP, ()> {
81
+ let p = integer_from_hex_str(p_hex_str);
82
+ let p_bits = (p.to_biguint().unwrap().bits() + LIMB_BITS - 1) /
83
+ LIMB_BITS * LIMB_BITS;
84
+ let neg_p = -&p;
85
+
86
+ let r = (Integer::one() << p_bits) % &p;
87
+ let rr = (&r * &r) % &p;
88
+ let tmod = Integer::one() << 64;
89
+ let k = try!(mod_inv(&neg_p, &tmod));
90
+ let mut k = k % (Integer::one() << 64);
91
+ if k.is_negative() {
92
+ k = &k + (Integer::one() << 64);
93
+ }
94
+ let k = k.to_u64().unwrap();
95
+ Ok(ModP {
96
+ p: p.clone(),
97
+ r: r.clone(),
98
+ rr: rr.clone(),
99
+ k: k.clone(),
100
+ })
101
+ }
102
+
103
+ fn encode(&self, n: &Integer) -> Integer {
104
+ (n * &self.r) % &self.p
105
+ }
106
+ }
107
+
108
+ fn integer_from_hex_str(hex_str: &str) -> Integer {
109
+ Integer::from_str_radix(hex_str, 16).unwrap()
110
+ }
111
+
112
+ // Generation of the C code for |EC_GROUP|
113
+ pub fn generate_ec_groups(out_dir: &str) -> std::io::Result<()> {
114
+ use std::io::Write;
115
+
116
+ let mut fragments = SUPPORTED_CURVES.into_iter()
117
+ .map(|x| ec_group(x))
118
+ .collect::<Vec<_>>();
119
+ fragments.insert(0, String::from(EC_GROUPS_BOILERPLATE));
120
+
121
+ // Ensure file ends with newline to avoid undefined behavior
122
+ let code = fragments.join("\n") + "\n";
123
+
124
+ let dest_path = std::path::Path::new(&out_dir).join("ec_curve_data.inl");
125
+ let mut f = try!(std::fs::File::create(&dest_path));
126
+ try!(f.write_all(code.as_bytes()));
127
+ Ok(())
128
+ }
129
+
130
+ fn ec_group(curve: &NISTCurve) -> String {
131
+ assert_eq!(curve.cofactor, 1);
132
+
133
+ let q = ModP::new(&curve.q).unwrap();
134
+
135
+ let n = ModP::new(&curve.n).unwrap();
136
+ let n_minus_2 = &n.p - Integer::from_i8(2).unwrap();
137
+
138
+ let one = Integer::one();
139
+ assert_eq!(curve.a, -3);
140
+ let a = &q.p + Integer::from_i8(curve.a).unwrap();
141
+ let b = integer_from_hex_str(&curve.b);
142
+
143
+ let (generator_x, generator_y) =
144
+ (integer_from_hex_str(&curve.generator.0),
145
+ integer_from_hex_str(&curve.generator.1));
146
+
147
+ let one_mont = q.encode(&one);
148
+ let a_mont = q.encode(&a);
149
+ let b_mont = q.encode(&b);
150
+ let generator_x_mont = q.encode(&generator_x);
151
+ let generator_y_mont = q.encode(&generator_y);
152
+
153
+ format!("
154
+ const EC_GROUP *{ec_group_fn_name}(void) {{
155
+ static const BN_ULONG field_limbs[] = {q};
156
+ static const BN_ULONG field_rr_limbs[] = {q_rr};
157
+ static const BN_ULONG order_limbs[] = {n};
158
+ static const BN_ULONG order_rr_limbs[] = {n_rr};
159
+ static const BN_ULONG order_minus_2_limbs[] = {n_minus_2};
160
+ #if defined({name}_NO_MONT)
161
+ static const BN_ULONG generator_x_limbs[] = {x};
162
+ static const BN_ULONG generator_y_limbs[] = {y};
163
+ static const BN_ULONG a_limbs[] = {a};
164
+ static const BN_ULONG b_limbs[] = {b};
165
+ static const BN_ULONG one_limbs[] = {one};
166
+ #else
167
+ static const BN_ULONG generator_x_limbs[] = {x_mont};
168
+ static const BN_ULONG generator_y_limbs[] = {y_mont};
169
+ static const BN_ULONG a_limbs[] = {a_mont};
170
+ static const BN_ULONG b_limbs[] = {b_mont};
171
+ static const BN_ULONG one_limbs[] = {one_mont};
172
+ #endif
173
+ static const EC_GROUP group = {{
174
+ FIELD(.meth =) &{name}_EC_METHOD,
175
+ FIELD(.generator =) {{
176
+ FIELD(.meth =) &{name}_EC_METHOD,
177
+ FIELD(.X =) STATIC_BIGNUM(generator_x_limbs),
178
+ FIELD(.Y =) STATIC_BIGNUM(generator_y_limbs),
179
+ FIELD(.Z =) STATIC_BIGNUM(one_limbs),
180
+ }},
181
+ FIELD(.order =) STATIC_BIGNUM(order_limbs),
182
+ FIELD(.order_mont =) {{
183
+ FIELD(.RR =) STATIC_BIGNUM(order_rr_limbs),
184
+ FIELD(.N =) STATIC_BIGNUM(order_limbs),
185
+ FIELD(.n0 =) {{ BN_MONT_CTX_N0(0x{n_n1:x}, 0x{n_n0:x}) }},
186
+ }},
187
+ FIELD(.order_minus_2 =) STATIC_BIGNUM(order_minus_2_limbs),
188
+ FIELD(.curve_name =) {nid},
189
+ FIELD(.field =) STATIC_BIGNUM(field_limbs),
190
+ FIELD(.a =) STATIC_BIGNUM(a_limbs),
191
+ FIELD(.b =) STATIC_BIGNUM(b_limbs),
192
+ FIELD(.mont =) {{
193
+ FIELD(.RR =) STATIC_BIGNUM(field_rr_limbs),
194
+ FIELD(.N =) STATIC_BIGNUM(field_limbs),
195
+ FIELD(.n0 =) {{ BN_MONT_CTX_N0(0x{q_n1:x}, 0x{q_n0:x}) }},
196
+ }},
197
+ FIELD(.one =) STATIC_BIGNUM(one_limbs),
198
+ }};
199
+ return &group;
200
+ }}",
201
+ ec_group_fn_name = curve.name.replace("CURVE", "EC_GROUP"),
202
+ name = curve.name,
203
+ nid = curve.nid,
204
+
205
+ q = bn_limbs(&q.p),
206
+ q_rr = bn_limbs(&q.rr),
207
+ q_n0 = (q.k % (1u64 << 32)) as usize,
208
+ q_n1 = (q.k / (1u64 << 32)) as usize,
209
+
210
+ n = bn_limbs(&n.p),
211
+ n_minus_2 = bn_limbs(&n_minus_2),
212
+ n_rr = bn_limbs(&n.rr),
213
+ n_n0 = (n.k % (1u64 << 32)) as usize,
214
+ n_n1 = (n.k / (1u64 << 32)) as usize,
215
+
216
+ one = bn_limbs(&one),
217
+ x = bn_limbs(&generator_x),
218
+ y = bn_limbs(&generator_y),
219
+ a = bn_limbs(&a),
220
+ b = bn_limbs(&b),
221
+
222
+ one_mont = bn_limbs(&one_mont),
223
+ x_mont = bn_limbs(&generator_x_mont),
224
+ y_mont = bn_limbs(&generator_y_mont),
225
+ a_mont = bn_limbs(&a_mont),
226
+ b_mont = bn_limbs(&b_mont))
227
+ .replace("\n ", "\n")
228
+ }
229
+
230
+ fn bn_limbs(value: &Integer) -> String {
231
+ const INDENT: &'static str = " ";
232
+
233
+ let limbs =
234
+ value
235
+ .to_bytes_le()
236
+ .1
237
+ .chunks(4)
238
+ .map(|bytes| {
239
+ let mut place = 0;
240
+ let mut value = 0;
241
+ for b in bytes {
242
+ value |= (*b as u32) << place;
243
+ place += 8;
244
+ }
245
+ value
246
+ })
247
+ .collect::<Vec<_>>()
248
+ .chunks(2)
249
+ .map(|limbs_32x2| {
250
+ match limbs_32x2.len() {
251
+ 2 => format!("{}TOBN(0x{:08x}, 0x{:08x}),\n", INDENT,
252
+ limbs_32x2[1], limbs_32x2[0]),
253
+ 1 => format!("{}0x{:08x},\n", INDENT,
254
+ limbs_32x2[0]),
255
+ _ => unreachable!()
256
+ }
257
+ })
258
+ .collect::<String>();
259
+
260
+ format!("{{\n{} }}", limbs)
261
+ }
262
+
263
+ const EC_GROUPS_BOILERPLATE: &'static str = r##"/* Copyright 2015 Brian Smith.
264
+ *
265
+ * Permission to use, copy, modify, and/or distribute this software for any
266
+ * purpose with or without fee is hereby granted, provided that the above
267
+ * copyright notice and this permission notice appear in all copies.
268
+ *
269
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
270
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
271
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
272
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
273
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
274
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
275
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
276
+
277
+ /* This entire file was generated by ecc_build.rs from
278
+ * https://github.com/briansmith/ring. */
279
+ "##;
@@ -0,0 +1,117 @@
1
+ // Copyright 2015 Brian Smith.
2
+ //
3
+ // Permission to use, copy, modify, and/or distribute this software for any
4
+ // purpose with or without fee is hereby granted, provided that the above
5
+ // copyright notice and this permission notice appear in all copies.
6
+ //
7
+ // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8
+ // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10
+ // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
+ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
+ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ //! Data defining the supported elliptic curves.
16
+
17
+ pub struct NISTCurve {
18
+ pub name: &'static str,
19
+ pub nid: &'static str,
20
+ pub q: &'static str,
21
+ pub n: &'static str,
22
+ pub generator: (&'static str, &'static str),
23
+ pub a: i8, // Must always be -3.
24
+ pub b: &'static str,
25
+ pub cofactor: i8, // Must always be 1.
26
+ }
27
+
28
+ // The curve parameters are from
29
+ // http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf.
30
+
31
+ pub static SUPPORTED_CURVES: [NISTCurve; 4] = [
32
+ NISTCurve {
33
+ name: "CURVE_P224",
34
+
35
+ // 2^224 − 2^96 + 1
36
+ q: "ffffffffffffffffffffffffffffffff000000000000000000000001",
37
+
38
+ n: "ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d",
39
+
40
+ generator:
41
+ ("b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21",
42
+ "bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34"),
43
+
44
+ a: -3,
45
+ b: "b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4",
46
+ cofactor: 1,
47
+
48
+ nid: "NID_secp224r1",
49
+ },
50
+ NISTCurve {
51
+ name: "CURVE_P256",
52
+
53
+ // 2**256 - 2**224 + 2**192 + 2**96 - 1
54
+ q: "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
55
+
56
+ // 2**256 - 2**224 + 2**192 - 2**128 +
57
+ // 0xbce6faada7179e84f3b9cac2fc632551
58
+ n: "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
59
+
60
+ generator:
61
+ ("6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",
62
+ "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),
63
+
64
+ a: -3,
65
+ b: "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b",
66
+ cofactor: 1,
67
+
68
+ nid: "NID_X9_62_prime256v1",
69
+ },
70
+ NISTCurve {
71
+ name: "CURVE_P384",
72
+
73
+ // 2^384 − 2^128 − 2^96 + 2^32 − 1
74
+ q: "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe\
75
+ ffffffff0000000000000000ffffffff",
76
+
77
+ // 2^384 - 2^192 + 0xc7634d81f4372ddf581a0db248b0a77aecec196accc52973
78
+ n: "ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf\
79
+ 581a0db248b0a77aecec196accc52973",
80
+
81
+ generator:
82
+ ("aa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a38\
83
+ 5502f25dbf55296c3a545e3872760ab7",
84
+ "3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c0\
85
+ 0a60b1ce1d7e819d7a431d7c90ea0e5f"),
86
+
87
+ a: -3,
88
+ b: "b3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875a\
89
+ c656398d8a2ed19d2a85c8edd3ec2aef",
90
+ cofactor: 1,
91
+
92
+ nid: "NID_secp384r1",
93
+ },
94
+ NISTCurve {
95
+ name: "CURVE_P521",
96
+
97
+ // 2^521 − 1
98
+ q: "01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
99
+ ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
100
+
101
+ n: "01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\
102
+ fa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409",
103
+
104
+ generator:
105
+ ("00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3d\
106
+ baa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66",
107
+ "011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e66\
108
+ 2c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650"),
109
+
110
+ a: -3,
111
+ b: "0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109\
112
+ e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00",
113
+ cofactor: 1,
114
+
115
+ nid: "NID_secp521r1",
116
+ },
117
+ ];