ring-native 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,282 +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
- #include "internal.h"
16
-
17
- #if defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_THREADS)
18
-
19
- #pragma warning(push, 3)
20
- #include <windows.h>
21
- #pragma warning(pop)
22
-
23
- #include <assert.h>
24
- #include <stdlib.h>
25
- #include <string.h>
26
-
27
- #include <openssl/mem.h>
28
- #include <openssl/type_check.h>
29
-
30
-
31
- OPENSSL_COMPILE_ASSERT(sizeof(CRYPTO_MUTEX) >= sizeof(CRITICAL_SECTION),
32
- CRYPTO_MUTEX_too_small);
33
-
34
- static void run_once(CRYPTO_once_t *in_once, void (*init)(void *), void *arg) {
35
- volatile LONG *once = in_once;
36
-
37
- /* Values must be aligned. */
38
- assert((((uintptr_t) once) & 3) == 0);
39
-
40
- /* This assumes that reading *once has acquire semantics. This should be true
41
- * on x86 and x86-64, where we expect Windows to run. */
42
- #if !defined(OPENSSL_X86) && !defined(OPENSSL_X86_64)
43
- #error "Windows once code may not work on other platforms." \
44
- "You can use InitOnceBeginInitialize on >=Vista"
45
- #endif
46
- if (*once == 1) {
47
- return;
48
- }
49
-
50
- for (;;) {
51
- switch (InterlockedCompareExchange(once, 2, 0)) {
52
- case 0:
53
- /* The value was zero so we are the first thread to call |CRYPTO_once|
54
- * on it. */
55
- init(arg);
56
- /* Write one to indicate that initialisation is complete. */
57
- InterlockedExchange(once, 1);
58
- return;
59
-
60
- case 1:
61
- /* Another thread completed initialisation between our fast-path check
62
- * and |InterlockedCompareExchange|. */
63
- return;
64
-
65
- case 2:
66
- /* Another thread is running the initialisation. Switch to it then try
67
- * again. */
68
- SwitchToThread();
69
- break;
70
-
71
- default:
72
- abort();
73
- }
74
- }
75
- }
76
-
77
- static void call_once_init(void *arg) {
78
- void (*init_func)(void);
79
- /* MSVC does not like casting between data and function pointers. */
80
- memcpy(&init_func, &arg, sizeof(void *));
81
- init_func();
82
- }
83
-
84
- void CRYPTO_once(CRYPTO_once_t *in_once, void (*init)(void)) {
85
- void *arg;
86
- /* MSVC does not like casting between data and function pointers. */
87
- memcpy(&arg, &init, sizeof(void *));
88
- run_once(in_once, call_once_init, arg);
89
- }
90
-
91
- void CRYPTO_MUTEX_init(CRYPTO_MUTEX *lock) {
92
- if (!InitializeCriticalSectionAndSpinCount((CRITICAL_SECTION *) lock, 0x400)) {
93
- abort();
94
- }
95
- }
96
-
97
- void CRYPTO_MUTEX_lock_read(CRYPTO_MUTEX *lock) {
98
- /* Since we have to support Windows XP, read locks are actually exclusive. */
99
- EnterCriticalSection((CRITICAL_SECTION *) lock);
100
- }
101
-
102
- void CRYPTO_MUTEX_lock_write(CRYPTO_MUTEX *lock) {
103
- EnterCriticalSection((CRITICAL_SECTION *) lock);
104
- }
105
-
106
- void CRYPTO_MUTEX_unlock(CRYPTO_MUTEX *lock) {
107
- LeaveCriticalSection((CRITICAL_SECTION *) lock);
108
- }
109
-
110
- void CRYPTO_MUTEX_cleanup(CRYPTO_MUTEX *lock) {
111
- DeleteCriticalSection((CRITICAL_SECTION *) lock);
112
- }
113
-
114
- static void static_lock_init(void *arg) {
115
- struct CRYPTO_STATIC_MUTEX *lock = arg;
116
- if (!InitializeCriticalSectionAndSpinCount(&lock->lock, 0x400)) {
117
- abort();
118
- }
119
- }
120
-
121
- void CRYPTO_STATIC_MUTEX_lock_read(struct CRYPTO_STATIC_MUTEX *lock) {
122
- /* Since we have to support Windows XP, read locks are actually exclusive. */
123
- run_once(&lock->once, static_lock_init, lock);
124
- EnterCriticalSection(&lock->lock);
125
- }
126
-
127
- void CRYPTO_STATIC_MUTEX_lock_write(struct CRYPTO_STATIC_MUTEX *lock) {
128
- CRYPTO_STATIC_MUTEX_lock_read(lock);
129
- }
130
-
131
- void CRYPTO_STATIC_MUTEX_unlock(struct CRYPTO_STATIC_MUTEX *lock) {
132
- LeaveCriticalSection(&lock->lock);
133
- }
134
-
135
- static CRITICAL_SECTION g_destructors_lock;
136
- static thread_local_destructor_t g_destructors[NUM_OPENSSL_THREAD_LOCALS];
137
-
138
- static CRYPTO_once_t g_thread_local_init_once = CRYPTO_ONCE_INIT;
139
- static DWORD g_thread_local_key;
140
- static int g_thread_local_failed;
141
-
142
- static void thread_local_init(void) {
143
- if (!InitializeCriticalSectionAndSpinCount(&g_destructors_lock, 0x400)) {
144
- g_thread_local_failed = 1;
145
- return;
146
- }
147
- g_thread_local_key = TlsAlloc();
148
- g_thread_local_failed = (g_thread_local_key == TLS_OUT_OF_INDEXES);
149
- }
150
-
151
- static void NTAPI thread_local_destructor(PVOID module,
152
- DWORD reason, PVOID reserved) {
153
- if (DLL_THREAD_DETACH != reason && DLL_PROCESS_DETACH != reason) {
154
- return;
155
- }
156
-
157
- CRYPTO_once(&g_thread_local_init_once, thread_local_init);
158
- if (g_thread_local_failed) {
159
- return;
160
- }
161
-
162
- void **pointers = (void**) TlsGetValue(g_thread_local_key);
163
- if (pointers == NULL) {
164
- return;
165
- }
166
-
167
- thread_local_destructor_t destructors[NUM_OPENSSL_THREAD_LOCALS];
168
-
169
- EnterCriticalSection(&g_destructors_lock);
170
- memcpy(destructors, g_destructors, sizeof(destructors));
171
- LeaveCriticalSection(&g_destructors_lock);
172
-
173
- unsigned i;
174
- for (i = 0; i < NUM_OPENSSL_THREAD_LOCALS; i++) {
175
- if (destructors[i] != NULL) {
176
- destructors[i](pointers[i]);
177
- }
178
- }
179
-
180
- OPENSSL_free(pointers);
181
- }
182
-
183
- /* Thread Termination Callbacks.
184
- *
185
- * Windows doesn't support a per-thread destructor with its TLS primitives.
186
- * So, we build it manually by inserting a function to be called on each
187
- * thread's exit. This magic is from http://www.codeproject.com/threads/tls.asp
188
- * and it works for VC++ 7.0 and later.
189
- *
190
- * Force a reference to _tls_used to make the linker create the TLS directory
191
- * if it's not already there. (E.g. if __declspec(thread) is not used). Force
192
- * a reference to p_thread_callback_boringssl to prevent whole program
193
- * optimization from discarding the variable. */
194
- #ifdef _WIN64
195
- #pragma comment(linker, "/INCLUDE:_tls_used")
196
- #pragma comment(linker, "/INCLUDE:p_thread_callback_boringssl")
197
- #else
198
- #pragma comment(linker, "/INCLUDE:__tls_used")
199
- #pragma comment(linker, "/INCLUDE:_p_thread_callback_boringssl")
200
- #endif
201
-
202
- /* .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are
203
- * called automatically by the OS loader code (not the CRT) when the module is
204
- * loaded and on thread creation. They are NOT called if the module has been
205
- * loaded by a LoadLibrary() call. It must have implicitly been loaded at
206
- * process startup.
207
- *
208
- * By implicitly loaded, I mean that it is directly referenced by the main EXE
209
- * or by one of its dependent DLLs. Delay-loaded DLL doesn't count as being
210
- * implicitly loaded.
211
- *
212
- * See VC\crt\src\tlssup.c for reference. */
213
-
214
- /* The linker must not discard p_thread_callback_boringssl. (We force a reference
215
- * to this variable with a linker /INCLUDE:symbol pragma to ensure that.) If
216
- * this variable is discarded, the OnThreadExit function will never be
217
- * called. */
218
- #ifdef _WIN64
219
-
220
- /* .CRT section is merged with .rdata on x64 so it must be constant data. */
221
- #pragma const_seg(".CRT$XLC")
222
- /* When defining a const variable, it must have external linkage to be sure the
223
- * linker doesn't discard it. */
224
- extern const PIMAGE_TLS_CALLBACK p_thread_callback_boringssl;
225
- const PIMAGE_TLS_CALLBACK p_thread_callback_boringssl = thread_local_destructor;
226
- /* Reset the default section. */
227
- #pragma const_seg()
228
-
229
- #else
230
-
231
- #pragma data_seg(".CRT$XLC")
232
- PIMAGE_TLS_CALLBACK p_thread_callback_boringssl = thread_local_destructor;
233
- /* Reset the default section. */
234
- #pragma data_seg()
235
-
236
- #endif /* _WIN64 */
237
-
238
- void *CRYPTO_get_thread_local(thread_local_data_t index) {
239
- CRYPTO_once(&g_thread_local_init_once, thread_local_init);
240
- if (g_thread_local_failed) {
241
- return NULL;
242
- }
243
-
244
- void **pointers = TlsGetValue(g_thread_local_key);
245
- if (pointers == NULL) {
246
- return NULL;
247
- }
248
- return pointers[index];
249
- }
250
-
251
- int CRYPTO_set_thread_local(thread_local_data_t index, void *value,
252
- thread_local_destructor_t destructor) {
253
- CRYPTO_once(&g_thread_local_init_once, thread_local_init);
254
- if (g_thread_local_failed) {
255
- destructor(value);
256
- return 0;
257
- }
258
-
259
- void **pointers = TlsGetValue(g_thread_local_key);
260
- if (pointers == NULL) {
261
- pointers = OPENSSL_malloc(sizeof(void *) * NUM_OPENSSL_THREAD_LOCALS);
262
- if (pointers == NULL) {
263
- destructor(value);
264
- return 0;
265
- }
266
- memset(pointers, 0, sizeof(void *) * NUM_OPENSSL_THREAD_LOCALS);
267
- if (TlsSetValue(g_thread_local_key, pointers) == 0) {
268
- OPENSSL_free(pointers);
269
- destructor(value);
270
- return 0;
271
- }
272
- }
273
-
274
- EnterCriticalSection(&g_destructors_lock);
275
- g_destructors[index] = destructor;
276
- LeaveCriticalSection(&g_destructors_lock);
277
-
278
- pointers[index] = value;
279
- return 1;
280
- }
281
-
282
- #endif /* OPENSSL_WINDOWS && !OPENSSL_NO_THREADS */
@@ -1,103 +0,0 @@
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 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
- extern crate ring;
16
- extern crate rustc_serialize;
17
-
18
- use ring::*;
19
- use rustc_serialize::hex::FromHex;
20
- use std::error::Error;
21
- use std::io::{Read, Write};
22
-
23
-
24
- fn print_usage(program_name: &str) {
25
- let program_file_name = std::path::Path::new(program_name)
26
- .file_name().unwrap().to_str().unwrap();
27
-
28
- println!(
29
- "Usage: {} sha256|sha384|sha512 <digest value in hex> <filename>\n\
30
- \n\
31
- On success nothing is output, and 0 is returned.\n\
32
- On failure, an error message is printed, and a non-zero value is returned\n\
33
- \n\
34
- Example:\n\
35
- {} sha256 \
36
- def7352915ac84bea5e2ed16f6fff712d35de519799777bf927e2a567ab53b7e \
37
- LICENSE",
38
- program_file_name, program_file_name);
39
- }
40
-
41
- fn run(digest_name: &str, expected_digest_hex: &str,
42
- file_path: &std::path::Path) -> Result<(), &'static str> {
43
- let digest_alg = match digest_name {
44
- "sha256" => &digest::SHA256,
45
- "sha384" => &digest::SHA384,
46
- "sha512" => &digest::SHA512,
47
- _ => { return Err("unsupported digest algorithm"); }
48
- };
49
-
50
- let mut ctx = digest::Context::new(digest_alg);
51
-
52
- {
53
- let mut file = match std::fs::File::open(file_path) {
54
- Ok(file) => file,
55
- // TODO: don't use panic here.
56
- Err(why) => panic!("couldn't open {}: {}", file_path.display(),
57
- why.description())
58
- };
59
-
60
- let mut chunk = vec![0u8; 128 * 1024];
61
- loop {
62
- match file.read(&mut chunk[..]) {
63
- Ok(0) => break,
64
- Ok(bytes_read) => ctx.update(&chunk[0..bytes_read]),
65
- // TODO: don't use panic here
66
- Err(why) => panic!("couldn't open {}: {}", file_path.display(),
67
- why.description())
68
- }
69
- }
70
- }
71
-
72
- let actual_digest = ctx.finish();
73
-
74
- let matched = match expected_digest_hex.from_hex() {
75
- Ok(expected) => actual_digest.as_ref() == &expected[..],
76
- Err(_) => panic!("syntactically invalid digest")
77
- };
78
-
79
- match matched {
80
- true => Ok(()),
81
- false => Err("digest mismatch") // TODO: calculated digest.
82
- }
83
- }
84
-
85
- fn main() {
86
- let args: Vec<String> = std::env::args().collect();
87
-
88
- if args.iter().any(|arg| arg == "-h") {
89
- print_usage(&args[0]);
90
- return
91
- } else if args.len() < 4 {
92
- print_usage(&args[0]);
93
- std::process::exit(1);
94
- }
95
-
96
- match run(&args[1], &args[2], std::path::Path::new(&args[3])) {
97
- Ok(x) => x,
98
- Err(s) => {
99
- let _ = writeln!(&mut std::io::stderr(), "{}", s);
100
- std::process::exit(1)
101
- }
102
- }
103
- }
@@ -1,121 +0,0 @@
1
- /* ====================================================================
2
- * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved.
3
- *
4
- * Redistribution and use in source and binary forms, with or without
5
- * modification, are permitted provided that the following conditions
6
- * are met:
7
- *
8
- * 1. Redistributions of source code must retain the above copyright
9
- * notice, this list of conditions and the following disclaimer.
10
- *
11
- * 2. Redistributions in binary form must reproduce the above copyright
12
- * notice, this list of conditions and the following disclaimer in
13
- * the documentation and/or other materials provided with the
14
- * distribution.
15
- *
16
- * 3. All advertising materials mentioning features or use of this
17
- * software must display the following acknowledgment:
18
- * "This product includes software developed by the OpenSSL Project
19
- * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20
- *
21
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22
- * endorse or promote products derived from this software without
23
- * prior written permission. For written permission, please contact
24
- * openssl-core@openssl.org.
25
- *
26
- * 5. Products derived from this software may not be called "OpenSSL"
27
- * nor may "OpenSSL" appear in their names without prior written
28
- * permission of the OpenSSL Project.
29
- *
30
- * 6. Redistributions of any form whatsoever must retain the following
31
- * acknowledgment:
32
- * "This product includes software developed by the OpenSSL Project
33
- * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34
- *
35
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46
- * OF THE POSSIBILITY OF SUCH DAMAGE.
47
- * ==================================================================== */
48
-
49
- #ifndef OPENSSL_HEADER_AES_H
50
- #define OPENSSL_HEADER_AES_H
51
-
52
- #include <openssl/base.h>
53
-
54
- #if defined(__cplusplus)
55
- extern "C" {
56
- #endif
57
-
58
-
59
- /* Raw AES functions. */
60
-
61
-
62
- #define AES_ENCRYPT 1
63
- #define AES_DECRYPT 0
64
-
65
- /* AES_MAXNR is the maximum number of AES rounds. */
66
- #define AES_MAXNR 14
67
-
68
- #define AES_BLOCK_SIZE 16
69
-
70
- /* aes_key_st should be an opaque type, but EVP requires that the size be
71
- * known. */
72
- struct aes_key_st {
73
- uint32_t rd_key[4 * (AES_MAXNR + 1)];
74
- unsigned rounds;
75
- };
76
- typedef struct aes_key_st AES_KEY;
77
-
78
- /* AES_set_encrypt_key configures |aeskey| to encrypt with the |bits|-bit key,
79
- * |key|.
80
- *
81
- * WARNING: unlike other OpenSSL functions, this returns zero on success and a
82
- * negative number on error. */
83
- OPENSSL_EXPORT int AES_set_encrypt_key(const uint8_t *key, unsigned bits,
84
- AES_KEY *aeskey);
85
-
86
- /* AES_set_decrypt_key configures |aeskey| to decrypt with the |bits|-bit key,
87
- * |key|.
88
- *
89
- * WARNING: unlike other OpenSSL functions, this returns zero on success and a
90
- * negative number on error. */
91
- OPENSSL_EXPORT int AES_set_decrypt_key(const uint8_t *key, unsigned bits,
92
- AES_KEY *aeskey);
93
-
94
- /* AES_encrypt encrypts a single block from |in| to |out| with |key|. The |in|
95
- * and |out| pointers may overlap. */
96
- OPENSSL_EXPORT void AES_encrypt(const uint8_t *in, uint8_t *out,
97
- const AES_KEY *key);
98
-
99
- /* AES_decrypt decrypts a single block from |in| to |out| with |key|. The |in|
100
- * and |out| pointers may overlap. */
101
- OPENSSL_EXPORT void AES_decrypt(const uint8_t *in, uint8_t *out,
102
- const AES_KEY *key);
103
-
104
-
105
- /* Block cipher modes. */
106
-
107
- /* AES_ctr128_encrypt encrypts (or decrypts, it's the same in CTR mode) |len|
108
- * bytes from |in| to |out|. The |num| parameter must be set to zero on the
109
- * first call and |ivec| will be incremented. */
110
- OPENSSL_EXPORT void AES_ctr128_encrypt(const uint8_t *in, uint8_t *out,
111
- size_t len, const AES_KEY *key,
112
- uint8_t ivec[AES_BLOCK_SIZE],
113
- uint8_t ecount_buf[AES_BLOCK_SIZE],
114
- unsigned int *num);
115
-
116
-
117
- #if defined(__cplusplus)
118
- } /* extern C */
119
- #endif
120
-
121
- #endif /* OPENSSL_HEADER_AES_H */