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,46 +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 "test_util.h"
16
-
17
- #include <stdint.h>
18
- #include <stdio.h>
19
-
20
- #include "openssl/rand.h"
21
-
22
-
23
- void hexdump(FILE *fp, const char *msg, const void *in, size_t len) {
24
- const uint8_t *data = reinterpret_cast<const uint8_t*>(in);
25
- size_t i;
26
-
27
- fputs(msg, fp);
28
- for (i = 0; i < len; i++) {
29
- fprintf(fp, "%02x", data[i]);
30
- }
31
- fputs("\n", fp);
32
- }
33
-
34
- // XXX: In *ring*, we implement |BN_generate_dsa_nonce_digest| in Rust so that
35
- // we can use |ring::digest|. But, the tests don't link against any Rust code.
36
- // Fortunately, we don't need secure nonces in the tests, so we can do the
37
- // thing you're not supposed to do in this implementation. This will likely
38
- // throw off the ECDSA_sign performance measurements in |bssl speed| though.
39
- extern "C" int BN_generate_dsa_nonce_digest(uint8_t *out, size_t out_len,
40
- const uint8_t *, size_t,
41
- const uint8_t *, size_t,
42
- const uint8_t *, size_t,
43
- const uint8_t *, size_t,
44
- const uint8_t *, size_t) {
45
- return RAND_bytes(out, out_len);
46
- }
@@ -1,41 +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_TEST_TEST_UTIL_H
16
- #define OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H
17
-
18
- #include <stddef.h>
19
- #include <stdio.h>
20
-
21
- #if defined(_MSC_VER) && _MSC_VER < 1900
22
- #define OPENSSL_PR_SIZE_T "Iu" /* MSVC doesn't support %zu until MSVC 2015. */
23
- #else
24
- #define OPENSSL_PR_SIZE_T "zu" /* "%zu" is the C99 standard format specifier. */
25
- #endif
26
-
27
- #if defined(__cplusplus)
28
- extern "C" {
29
- #endif
30
-
31
-
32
- /* hexdump writes |msg| to |fp| followed by the hex encoding of |len| bytes
33
- * from |in|. */
34
- void hexdump(FILE *fp, const char *msg, const void *in, size_t len);
35
-
36
-
37
- #if defined(__cplusplus)
38
- }
39
- #endif
40
-
41
- #endif /* OPENSSL_HEADER_CRYPTO_TEST_TEST_UTIL_H */
@@ -1,55 +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_NO_THREADS)
18
-
19
- void CRYPTO_MUTEX_init(CRYPTO_MUTEX *lock) {}
20
-
21
- void CRYPTO_MUTEX_lock_read(CRYPTO_MUTEX *lock) {}
22
-
23
- void CRYPTO_MUTEX_lock_write(CRYPTO_MUTEX *lock) {}
24
-
25
- void CRYPTO_MUTEX_unlock(CRYPTO_MUTEX *lock) {}
26
-
27
- void CRYPTO_MUTEX_cleanup(CRYPTO_MUTEX *lock) {}
28
-
29
- void CRYPTO_STATIC_MUTEX_lock_read(struct CRYPTO_STATIC_MUTEX *lock) {}
30
-
31
- void CRYPTO_STATIC_MUTEX_lock_write(struct CRYPTO_STATIC_MUTEX *lock) {}
32
-
33
- void CRYPTO_STATIC_MUTEX_unlock(struct CRYPTO_STATIC_MUTEX *lock) {}
34
-
35
- void CRYPTO_once(CRYPTO_once_t *once, void (*init)(void)) {
36
- if (*once) {
37
- return;
38
- }
39
- *once = 1;
40
- init();
41
- }
42
-
43
- static void *g_thread_locals[NUM_OPENSSL_THREAD_LOCALS];
44
-
45
- void *CRYPTO_get_thread_local(thread_local_data_t index) {
46
- return g_thread_locals[index];
47
- }
48
-
49
- int CRYPTO_set_thread_local(thread_local_data_t index, void *value,
50
- thread_local_destructor_t destructor) {
51
- g_thread_locals[index] = value;
52
- return 1;
53
- }
54
-
55
- #endif /* OPENSSL_NO_THREADS */
@@ -1,165 +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
- #include <pthread.h>
20
- #include <stdio.h>
21
- #include <stdlib.h>
22
- #include <string.h>
23
-
24
- #include <openssl/mem.h>
25
- #include <openssl/type_check.h>
26
-
27
-
28
- OPENSSL_COMPILE_ASSERT(sizeof(CRYPTO_MUTEX) >= sizeof(pthread_rwlock_t),
29
- CRYPTO_MUTEX_too_small);
30
-
31
- void CRYPTO_MUTEX_init(CRYPTO_MUTEX *lock) {
32
- if (pthread_rwlock_init((pthread_rwlock_t *) lock, NULL) != 0) {
33
- abort();
34
- }
35
- }
36
-
37
- void CRYPTO_MUTEX_lock_read(CRYPTO_MUTEX *lock) {
38
- if (pthread_rwlock_rdlock((pthread_rwlock_t *) lock) != 0) {
39
- abort();
40
- }
41
- }
42
-
43
- void CRYPTO_MUTEX_lock_write(CRYPTO_MUTEX *lock) {
44
- if (pthread_rwlock_wrlock((pthread_rwlock_t *) lock) != 0) {
45
- abort();
46
- }
47
- }
48
-
49
- void CRYPTO_MUTEX_unlock(CRYPTO_MUTEX *lock) {
50
- if (pthread_rwlock_unlock((pthread_rwlock_t *) lock) != 0) {
51
- abort();
52
- }
53
- }
54
-
55
- void CRYPTO_MUTEX_cleanup(CRYPTO_MUTEX *lock) {
56
- pthread_rwlock_destroy((pthread_rwlock_t *) lock);
57
- }
58
-
59
- void CRYPTO_STATIC_MUTEX_lock_read(struct CRYPTO_STATIC_MUTEX *lock) {
60
- if (pthread_rwlock_rdlock(&lock->lock) != 0) {
61
- abort();
62
- }
63
- }
64
-
65
- void CRYPTO_STATIC_MUTEX_lock_write(struct CRYPTO_STATIC_MUTEX *lock) {
66
- if (pthread_rwlock_wrlock(&lock->lock) != 0) {
67
- abort();
68
- }
69
- }
70
-
71
- void CRYPTO_STATIC_MUTEX_unlock(struct CRYPTO_STATIC_MUTEX *lock) {
72
- if (pthread_rwlock_unlock(&lock->lock) != 0) {
73
- abort();
74
- }
75
- }
76
-
77
- void CRYPTO_once(CRYPTO_once_t *once, void (*init)(void)) {
78
- if (pthread_once(once, init) != 0) {
79
- abort();
80
- }
81
- }
82
-
83
- static pthread_mutex_t g_destructors_lock = PTHREAD_MUTEX_INITIALIZER;
84
- static thread_local_destructor_t g_destructors[NUM_OPENSSL_THREAD_LOCALS];
85
-
86
- static void thread_local_destructor(void *arg) {
87
- if (arg == NULL) {
88
- return;
89
- }
90
-
91
- thread_local_destructor_t destructors[NUM_OPENSSL_THREAD_LOCALS];
92
- if (pthread_mutex_lock(&g_destructors_lock) != 0) {
93
- return;
94
- }
95
- memcpy(destructors, g_destructors, sizeof(destructors));
96
- pthread_mutex_unlock(&g_destructors_lock);
97
-
98
- unsigned i;
99
- void **pointers = arg;
100
- for (i = 0; i < NUM_OPENSSL_THREAD_LOCALS; i++) {
101
- if (destructors[i] != NULL) {
102
- destructors[i](pointers[i]);
103
- }
104
- }
105
-
106
- OPENSSL_free(pointers);
107
- }
108
-
109
- static pthread_once_t g_thread_local_init_once = PTHREAD_ONCE_INIT;
110
- static pthread_key_t g_thread_local_key;
111
- static int g_thread_local_failed = 0;
112
-
113
- static void thread_local_init(void) {
114
- g_thread_local_failed =
115
- pthread_key_create(&g_thread_local_key, thread_local_destructor) != 0;
116
- }
117
-
118
- void *CRYPTO_get_thread_local(thread_local_data_t index) {
119
- CRYPTO_once(&g_thread_local_init_once, thread_local_init);
120
- if (g_thread_local_failed) {
121
- return NULL;
122
- }
123
-
124
- void **pointers = pthread_getspecific(g_thread_local_key);
125
- if (pointers == NULL) {
126
- return NULL;
127
- }
128
- return pointers[index];
129
- }
130
-
131
- int CRYPTO_set_thread_local(thread_local_data_t index, void *value,
132
- thread_local_destructor_t destructor) {
133
- CRYPTO_once(&g_thread_local_init_once, thread_local_init);
134
- if (g_thread_local_failed) {
135
- destructor(value);
136
- return 0;
137
- }
138
-
139
- void **pointers = pthread_getspecific(g_thread_local_key);
140
- if (pointers == NULL) {
141
- pointers = OPENSSL_malloc(sizeof(void *) * NUM_OPENSSL_THREAD_LOCALS);
142
- if (pointers == NULL) {
143
- destructor(value);
144
- return 0;
145
- }
146
- memset(pointers, 0, sizeof(void *) * NUM_OPENSSL_THREAD_LOCALS);
147
- if (pthread_setspecific(g_thread_local_key, pointers) != 0) {
148
- OPENSSL_free(pointers);
149
- destructor(value);
150
- return 0;
151
- }
152
- }
153
-
154
- if (pthread_mutex_lock(&g_destructors_lock) != 0) {
155
- destructor(value);
156
- return 0;
157
- }
158
- g_destructors[index] = destructor;
159
- pthread_mutex_unlock(&g_destructors_lock);
160
-
161
- pointers[index] = value;
162
- return 1;
163
- }
164
-
165
- #endif /* !OPENSSL_WINDOWS && !OPENSSL_NO_THREADS */
@@ -1,25 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
- <PropertyGroup Label="Globals">
4
- <ProjectGuid>{52C6E909-4E56-4329-8B99-E1B5C2E1FB19}</ProjectGuid>
5
- <TargetName>thread_test</TargetName>
6
- </PropertyGroup>
7
- <ImportGroup Label="PropertySheets">
8
- <Import Project="..\mk\WindowsTest.props" />
9
- </ImportGroup>
10
- <PropertyGroup Label="Configuration">
11
- <OutDir>$(OutRootDir)\test\ring\crypto\</OutDir>
12
- </PropertyGroup>
13
- <ItemGroup>
14
- <ClCompile Include="thread_test.c" />
15
- </ItemGroup>
16
- <ItemGroup>
17
- <ProjectReference Include="libring.Windows.vcxproj">
18
- <Project>{f4c0a1b6-5e09-41c8-8242-3e1f6762fb18}</Project>
19
- </ProjectReference>
20
- <ProjectReference Include="test\test.Windows.vcxproj">
21
- <Project>{1dace503-6498-492d-b1ff-f9ee18624443}</Project>
22
- </ProjectReference>
23
- </ItemGroup>
24
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
25
- </Project>
@@ -1,200 +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
- #include <stdio.h>
18
-
19
-
20
- #if !defined(OPENSSL_NO_THREADS)
21
-
22
- #if defined(OPENSSL_WINDOWS)
23
-
24
- #pragma warning(push, 3)
25
- #include <windows.h>
26
- #pragma warning(pop)
27
-
28
- typedef HANDLE thread_t;
29
-
30
- static DWORD WINAPI thread_run(LPVOID arg) {
31
- void (*thread_func)(void);
32
- /* VC really doesn't like casting between data and function pointers. */
33
- memcpy(&thread_func, &arg, sizeof(thread_func));
34
- thread_func();
35
- return 0;
36
- }
37
-
38
- static int run_thread(thread_t *out_thread, void (*thread_func)(void)) {
39
- void *arg;
40
- /* VC really doesn't like casting between data and function pointers. */
41
- memcpy(&arg, &thread_func, sizeof(arg));
42
-
43
- *out_thread = CreateThread(NULL /* security attributes */,
44
- 0 /* default stack size */, thread_run, arg,
45
- 0 /* run immediately */, NULL /* ignore id */);
46
- return *out_thread != NULL;
47
- }
48
-
49
- static int wait_for_thread(thread_t thread) {
50
- return WaitForSingleObject(thread, INFINITE) == 0;
51
- }
52
-
53
- #else
54
-
55
- #include <pthread.h>
56
-
57
- typedef pthread_t thread_t;
58
-
59
- static void *thread_run(void *arg) {
60
- void (*thread_func)(void) = arg;
61
- thread_func();
62
- return NULL;
63
- }
64
-
65
- static int run_thread(thread_t *out_thread, void (*thread_func)(void)) {
66
- return pthread_create(out_thread, NULL /* default attributes */, thread_run,
67
- thread_func) == 0;
68
- }
69
-
70
- static int wait_for_thread(thread_t thread) {
71
- return pthread_join(thread, NULL) == 0;
72
- }
73
-
74
- #endif /* OPENSSL_WINDOWS */
75
-
76
- static unsigned g_once_init_called = 0;
77
-
78
- static void once_init(void) {
79
- g_once_init_called++;
80
- }
81
-
82
- static CRYPTO_once_t g_test_once = CRYPTO_ONCE_INIT;
83
-
84
- static void call_once_thread(void) {
85
- CRYPTO_once(&g_test_once, once_init);
86
- }
87
-
88
- static int test_once(void) {
89
- if (g_once_init_called != 0) {
90
- fprintf(stderr, "g_once_init_called was non-zero at start.\n");
91
- return 0;
92
- }
93
-
94
- thread_t thread;
95
- if (!run_thread(&thread, call_once_thread) ||
96
- !wait_for_thread(thread)) {
97
- fprintf(stderr, "thread failed.\n");
98
- return 0;
99
- }
100
-
101
- CRYPTO_once(&g_test_once, once_init);
102
-
103
- if (g_once_init_called != 1) {
104
- fprintf(stderr, "Expected init function to be called once, but found %u.\n",
105
- g_once_init_called);
106
- return 0;
107
- }
108
-
109
- return 1;
110
- }
111
-
112
-
113
- static int g_test_thread_ok = 0;
114
- static unsigned g_destructor_called_count = 0;
115
-
116
- static void thread_local_destructor(void *arg) {
117
- if (arg == NULL) {
118
- return;
119
- }
120
-
121
- unsigned *count = arg;
122
- (*count)++;
123
- }
124
-
125
- static void thread_local_test_thread(void) {
126
- void *ptr = CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_TEST);
127
- if (ptr != NULL) {
128
- return;
129
- }
130
-
131
- if (!CRYPTO_set_thread_local(OPENSSL_THREAD_LOCAL_TEST,
132
- &g_destructor_called_count,
133
- thread_local_destructor)) {
134
- return;
135
- }
136
-
137
- if (CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_TEST) !=
138
- &g_destructor_called_count) {
139
- return;
140
- }
141
-
142
- g_test_thread_ok = 1;
143
- }
144
-
145
- static void thread_local_test2_thread(void) {}
146
-
147
- static int test_thread_local(void) {
148
- void *ptr = CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_TEST);
149
- if (ptr != NULL) {
150
- fprintf(stderr, "Thread-local data was non-NULL at start.\n");
151
- }
152
-
153
- thread_t thread;
154
- if (!run_thread(&thread, thread_local_test_thread) ||
155
- !wait_for_thread(thread)) {
156
- fprintf(stderr, "thread failed.\n");
157
- return 0;
158
- }
159
-
160
- if (!g_test_thread_ok) {
161
- fprintf(stderr, "Thread-local data didn't work in thread.\n");
162
- return 0;
163
- }
164
-
165
- if (g_destructor_called_count != 1) {
166
- fprintf(stderr,
167
- "Destructor should have been called once, but actually called %u "
168
- "times.\n",
169
- g_destructor_called_count);
170
- return 0;
171
- }
172
-
173
- /* thread_local_test2_thread doesn't do anything, but it tests that the
174
- * thread destructor function works even if thread-local storage wasn't used
175
- * for a thread. */
176
- if (!run_thread(&thread, thread_local_test2_thread) ||
177
- !wait_for_thread(thread)) {
178
- fprintf(stderr, "thread failed.\n");
179
- return 0;
180
- }
181
-
182
- return 1;
183
- }
184
-
185
- int main(int argc, char **argv) {
186
- if (!test_once() ||
187
- !test_thread_local()) {
188
- return 1;
189
- }
190
-
191
- return 0;
192
- }
193
-
194
- #else /* OPENSSL_NO_THREADS */
195
-
196
- int main(int argc, char **argv) {
197
- return 0;
198
- }
199
-
200
- #endif