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,75 +0,0 @@
1
- #!/usr/bin/env perl
2
-
3
- # Copyright (c) 2015, Google Inc.
4
- #
5
- # Permission to use, copy, modify, and/or distribute this software for any
6
- # purpose with or without fee is hereby granted, provided that the above
7
- # copyright notice and this permission notice appear in all copies.
8
- #
9
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12
- # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14
- # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15
- # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
16
-
17
- $flavour = shift;
18
- $output = shift;
19
- if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
20
-
21
- $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
22
- ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
23
- die "can't locate x86_64-xlate.pl";
24
-
25
- open OUT,"| \"$^X\" $xlate $flavour $output";
26
- *STDOUT=*OUT;
27
-
28
- print<<___;
29
- .text
30
-
31
- # CRYPTO_rdrand writes eight bytes of random data from the hardware RNG to
32
- # |out|. It returns one on success or zero on hardware failure.
33
- # int CRYPTO_rdrand(uint8_t out[8]);
34
- .globl CRYPTO_rdrand
35
- .type CRYPTO_rdrand,\@function,1
36
- .align 16
37
- CRYPTO_rdrand:
38
- xorq %rax, %rax
39
- # This is rdrand %rcx. It sets rcx to a random value and sets the carry
40
- # flag on success.
41
- .byte 0x48, 0x0f, 0xc7, 0xf1
42
- # An add-with-carry of zero effectively sets %rax to the carry flag.
43
- adcq %rax, %rax
44
- movq %rcx, 0(%rdi)
45
- retq
46
-
47
- # CRYPTO_rdrand_multiple8_buf fills |len| bytes at |buf| with random data from
48
- # the hardware RNG. The |len| argument must be a multiple of eight. It returns
49
- # one on success and zero on hardware failure.
50
- # int CRYPTO_rdrand_multiple8_buf(uint8_t *buf, size_t len);
51
- .globl CRYPTO_rdrand_multiple8_buf
52
- .type CRYPTO_rdrand_multiple8_buf,\@function,2
53
- .align 16
54
- CRYPTO_rdrand_multiple8_buf:
55
- test %rsi, %rsi
56
- jz .Lout
57
- movq \$8, %rdx
58
- .Lloop:
59
- # This is rdrand %rcx. It sets rcx to a random value and sets the carry
60
- # flag on success.
61
- .byte 0x48, 0x0f, 0xc7, 0xf1
62
- jnc .Lerr
63
- movq %rcx, 0(%rdi)
64
- addq %rdx, %rdi
65
- subq %rdx, %rsi
66
- jnz .Lloop
67
- .Lout:
68
- movq \$1, %rax
69
- retq
70
- .Lerr:
71
- xorq %rax, %rax
72
- retq
73
- ___
74
-
75
- close STDOUT; # flush
@@ -1,32 +0,0 @@
1
- /* Copyright (c) 2015, Google Inc.
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 AUTHOR DISCLAIMS ALL WARRANTIES
8
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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
- #ifndef OPENSSL_HEADER_CRYPTO_RAND_INTERNAL_H
16
- #define OPENSSL_HEADER_CRYPTO_RAND_INTERNAL_H
17
-
18
- #if defined(__cplusplus)
19
- extern "C" {
20
- #endif
21
-
22
-
23
- /* CRYPTO_sysrand fills |len| bytes at |buf| with entropy from the operating
24
- * system. */
25
- void CRYPTO_sysrand(uint8_t *buf, size_t len);
26
-
27
-
28
- #if defined(__cplusplus)
29
- } /* extern C */
30
- #endif
31
-
32
- #endif /* OPENSSL_HEADER_CRYPTO_RAND_INTERNAL_H */
@@ -1,189 +0,0 @@
1
- /* Copyright (c) 2014, Google Inc.
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 AUTHOR DISCLAIMS ALL WARRANTIES
8
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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
- #include <openssl/rand.h>
16
-
17
- #include <assert.h>
18
- #include <limits.h>
19
- #include <string.h>
20
-
21
- #include <openssl/chacha.h>
22
- #include <openssl/cpu.h>
23
- #include <openssl/mem.h>
24
-
25
- #include "internal.h"
26
- #include "../internal.h"
27
-
28
-
29
- /* It's assumed that the operating system always has an unfailing source of
30
- * entropy which is accessed via |CRYPTO_sysrand|. (If the operating system
31
- * entropy source fails, it's up to |CRYPTO_sysrand| to abort the process—we
32
- * don't try to handle it.)
33
- *
34
- * In addition, the hardware may provide a low-latency RNG. Intel's rdrand
35
- * instruction is the canonical example of this. When a hardware RNG is
36
- * available we don't need to worry about an RNG failure arising from fork()ing
37
- * the process or moving a VM, so we can keep thread-local RNG state and XOR
38
- * the hardware entropy in.
39
- *
40
- * (We assume that the OS entropy is safe from fork()ing and VM duplication.
41
- * This might be a bit of a leap of faith, esp on Windows, but there's nothing
42
- * that we can do about it.) */
43
-
44
- /* rand_thread_state contains the per-thread state for the RNG. This is only
45
- * used if the system has support for a hardware RNG. */
46
- struct rand_thread_state {
47
- uint8_t key[32];
48
- uint64_t calls_used;
49
- size_t bytes_used;
50
- uint8_t partial_block[64];
51
- unsigned partial_block_used;
52
- };
53
-
54
- /* kMaxCallsPerRefresh is the maximum number of |RAND_bytes| calls that we'll
55
- * serve before reading a new key from the operating system. This only applies
56
- * if we have a hardware RNG. */
57
- static const unsigned kMaxCallsPerRefresh = 1024;
58
-
59
- /* kMaxBytesPerRefresh is the maximum number of bytes that we'll return from
60
- * |RAND_bytes| before reading a new key from the operating system. This only
61
- * applies if we have a hardware RNG. */
62
- static const uint64_t kMaxBytesPerRefresh = 1024 * 1024;
63
-
64
- /* rand_thread_state_free frees a |rand_thread_state|. This is called when a
65
- * thread exits. */
66
- static void rand_thread_state_free(void *state) {
67
- if (state == NULL) {
68
- return;
69
- }
70
-
71
- OPENSSL_cleanse(state, sizeof(struct rand_thread_state));
72
- OPENSSL_free(state);
73
- }
74
-
75
- #if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM)
76
-
77
- /* These functions are defined in asm/rdrand-x86_64.pl */
78
- extern int CRYPTO_rdrand(uint8_t out[8]);
79
- extern int CRYPTO_rdrand_multiple8_buf(uint8_t *buf, size_t len);
80
-
81
- static int have_rdrand(void) {
82
- return (OPENSSL_ia32cap_P[1] & (1u << 30)) != 0;
83
- }
84
-
85
- static int hwrand(uint8_t *buf, size_t len) {
86
- if (!have_rdrand()) {
87
- return 0;
88
- }
89
-
90
- const size_t len_multiple8 = len & ~7;
91
- if (!CRYPTO_rdrand_multiple8_buf(buf, len_multiple8)) {
92
- return 0;
93
- }
94
- len -= len_multiple8;
95
-
96
- if (len != 0) {
97
- assert(len < 8);
98
-
99
- uint8_t rand_buf[8];
100
- if (!CRYPTO_rdrand(rand_buf)) {
101
- return 0;
102
- }
103
- memcpy(buf + len_multiple8, rand_buf, len);
104
- }
105
-
106
- return 1;
107
- }
108
-
109
- #else
110
-
111
- static int hwrand(uint8_t *buf, size_t len) {
112
- return 0;
113
- }
114
-
115
- #endif
116
-
117
- int RAND_bytes(uint8_t *buf, size_t len) {
118
- if (len == 0) {
119
- return 1;
120
- }
121
-
122
- if (!hwrand(buf, len)) {
123
- /* Without a hardware RNG to save us from address-space duplication, the OS
124
- * entropy is used directly. */
125
- CRYPTO_sysrand(buf, len);
126
- return 1;
127
- }
128
-
129
- struct rand_thread_state *state =
130
- CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_RAND);
131
- if (state == NULL) {
132
- state = OPENSSL_malloc(sizeof(struct rand_thread_state));
133
- if (state == NULL ||
134
- !CRYPTO_set_thread_local(OPENSSL_THREAD_LOCAL_RAND, state,
135
- rand_thread_state_free)) {
136
- CRYPTO_sysrand(buf, len);
137
- return 1;
138
- }
139
-
140
- memset(state->partial_block, 0, sizeof(state->partial_block));
141
- state->calls_used = kMaxCallsPerRefresh;
142
- }
143
-
144
- if (state->calls_used >= kMaxCallsPerRefresh ||
145
- state->bytes_used >= kMaxBytesPerRefresh) {
146
- CRYPTO_sysrand(state->key, sizeof(state->key));
147
- state->calls_used = 0;
148
- state->bytes_used = 0;
149
- state->partial_block_used = sizeof(state->partial_block);
150
- }
151
-
152
- if (len >= sizeof(state->partial_block)) {
153
- size_t remaining = len;
154
- while (remaining > 0) {
155
- /* kMaxBytesPerCall is only 2GB, while ChaCha can handle 256GB. But this
156
- * is sufficient and easier on 32-bit. */
157
- static const size_t kMaxBytesPerCall = 0x80000000;
158
- size_t todo = remaining;
159
- if (todo > kMaxBytesPerCall) {
160
- todo = kMaxBytesPerCall;
161
- }
162
- uint8_t nonce[12];
163
- memset(nonce, 0, 4);
164
- memcpy(nonce + 4, &state->calls_used, sizeof(state->calls_used));
165
- CRYPTO_chacha_20(buf, buf, todo, state->key, nonce, 0);
166
- buf += todo;
167
- remaining -= todo;
168
- state->calls_used++;
169
- }
170
- } else {
171
- if (sizeof(state->partial_block) - state->partial_block_used < len) {
172
- uint8_t nonce[12];
173
- memset(nonce, 0, 4);
174
- memcpy(nonce + 4, &state->calls_used, sizeof(state->calls_used));
175
- CRYPTO_chacha_20(state->partial_block, state->partial_block,
176
- sizeof(state->partial_block), state->key, nonce, 0);
177
- state->partial_block_used = 0;
178
- }
179
-
180
- unsigned i;
181
- for (i = 0; i < len; i++) {
182
- buf[i] ^= state->partial_block[state->partial_block_used++];
183
- }
184
- state->calls_used++;
185
- }
186
- state->bytes_used += len;
187
-
188
- return 1;
189
- }
@@ -1,219 +0,0 @@
1
- /* Copyright (c) 2014, Google Inc.
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 AUTHOR DISCLAIMS ALL WARRANTIES
8
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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
- #include <openssl/rand.h>
16
-
17
- #if !defined(OPENSSL_WINDOWS)
18
-
19
- #include <assert.h>
20
- #include <errno.h>
21
- #include <fcntl.h>
22
- #include <string.h>
23
- #include <unistd.h>
24
-
25
- #include <openssl/thread.h>
26
- #include <openssl/mem.h>
27
-
28
- #include "internal.h"
29
- #include "../internal.h"
30
-
31
-
32
- /* This file implements a PRNG by reading from /dev/urandom, optionally with a
33
- * buffer, which is unsafe across |fork|. */
34
-
35
- #define BUF_SIZE 4096
36
-
37
- /* rand_buffer contains unused, random bytes, some of which may have been
38
- * consumed already. */
39
- struct rand_buffer {
40
- size_t used;
41
- uint8_t rand[BUF_SIZE];
42
- };
43
-
44
- /* requested_lock is used to protect the |*_requested| variables. */
45
- static struct CRYPTO_STATIC_MUTEX requested_lock = CRYPTO_STATIC_MUTEX_INIT;
46
-
47
- /* urandom_fd_requested is set by |RAND_set_urandom_fd|. It's protected by
48
- * |requested_lock|. */
49
- static int urandom_fd_requested = -2;
50
-
51
- /* urandom_fd is a file descriptor to /dev/urandom. It's protected by |once|. */
52
- static int urandom_fd = -2;
53
-
54
- /* urandom_buffering_requested is set by |RAND_enable_fork_unsafe_buffering|.
55
- * It's protected by |requested_lock|. */
56
- static int urandom_buffering_requested = 0;
57
-
58
- /* urandom_buffering controls whether buffering is enabled (1) or not (0). This
59
- * is protected by |once|. */
60
- static int urandom_buffering = 0;
61
-
62
- static CRYPTO_once_t once = CRYPTO_ONCE_INIT;
63
-
64
- /* init_once initializes the state of this module to values previously
65
- * requested. This is the only function that modifies |urandom_fd| and
66
- * |urandom_buffering|, whose values may be read safely after calling the
67
- * once. */
68
- static void init_once(void) {
69
- CRYPTO_STATIC_MUTEX_lock_read(&requested_lock);
70
- urandom_buffering = urandom_buffering_requested;
71
- int fd = urandom_fd_requested;
72
- CRYPTO_STATIC_MUTEX_unlock(&requested_lock);
73
-
74
- if (fd == -2) {
75
- do {
76
- fd = open("/dev/urandom", O_RDONLY);
77
- } while (fd == -1 && errno == EINTR);
78
- }
79
-
80
- if (fd < 0) {
81
- abort();
82
- }
83
-
84
- int flags = fcntl(fd, F_GETFD);
85
- if (flags == -1) {
86
- abort();
87
- }
88
- flags |= FD_CLOEXEC;
89
- if (fcntl(fd, F_SETFD, flags) == -1) {
90
- abort();
91
- }
92
- urandom_fd = fd;
93
- }
94
-
95
- void RAND_cleanup(void) {}
96
-
97
- void RAND_set_urandom_fd(int fd) {
98
- fd = dup(fd);
99
- if (fd < 0) {
100
- abort();
101
- }
102
-
103
- CRYPTO_STATIC_MUTEX_lock_write(&requested_lock);
104
- urandom_fd_requested = fd;
105
- CRYPTO_STATIC_MUTEX_unlock(&requested_lock);
106
-
107
- CRYPTO_once(&once, init_once);
108
- if (urandom_fd != fd) {
109
- abort(); // Already initialized.
110
- }
111
- }
112
-
113
- void RAND_enable_fork_unsafe_buffering(int fd) {
114
- if (fd >= 0) {
115
- fd = dup(fd);
116
- if (fd < 0) {
117
- abort();
118
- }
119
- } else {
120
- fd = -2;
121
- }
122
-
123
- CRYPTO_STATIC_MUTEX_lock_write(&requested_lock);
124
- urandom_buffering_requested = 1;
125
- urandom_fd_requested = fd;
126
- CRYPTO_STATIC_MUTEX_unlock(&requested_lock);
127
-
128
- CRYPTO_once(&once, init_once);
129
- if (urandom_buffering != 1 || (fd >= 0 && urandom_fd != fd)) {
130
- abort(); // Already initialized.
131
- }
132
- }
133
-
134
- static struct rand_buffer *get_thread_local_buffer(void) {
135
- struct rand_buffer *buf =
136
- CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_URANDOM_BUF);
137
- if (buf != NULL) {
138
- return buf;
139
- }
140
-
141
- buf = OPENSSL_malloc(sizeof(struct rand_buffer));
142
- if (buf == NULL) {
143
- return NULL;
144
- }
145
- buf->used = BUF_SIZE; /* To trigger a |read_full| on first use. */
146
- if (!CRYPTO_set_thread_local(OPENSSL_THREAD_LOCAL_URANDOM_BUF, buf,
147
- OPENSSL_free)) {
148
- OPENSSL_free(buf);
149
- return NULL;
150
- }
151
-
152
- return buf;
153
- }
154
-
155
- /* read_full reads exactly |len| bytes from |fd| into |out| and returns 1. In
156
- * the case of an error it returns 0. */
157
- static char read_full(int fd, uint8_t *out, size_t len) {
158
- ssize_t r;
159
-
160
- while (len > 0) {
161
- do {
162
- r = read(fd, out, len);
163
- } while (r == -1 && errno == EINTR);
164
-
165
- if (r <= 0) {
166
- return 0;
167
- }
168
- out += r;
169
- len -= r;
170
- }
171
-
172
- return 1;
173
- }
174
-
175
- /* read_from_buffer reads |requested| random bytes from the buffer into |out|,
176
- * refilling it if necessary to satisfy the request. */
177
- static void read_from_buffer(struct rand_buffer *buf,
178
- uint8_t *out, size_t requested) {
179
- size_t remaining = BUF_SIZE - buf->used;
180
-
181
- while (requested > remaining) {
182
- memcpy(out, &buf->rand[buf->used], remaining);
183
- buf->used += remaining;
184
- out += remaining;
185
- requested -= remaining;
186
-
187
- if (!read_full(urandom_fd, buf->rand, BUF_SIZE)) {
188
- abort();
189
- return;
190
- }
191
- buf->used = 0;
192
- remaining = BUF_SIZE;
193
- }
194
-
195
- memcpy(out, &buf->rand[buf->used], requested);
196
- buf->used += requested;
197
- }
198
-
199
- /* CRYPTO_sysrand puts |requested| random bytes into |out|. */
200
- void CRYPTO_sysrand(uint8_t *out, size_t requested) {
201
- if (requested == 0) {
202
- return;
203
- }
204
-
205
- CRYPTO_once(&once, init_once);
206
- if (urandom_buffering && requested < BUF_SIZE) {
207
- struct rand_buffer *buf = get_thread_local_buffer();
208
- if (buf != NULL) {
209
- read_from_buffer(buf, out, requested);
210
- return;
211
- }
212
- }
213
-
214
- if (!read_full(urandom_fd, out, requested)) {
215
- abort();
216
- }
217
- }
218
-
219
- #endif /* !OPENSSL_WINDOWS */