ring-native 0.0.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 (261) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/Gemfile +3 -0
  4. data/README.md +22 -0
  5. data/Rakefile +1 -0
  6. data/ext/ring/extconf.rb +29 -0
  7. data/lib/ring/native.rb +8 -0
  8. data/lib/ring/native/version.rb +5 -0
  9. data/ring-native.gemspec +25 -0
  10. data/vendor/ring/BUILDING.md +40 -0
  11. data/vendor/ring/Cargo.toml +43 -0
  12. data/vendor/ring/LICENSE +185 -0
  13. data/vendor/ring/Makefile +35 -0
  14. data/vendor/ring/PORTING.md +163 -0
  15. data/vendor/ring/README.md +113 -0
  16. data/vendor/ring/STYLE.md +197 -0
  17. data/vendor/ring/appveyor.yml +27 -0
  18. data/vendor/ring/build.rs +108 -0
  19. data/vendor/ring/crypto/aes/aes.c +1142 -0
  20. data/vendor/ring/crypto/aes/aes_test.Windows.vcxproj +25 -0
  21. data/vendor/ring/crypto/aes/aes_test.cc +93 -0
  22. data/vendor/ring/crypto/aes/asm/aes-586.pl +2368 -0
  23. data/vendor/ring/crypto/aes/asm/aes-armv4.pl +1249 -0
  24. data/vendor/ring/crypto/aes/asm/aes-x86_64.pl +2246 -0
  25. data/vendor/ring/crypto/aes/asm/aesni-x86.pl +1318 -0
  26. data/vendor/ring/crypto/aes/asm/aesni-x86_64.pl +2084 -0
  27. data/vendor/ring/crypto/aes/asm/aesv8-armx.pl +675 -0
  28. data/vendor/ring/crypto/aes/asm/bsaes-armv7.pl +1364 -0
  29. data/vendor/ring/crypto/aes/asm/bsaes-x86_64.pl +1565 -0
  30. data/vendor/ring/crypto/aes/asm/vpaes-x86.pl +841 -0
  31. data/vendor/ring/crypto/aes/asm/vpaes-x86_64.pl +1116 -0
  32. data/vendor/ring/crypto/aes/internal.h +87 -0
  33. data/vendor/ring/crypto/aes/mode_wrappers.c +61 -0
  34. data/vendor/ring/crypto/bn/add.c +394 -0
  35. data/vendor/ring/crypto/bn/asm/armv4-mont.pl +694 -0
  36. data/vendor/ring/crypto/bn/asm/armv8-mont.pl +1503 -0
  37. data/vendor/ring/crypto/bn/asm/bn-586.pl +774 -0
  38. data/vendor/ring/crypto/bn/asm/co-586.pl +287 -0
  39. data/vendor/ring/crypto/bn/asm/rsaz-avx2.pl +1882 -0
  40. data/vendor/ring/crypto/bn/asm/x86-mont.pl +592 -0
  41. data/vendor/ring/crypto/bn/asm/x86_64-gcc.c +599 -0
  42. data/vendor/ring/crypto/bn/asm/x86_64-mont.pl +1393 -0
  43. data/vendor/ring/crypto/bn/asm/x86_64-mont5.pl +3507 -0
  44. data/vendor/ring/crypto/bn/bn.c +352 -0
  45. data/vendor/ring/crypto/bn/bn_asn1.c +74 -0
  46. data/vendor/ring/crypto/bn/bn_test.Windows.vcxproj +25 -0
  47. data/vendor/ring/crypto/bn/bn_test.cc +1696 -0
  48. data/vendor/ring/crypto/bn/cmp.c +200 -0
  49. data/vendor/ring/crypto/bn/convert.c +433 -0
  50. data/vendor/ring/crypto/bn/ctx.c +311 -0
  51. data/vendor/ring/crypto/bn/div.c +594 -0
  52. data/vendor/ring/crypto/bn/exponentiation.c +1335 -0
  53. data/vendor/ring/crypto/bn/gcd.c +711 -0
  54. data/vendor/ring/crypto/bn/generic.c +1019 -0
  55. data/vendor/ring/crypto/bn/internal.h +316 -0
  56. data/vendor/ring/crypto/bn/montgomery.c +516 -0
  57. data/vendor/ring/crypto/bn/mul.c +888 -0
  58. data/vendor/ring/crypto/bn/prime.c +829 -0
  59. data/vendor/ring/crypto/bn/random.c +334 -0
  60. data/vendor/ring/crypto/bn/rsaz_exp.c +262 -0
  61. data/vendor/ring/crypto/bn/rsaz_exp.h +53 -0
  62. data/vendor/ring/crypto/bn/shift.c +276 -0
  63. data/vendor/ring/crypto/bytestring/bytestring_test.Windows.vcxproj +25 -0
  64. data/vendor/ring/crypto/bytestring/bytestring_test.cc +421 -0
  65. data/vendor/ring/crypto/bytestring/cbb.c +399 -0
  66. data/vendor/ring/crypto/bytestring/cbs.c +227 -0
  67. data/vendor/ring/crypto/bytestring/internal.h +46 -0
  68. data/vendor/ring/crypto/chacha/chacha_generic.c +140 -0
  69. data/vendor/ring/crypto/chacha/chacha_vec.c +323 -0
  70. data/vendor/ring/crypto/chacha/chacha_vec_arm.S +1447 -0
  71. data/vendor/ring/crypto/chacha/chacha_vec_arm_generate.go +153 -0
  72. data/vendor/ring/crypto/cipher/cipher_test.Windows.vcxproj +25 -0
  73. data/vendor/ring/crypto/cipher/e_aes.c +390 -0
  74. data/vendor/ring/crypto/cipher/e_chacha20poly1305.c +208 -0
  75. data/vendor/ring/crypto/cipher/internal.h +173 -0
  76. data/vendor/ring/crypto/cipher/test/aes_128_gcm_tests.txt +543 -0
  77. data/vendor/ring/crypto/cipher/test/aes_128_key_wrap_tests.txt +9 -0
  78. data/vendor/ring/crypto/cipher/test/aes_256_gcm_tests.txt +475 -0
  79. data/vendor/ring/crypto/cipher/test/aes_256_key_wrap_tests.txt +23 -0
  80. data/vendor/ring/crypto/cipher/test/chacha20_poly1305_old_tests.txt +422 -0
  81. data/vendor/ring/crypto/cipher/test/chacha20_poly1305_tests.txt +484 -0
  82. data/vendor/ring/crypto/cipher/test/cipher_test.txt +100 -0
  83. data/vendor/ring/crypto/constant_time_test.Windows.vcxproj +25 -0
  84. data/vendor/ring/crypto/constant_time_test.c +304 -0
  85. data/vendor/ring/crypto/cpu-arm-asm.S +32 -0
  86. data/vendor/ring/crypto/cpu-arm.c +199 -0
  87. data/vendor/ring/crypto/cpu-intel.c +261 -0
  88. data/vendor/ring/crypto/crypto.c +151 -0
  89. data/vendor/ring/crypto/curve25519/asm/x25519-arm.S +2118 -0
  90. data/vendor/ring/crypto/curve25519/curve25519.c +4888 -0
  91. data/vendor/ring/crypto/curve25519/x25519_test.cc +128 -0
  92. data/vendor/ring/crypto/digest/md32_common.h +181 -0
  93. data/vendor/ring/crypto/ec/asm/p256-x86_64-asm.pl +2725 -0
  94. data/vendor/ring/crypto/ec/ec.c +193 -0
  95. data/vendor/ring/crypto/ec/ec_curves.c +61 -0
  96. data/vendor/ring/crypto/ec/ec_key.c +228 -0
  97. data/vendor/ring/crypto/ec/ec_montgomery.c +114 -0
  98. data/vendor/ring/crypto/ec/example_mul.Windows.vcxproj +25 -0
  99. data/vendor/ring/crypto/ec/internal.h +243 -0
  100. data/vendor/ring/crypto/ec/oct.c +253 -0
  101. data/vendor/ring/crypto/ec/p256-64.c +1794 -0
  102. data/vendor/ring/crypto/ec/p256-x86_64-table.h +9548 -0
  103. data/vendor/ring/crypto/ec/p256-x86_64.c +509 -0
  104. data/vendor/ring/crypto/ec/simple.c +1007 -0
  105. data/vendor/ring/crypto/ec/util-64.c +183 -0
  106. data/vendor/ring/crypto/ec/wnaf.c +508 -0
  107. data/vendor/ring/crypto/ecdh/ecdh.c +155 -0
  108. data/vendor/ring/crypto/ecdsa/ecdsa.c +304 -0
  109. data/vendor/ring/crypto/ecdsa/ecdsa_asn1.c +193 -0
  110. data/vendor/ring/crypto/ecdsa/ecdsa_test.Windows.vcxproj +25 -0
  111. data/vendor/ring/crypto/ecdsa/ecdsa_test.cc +327 -0
  112. data/vendor/ring/crypto/header_removed.h +17 -0
  113. data/vendor/ring/crypto/internal.h +495 -0
  114. data/vendor/ring/crypto/libring.Windows.vcxproj +101 -0
  115. data/vendor/ring/crypto/mem.c +98 -0
  116. data/vendor/ring/crypto/modes/asm/aesni-gcm-x86_64.pl +1045 -0
  117. data/vendor/ring/crypto/modes/asm/ghash-armv4.pl +517 -0
  118. data/vendor/ring/crypto/modes/asm/ghash-x86.pl +1393 -0
  119. data/vendor/ring/crypto/modes/asm/ghash-x86_64.pl +1741 -0
  120. data/vendor/ring/crypto/modes/asm/ghashv8-armx.pl +422 -0
  121. data/vendor/ring/crypto/modes/ctr.c +226 -0
  122. data/vendor/ring/crypto/modes/gcm.c +1206 -0
  123. data/vendor/ring/crypto/modes/gcm_test.Windows.vcxproj +25 -0
  124. data/vendor/ring/crypto/modes/gcm_test.c +348 -0
  125. data/vendor/ring/crypto/modes/internal.h +299 -0
  126. data/vendor/ring/crypto/perlasm/arm-xlate.pl +170 -0
  127. data/vendor/ring/crypto/perlasm/readme +100 -0
  128. data/vendor/ring/crypto/perlasm/x86_64-xlate.pl +1164 -0
  129. data/vendor/ring/crypto/perlasm/x86asm.pl +292 -0
  130. data/vendor/ring/crypto/perlasm/x86gas.pl +263 -0
  131. data/vendor/ring/crypto/perlasm/x86masm.pl +200 -0
  132. data/vendor/ring/crypto/perlasm/x86nasm.pl +187 -0
  133. data/vendor/ring/crypto/poly1305/poly1305.c +331 -0
  134. data/vendor/ring/crypto/poly1305/poly1305_arm.c +301 -0
  135. data/vendor/ring/crypto/poly1305/poly1305_arm_asm.S +2015 -0
  136. data/vendor/ring/crypto/poly1305/poly1305_test.Windows.vcxproj +25 -0
  137. data/vendor/ring/crypto/poly1305/poly1305_test.cc +80 -0
  138. data/vendor/ring/crypto/poly1305/poly1305_test.txt +52 -0
  139. data/vendor/ring/crypto/poly1305/poly1305_vec.c +892 -0
  140. data/vendor/ring/crypto/rand/asm/rdrand-x86_64.pl +75 -0
  141. data/vendor/ring/crypto/rand/internal.h +32 -0
  142. data/vendor/ring/crypto/rand/rand.c +189 -0
  143. data/vendor/ring/crypto/rand/urandom.c +219 -0
  144. data/vendor/ring/crypto/rand/windows.c +56 -0
  145. data/vendor/ring/crypto/refcount_c11.c +66 -0
  146. data/vendor/ring/crypto/refcount_lock.c +53 -0
  147. data/vendor/ring/crypto/refcount_test.Windows.vcxproj +25 -0
  148. data/vendor/ring/crypto/refcount_test.c +58 -0
  149. data/vendor/ring/crypto/rsa/blinding.c +462 -0
  150. data/vendor/ring/crypto/rsa/internal.h +108 -0
  151. data/vendor/ring/crypto/rsa/padding.c +300 -0
  152. data/vendor/ring/crypto/rsa/rsa.c +450 -0
  153. data/vendor/ring/crypto/rsa/rsa_asn1.c +261 -0
  154. data/vendor/ring/crypto/rsa/rsa_impl.c +944 -0
  155. data/vendor/ring/crypto/rsa/rsa_test.Windows.vcxproj +25 -0
  156. data/vendor/ring/crypto/rsa/rsa_test.cc +437 -0
  157. data/vendor/ring/crypto/sha/asm/sha-armv8.pl +436 -0
  158. data/vendor/ring/crypto/sha/asm/sha-x86_64.pl +2390 -0
  159. data/vendor/ring/crypto/sha/asm/sha256-586.pl +1275 -0
  160. data/vendor/ring/crypto/sha/asm/sha256-armv4.pl +735 -0
  161. data/vendor/ring/crypto/sha/asm/sha256-armv8.pl +14 -0
  162. data/vendor/ring/crypto/sha/asm/sha256-x86_64.pl +14 -0
  163. data/vendor/ring/crypto/sha/asm/sha512-586.pl +911 -0
  164. data/vendor/ring/crypto/sha/asm/sha512-armv4.pl +666 -0
  165. data/vendor/ring/crypto/sha/asm/sha512-armv8.pl +14 -0
  166. data/vendor/ring/crypto/sha/asm/sha512-x86_64.pl +14 -0
  167. data/vendor/ring/crypto/sha/sha1.c +271 -0
  168. data/vendor/ring/crypto/sha/sha256.c +204 -0
  169. data/vendor/ring/crypto/sha/sha512.c +355 -0
  170. data/vendor/ring/crypto/test/file_test.cc +326 -0
  171. data/vendor/ring/crypto/test/file_test.h +181 -0
  172. data/vendor/ring/crypto/test/malloc.cc +150 -0
  173. data/vendor/ring/crypto/test/scoped_types.h +95 -0
  174. data/vendor/ring/crypto/test/test.Windows.vcxproj +35 -0
  175. data/vendor/ring/crypto/test/test_util.cc +46 -0
  176. data/vendor/ring/crypto/test/test_util.h +41 -0
  177. data/vendor/ring/crypto/thread_none.c +55 -0
  178. data/vendor/ring/crypto/thread_pthread.c +165 -0
  179. data/vendor/ring/crypto/thread_test.Windows.vcxproj +25 -0
  180. data/vendor/ring/crypto/thread_test.c +200 -0
  181. data/vendor/ring/crypto/thread_win.c +282 -0
  182. data/vendor/ring/examples/checkdigest.rs +103 -0
  183. data/vendor/ring/include/openssl/aes.h +121 -0
  184. data/vendor/ring/include/openssl/arm_arch.h +129 -0
  185. data/vendor/ring/include/openssl/base.h +156 -0
  186. data/vendor/ring/include/openssl/bn.h +794 -0
  187. data/vendor/ring/include/openssl/buffer.h +18 -0
  188. data/vendor/ring/include/openssl/bytestring.h +235 -0
  189. data/vendor/ring/include/openssl/chacha.h +37 -0
  190. data/vendor/ring/include/openssl/cmac.h +76 -0
  191. data/vendor/ring/include/openssl/cpu.h +184 -0
  192. data/vendor/ring/include/openssl/crypto.h +43 -0
  193. data/vendor/ring/include/openssl/curve25519.h +88 -0
  194. data/vendor/ring/include/openssl/ec.h +225 -0
  195. data/vendor/ring/include/openssl/ec_key.h +129 -0
  196. data/vendor/ring/include/openssl/ecdh.h +110 -0
  197. data/vendor/ring/include/openssl/ecdsa.h +156 -0
  198. data/vendor/ring/include/openssl/err.h +201 -0
  199. data/vendor/ring/include/openssl/mem.h +101 -0
  200. data/vendor/ring/include/openssl/obj_mac.h +71 -0
  201. data/vendor/ring/include/openssl/opensslfeatures.h +68 -0
  202. data/vendor/ring/include/openssl/opensslv.h +18 -0
  203. data/vendor/ring/include/openssl/ossl_typ.h +18 -0
  204. data/vendor/ring/include/openssl/poly1305.h +51 -0
  205. data/vendor/ring/include/openssl/rand.h +70 -0
  206. data/vendor/ring/include/openssl/rsa.h +399 -0
  207. data/vendor/ring/include/openssl/thread.h +133 -0
  208. data/vendor/ring/include/openssl/type_check.h +71 -0
  209. data/vendor/ring/mk/Common.props +63 -0
  210. data/vendor/ring/mk/Windows.props +42 -0
  211. data/vendor/ring/mk/WindowsTest.props +18 -0
  212. data/vendor/ring/mk/appveyor.bat +62 -0
  213. data/vendor/ring/mk/bottom_of_makefile.mk +54 -0
  214. data/vendor/ring/mk/ring.mk +266 -0
  215. data/vendor/ring/mk/top_of_makefile.mk +214 -0
  216. data/vendor/ring/mk/travis.sh +40 -0
  217. data/vendor/ring/mk/update-travis-yml.py +229 -0
  218. data/vendor/ring/ring.sln +153 -0
  219. data/vendor/ring/src/aead.rs +682 -0
  220. data/vendor/ring/src/agreement.rs +248 -0
  221. data/vendor/ring/src/c.rs +129 -0
  222. data/vendor/ring/src/constant_time.rs +37 -0
  223. data/vendor/ring/src/der.rs +96 -0
  224. data/vendor/ring/src/digest.rs +690 -0
  225. data/vendor/ring/src/digest_tests.txt +57 -0
  226. data/vendor/ring/src/ecc.rs +28 -0
  227. data/vendor/ring/src/ecc_build.rs +279 -0
  228. data/vendor/ring/src/ecc_curves.rs +117 -0
  229. data/vendor/ring/src/ed25519_tests.txt +2579 -0
  230. data/vendor/ring/src/exe_tests.rs +46 -0
  231. data/vendor/ring/src/ffi.rs +29 -0
  232. data/vendor/ring/src/file_test.rs +187 -0
  233. data/vendor/ring/src/hkdf.rs +153 -0
  234. data/vendor/ring/src/hkdf_tests.txt +59 -0
  235. data/vendor/ring/src/hmac.rs +414 -0
  236. data/vendor/ring/src/hmac_tests.txt +97 -0
  237. data/vendor/ring/src/input.rs +312 -0
  238. data/vendor/ring/src/lib.rs +41 -0
  239. data/vendor/ring/src/pbkdf2.rs +265 -0
  240. data/vendor/ring/src/pbkdf2_tests.txt +113 -0
  241. data/vendor/ring/src/polyfill.rs +57 -0
  242. data/vendor/ring/src/rand.rs +28 -0
  243. data/vendor/ring/src/signature.rs +314 -0
  244. data/vendor/ring/third-party/NIST/README.md +9 -0
  245. data/vendor/ring/third-party/NIST/SHAVS/SHA1LongMsg.rsp +263 -0
  246. data/vendor/ring/third-party/NIST/SHAVS/SHA1Monte.rsp +309 -0
  247. data/vendor/ring/third-party/NIST/SHAVS/SHA1ShortMsg.rsp +267 -0
  248. data/vendor/ring/third-party/NIST/SHAVS/SHA224LongMsg.rsp +263 -0
  249. data/vendor/ring/third-party/NIST/SHAVS/SHA224Monte.rsp +309 -0
  250. data/vendor/ring/third-party/NIST/SHAVS/SHA224ShortMsg.rsp +267 -0
  251. data/vendor/ring/third-party/NIST/SHAVS/SHA256LongMsg.rsp +263 -0
  252. data/vendor/ring/third-party/NIST/SHAVS/SHA256Monte.rsp +309 -0
  253. data/vendor/ring/third-party/NIST/SHAVS/SHA256ShortMsg.rsp +267 -0
  254. data/vendor/ring/third-party/NIST/SHAVS/SHA384LongMsg.rsp +519 -0
  255. data/vendor/ring/third-party/NIST/SHAVS/SHA384Monte.rsp +309 -0
  256. data/vendor/ring/third-party/NIST/SHAVS/SHA384ShortMsg.rsp +523 -0
  257. data/vendor/ring/third-party/NIST/SHAVS/SHA512LongMsg.rsp +519 -0
  258. data/vendor/ring/third-party/NIST/SHAVS/SHA512Monte.rsp +309 -0
  259. data/vendor/ring/third-party/NIST/SHAVS/SHA512ShortMsg.rsp +523 -0
  260. data/vendor/ring/third-party/NIST/sha256sums.txt +1 -0
  261. metadata +333 -0
@@ -0,0 +1,46 @@
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", []);
@@ -0,0 +1,29 @@
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
+ }
@@ -0,0 +1,187 @@
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
+ }
@@ -0,0 +1,153 @@
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
+ }
@@ -0,0 +1,59 @@
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