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,46 +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 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
10
- // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- // These tests are ones that were written for OpenSSL or BoringSSL, each of
16
- // which is compiled into its own executable. The tests have been modified to
17
- // not print anything when they succeed.
18
-
19
- use std;
20
-
21
- macro_rules! exe_test {
22
- ( $name:ident, $relative_path_to_exe:expr, $args:expr ) => {
23
- #[test]
24
- fn $name() {
25
- let args: &[&'static str] = &$args;
26
- const RELATIVE_PATH_TO_EXE: &'static str =
27
- concat!(env!("OUT_DIR"), "/test/ring/", $relative_path_to_exe);
28
- assert!(std::process::Command::new(RELATIVE_PATH_TO_EXE)
29
- .args(args)
30
- .status()
31
- .unwrap()
32
- .success());
33
- }
34
- }
35
- }
36
-
37
- exe_test!(aes_test, "crypto/aes/aes_test", []);
38
- exe_test!(bn_test, "crypto/bn/bn_test", []);
39
- exe_test!(bytestring_test, "crypto/bytestring/bytestring_test", []);
40
- exe_test!(constant_time_test, "crypto/constant_time_test", []);
41
- exe_test!(ecdsa_test, "crypto/ecdsa/ecdsa_test", []);
42
- exe_test!(gcm_test, "crypto/modes/gcm_test", []);
43
- exe_test!(poly1305_test, "crypto/poly1305/poly1305_test", ["crypto/poly1305/poly1305_test.txt"]);
44
- exe_test!(refcount_test, "crypto/refcount_test", []);
45
- exe_test!(rsa_test, "crypto/rsa/rsa_test", []);
46
- exe_test!(thread_test, "crypto/thread_test", []);
@@ -1,29 +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 THE AUTHORS DISCLAIM ALL WARRANTIES
8
- // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10
- // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
- // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
- // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- use super::c;
16
-
17
- pub fn map_bssl_result(bssl_result: c::int) -> Result<(), ()> {
18
- match bssl_result {
19
- 1 => Ok(()),
20
- _ => Err(())
21
- }
22
- }
23
-
24
- pub fn map_bssl_ptr_result<T>(bssl_result: *mut T) -> Result<*mut T, ()> {
25
- if bssl_result.is_null() {
26
- return Err(());
27
- }
28
- Ok(bssl_result)
29
- }
@@ -1,187 +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 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
10
- // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- use rustc_serialize::hex::FromHex;
16
- use std;
17
- use std::io::BufRead;
18
- use super::digest;
19
-
20
- pub struct TestCase {
21
- attributes: std::collections::HashMap<String, String>,
22
- }
23
-
24
- impl TestCase {
25
- pub fn consume_digest_alg(&mut self, key: &str)
26
- -> Option<&'static digest::Algorithm> {
27
- let name = self.consume_string(key);
28
- match name.as_ref() {
29
- "SHA1" => Some(&digest::SHA1),
30
- "SHA224" => None, // We actively skip SHA-224 support.
31
- "SHA256" => Some(&digest::SHA256),
32
- "SHA384" => Some(&digest::SHA384),
33
- "SHA512" => Some(&digest::SHA512),
34
- _ => panic!("Unsupported digest algorithm: {}", name)
35
- }
36
- }
37
-
38
- pub fn consume_bytes(&mut self, key: &str) -> Vec<u8> {
39
- let mut s = self.consume_string(key);
40
- if s.starts_with("\"") {
41
- // The value is a quoted strong.
42
- // XXX: We don't deal with any inner quotes.
43
- if !s.ends_with("\"") {
44
- panic!("expected quoted string, found {}", s);
45
- }
46
- s.pop();
47
- s.remove(0);
48
- Vec::from(s.as_bytes())
49
- } else {
50
- // The value is hex encoded.
51
- match s.from_hex() {
52
- Ok(value) => value,
53
- Err(..) => panic!("Invalid hex encoding of attribute: {}", s)
54
- }
55
- }
56
- }
57
-
58
- pub fn consume_usize(&mut self, key: &str) -> usize {
59
- let s = self.consume_string(key);
60
- s.parse::<usize>().unwrap()
61
- }
62
-
63
- pub fn consume_string(&mut self, key: &str) -> String {
64
- self.consume_optional_string(key)
65
- .unwrap_or_else(|| panic!("No attribute named \"{}\"", key))
66
- }
67
-
68
- pub fn consume_optional_string(&mut self, key: &str) -> Option<String> {
69
- self.attributes.remove(key)
70
- }
71
- }
72
-
73
- pub fn run<F>(test_data_relative_file_path: &str, f: F)
74
- where F: Fn(&str, &mut TestCase) {
75
- let path = std::path::PathBuf::from(test_data_relative_file_path);
76
- let file = std::fs::File::open(path).unwrap();
77
- let mut lines = std::io::BufReader::new(&file).lines();
78
-
79
- let mut current_section = String::from("");
80
-
81
- loop {
82
- match parse_test_case(&mut current_section, &mut lines) {
83
- Some(ref mut test_case) => {
84
- f(&current_section, test_case);
85
-
86
- // Make sure all the attributes in the test case were consumed.
87
- assert!(test_case.attributes.is_empty());
88
- },
89
-
90
- None => {
91
- break;
92
- }
93
- }
94
- }
95
- }
96
-
97
- pub fn run_mut<F>(test_data_relative_file_path: &str, f: &mut F)
98
- where F: FnMut(&str, &mut TestCase) {
99
- let path = std::path::PathBuf::from(test_data_relative_file_path);
100
- let file = std::fs::File::open(path).unwrap();
101
- let mut lines = std::io::BufReader::new(&file).lines();
102
-
103
- let mut current_section = String::from("");
104
-
105
- loop {
106
- match parse_test_case(&mut current_section, &mut lines) {
107
- Some(ref mut test_case) => {
108
- f(&current_section, test_case);
109
-
110
- // Make sure all the attributes in the test case were consumed.
111
- assert!(test_case.attributes.is_empty());
112
- },
113
-
114
- None => {
115
- break;
116
- }
117
- }
118
- }
119
- }
120
-
121
- type FileLines<'a> = std::io::Lines<std::io::BufReader<&'a std::fs::File>>;
122
-
123
- fn parse_test_case(current_section: &mut String,
124
- lines: &mut FileLines) -> Option<TestCase> {
125
- let mut attributes = std::collections::HashMap::new();
126
-
127
- let mut is_first_line = true;
128
- loop {
129
- let line = match lines.next() {
130
- None => None,
131
- Some(result) => Some(result.unwrap()),
132
- };
133
-
134
- if let Some(ref text) = line {
135
- println!("Line: {}", text);
136
- }
137
-
138
- match line {
139
- // If we get to EOF when we're not in the middle of a test case,
140
- // then we're done.
141
- None if is_first_line => {
142
- return None;
143
- },
144
-
145
- // End of the file on a non-empty test cases ends the test case.
146
- None => {
147
- return Some(TestCase { attributes: attributes });
148
- },
149
-
150
- // A blank line ends a test case if the test case isn't empty.
151
- Some(ref line) if line.len() == 0 => {
152
- if !is_first_line {
153
- return Some(TestCase { attributes: attributes });
154
- }
155
- // Ignore leading blank lines.
156
- },
157
-
158
- // Comments start with '#'; ignore them.
159
- Some(ref line) if line.starts_with("#") => { },
160
-
161
- Some(ref line) if line.starts_with("[") => {
162
- assert!(is_first_line);
163
- assert!(line.ends_with("]"));
164
- current_section.truncate(0);
165
- current_section.push_str(line);
166
- current_section.pop();
167
- current_section.remove(0);
168
- },
169
-
170
- Some(ref line) => {
171
- is_first_line = false;
172
-
173
- let parts: Vec<&str> = line.splitn(2, " = ").collect();
174
- let key = parts[0].trim();
175
- let value = parts[1].trim();
176
-
177
- // Don't allow the value to be ommitted. An empty value can be
178
- // represented as an empty quoted string.
179
- assert!(value.len() != 0);
180
-
181
- // Checking is_none() ensures we don't accept duplicate keys.
182
- assert!(attributes.insert(String::from(key),
183
- String::from(value)).is_none());
184
- }
185
- }
186
- }
187
- }
@@ -1,153 +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 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
10
- // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- //! HMAC-based Extract-and-Expand Key Derivation Function.
16
- //!
17
- //! HKDF is specified in [RFC 5869](https://tools.ietf.org/html/rfc5869).
18
- //!
19
- //! In most situations, it is best to use `extract_and_expand` to do both the
20
- //! HKDF-Extract and HKDF-Expand as one atomic operation. It is only necessary
21
- //! to use the separate `expand` and `extract` functions if a single derived
22
- //! `PRK` (defined in RFC 5869) is used more than once.
23
- //!
24
- //! Salts have type `hmac::SigningKey` instead of `&[u8]` because they are
25
- //! frequently used for multiple HKDF operations, and it is more efficient to
26
- //! construct the `SigningKey` once and reuse it. Given a digest algorithm
27
- //! `digest_alg` and a salt `salt: &[u8]`, the `SigningKey` should be
28
- //! constructed as `hmac::SigningKey::new(digest_alg, salt)`.
29
-
30
-
31
- use super::hmac;
32
-
33
- /// Fills `out` with the output of the HKDF Extract-and-Expand operation for
34
- /// the given inputs.
35
- ///
36
- /// `extract_and_expand` is exactly equivalent to:
37
- ///
38
- /// ```ignore
39
- /// let prk = extract(salt, secret);
40
- /// expand(&prk, info, out)
41
- /// ```
42
- ///
43
- /// See the documentation for `extract` and `expand` for details.
44
- ///
45
- /// # Panics
46
- ///
47
- /// `extract_and_expand` panics if `expand` panics.
48
- pub fn extract_and_expand(salt: &hmac::SigningKey, secret: &[u8], info: &[u8],
49
- out: &mut [u8]) {
50
- let prk = extract(salt, secret);
51
- expand(&prk, info, out)
52
- }
53
-
54
- /// The HKDF-Extract operation.
55
- ///
56
- /// | Parameter | RFC 5869 Term
57
- /// |-------------------------|--------------
58
- /// | salt.digest_algorithm() | Hash
59
- /// | secret | IKM (Input Keying Material)
60
- /// | [return value] | PRK
61
- pub fn extract(salt: &hmac::SigningKey, secret: &[u8]) -> hmac::SigningKey {
62
- // The spec says that if no salt is provided then a key of
63
- // `digest_alg.output_len` bytes of zeros is used. But, HMAC keys are
64
- // already zero-padded to the block length, which is larger than the output
65
- // length of the extract step (the length of the digest). Consequently, the
66
- // `SigningKey` constructor will automatically do the right thing for a
67
- // zero-length string.
68
- let prk = hmac::sign(&salt, secret);
69
- hmac::SigningKey::new(salt.digest_algorithm(), prk.as_ref())
70
- }
71
-
72
- /// Fills `out` with the output of the HKDF-Expand operation for the given
73
- /// inputs.
74
- ///
75
- /// `prk` should be the return value of an earlier call to `extract`.
76
- ///
77
- /// | Parameter | RFC 5869 Term
78
- /// |------------|--------------
79
- /// | prk | PRK
80
- /// | info | info
81
- /// | out | OKM (Output Keying Material)
82
- /// | out.len() | L (Length of output keying material in bytes)
83
- ///
84
- /// # Panics
85
- ///
86
- /// `expand` panics if the requested output length is larger than 255 times the
87
- /// size of the digest algorithm, i.e. if
88
- /// `out.len() > 255 * salt.digest_algorithm().output_len`. This is the limit
89
- /// imposed by the HKDF specification, and is necessary to prevent overflow of
90
- /// the 8-bit iteration counter in the expansion step.
91
- pub fn expand(prk: &hmac::SigningKey, info: &[u8], out: &mut [u8]) {
92
- let digest_alg = prk.digest_algorithm();
93
- assert!(out.len() <= 255 * digest_alg.output_len);
94
- assert!(digest_alg.block_len >= digest_alg.output_len);
95
-
96
- let mut ctx = hmac::SigningContext::with_key(&prk);
97
-
98
- let mut n = 1u8;
99
- let mut pos = 0;
100
- loop {
101
- ctx.update(info);
102
- ctx.update(&[n]);
103
-
104
- let t = ctx.sign();
105
-
106
- // Append `t` to the output.
107
- let to_copy = if out.len() - pos < digest_alg.output_len {
108
- out.len() - pos
109
- } else {
110
- digest_alg.output_len
111
- };
112
- let t_bytes = t.as_ref();
113
- for i in 0..to_copy {
114
- out[pos + i] = t_bytes[i];
115
- }
116
- if to_copy < digest_alg.output_len {
117
- break;
118
- }
119
- pos += digest_alg.output_len;
120
-
121
- ctx = hmac::SigningContext::with_key(&prk);
122
- ctx.update(t_bytes);
123
- n += 1;
124
- }
125
- }
126
-
127
- #[cfg(test)]
128
- mod tests {
129
- use super::super::{file_test, hkdf, hmac};
130
-
131
- #[test]
132
- pub fn hkdf_tests() {
133
- file_test::run("src/hkdf_tests.txt", |section, test_case| {
134
- assert_eq!(section, "");
135
- let digest_alg = test_case.consume_digest_alg("Hash").unwrap();
136
- let secret = test_case.consume_bytes("IKM");
137
- let salt = test_case.consume_bytes("salt");
138
- let info = test_case.consume_bytes("info");
139
-
140
- // The PRK is an intermediate value that we can't test, but we
141
- // have to consume it to make file_test::run happy.
142
- let _ = test_case.consume_bytes("PRK");
143
-
144
- let out = test_case.consume_bytes("OKM");
145
-
146
- let salt = hmac::SigningKey::new(digest_alg, &salt);
147
-
148
- let mut out = vec![0u8; out.len()];
149
- hkdf::extract_and_expand(&salt, &secret, &info, &mut out);
150
- assert_eq!(out, out);
151
- });
152
- }
153
- }
@@ -1,59 +0,0 @@
1
- # Test Cases from RFC 5869. Note that the parameter L is implied by the length
2
- # of |OKM| and so it was omitted.
3
-
4
- # A.1. Test Case 1 = Basic test case with SHA-256
5
- Hash = SHA256
6
- IKM = 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
7
- salt = 000102030405060708090a0b0c
8
- info = f0f1f2f3f4f5f6f7f8f9
9
- PRK = 077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5
10
- OKM = 3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865
11
-
12
- # A.2. Test Case 2 = Test with SHA-256 and longer inputs/outputs
13
- Hash = SHA256
14
- IKM = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f
15
- salt = 606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf
16
- info = b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
17
- PRK = 06a6b88c5853361a06104c9ceb35b45cef760014904671014a193f40c15fc244
18
- OKM = b11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97c59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71cc30c58179ec3e87c14c01d5c1f3434f1d87
19
-
20
- # A.3. Test Case 3 = Test with SHA-256 and zero-length salt/info
21
- Hash = SHA256
22
- IKM = 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
23
- salt = ""
24
- info = ""
25
- PRK = 19ef24a32c717b167f33a91d6f648bdf96596776afdb6377ac434c1c293ccb04
26
- OKM = 8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8
27
-
28
- # A.4. Test Case 4 = Basic test case with SHA-1
29
- Hash = SHA1
30
- IKM = 0b0b0b0b0b0b0b0b0b0b0b
31
- salt = 000102030405060708090a0b0c
32
- info = f0f1f2f3f4f5f6f7f8f9
33
- PRK = 9b6c18c432a7bf8f0e71c8eb88f4b30baa2ba243
34
- OKM = 085a01ea1b10f36933068b56efa5ad81a4f14b822f5b091568a9cdd4f155fda2c22e422478d305f3f896
35
-
36
- # A.5. Test Case 5 = Test with SHA-1 and longer inputs/outputs
37
- Hash = SHA1
38
- IKM = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f
39
- salt = 606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf
40
- info = b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff
41
- PRK = 8adae09a2a307059478d309b26c4115a224cfaf6
42
- OKM = 0bd770a74d1160f7c9f12cd5912a06ebff6adcae899d92191fe4305673ba2ffe8fa3f1a4e5ad79f3f334b3b202b2173c486ea37ce3d397ed034c7f9dfeb15c5e927336d0441f4c4300e2cff0d0900b52d3b4
43
-
44
- # A.6. Test Case 6 = Test with SHA-1 and zero-length salt/info
45
- Hash = SHA1
46
- IKM = 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
47
- salt = ""
48
- info = ""
49
- PRK = da8c8a73c7fa77288ec6f5e7c297786aa0d32d01
50
- OKM = 0ac1af7002b3d761d1e55298da9d0506b9ae52057220a306e07b6b87e8df21d0ea00033de03984d34918
51
-
52
- # A.7. Test Case 7 = Test with SHA-1, salt not provided (defaults to HashLen
53
- # zero octets), zero-length info
54
- Hash = SHA1
55
- IKM = 0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
56
- salt = ""
57
- info = ""
58
- PRK = 2adccada18779e7c2077ad2eb19d3f3e731385dd
59
- OKM = 2c91117204d745f3500d636a62f64f0ab3bae548aa53d423b0d1f27ebba6f5e5673a081d70cce7acfc48