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,248 +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
- //! Key agreement: ECDH.
16
-
17
- use super::{c, digest, ecc, ffi};
18
- use super::input::Input;
19
- use std;
20
-
21
- /// A key agreement algorithm.
22
- pub struct Algorithm {
23
- ec_group_fn: unsafe extern fn () -> *const ecc::EC_GROUP,
24
- encoded_public_key_len: usize,
25
- nid: c::int,
26
- }
27
-
28
- /// An ephemeral key pair for use (only) with `agree_ephemeral`. The
29
- /// signature of `agree_ephemeral` ensures that an `EphemeralKeyPair` can be
30
- /// used for at most one key agreement.
31
- pub struct EphemeralKeyPair {
32
- key: *mut EC_KEY,
33
- algorithm: &'static Algorithm
34
- }
35
-
36
- impl EphemeralKeyPair {
37
- /// Generate a new ephemeral key pair for the given algorithm.
38
- ///
39
- /// C analog: `EC_KEY_new_by_curve_name` + `EC_KEY_generate_key`.
40
- pub fn generate(algorithm: &'static Algorithm)
41
- -> Result<EphemeralKeyPair, ()> {
42
- let key = try!(ffi::map_bssl_ptr_result(unsafe {
43
- EC_KEY_generate_key_ex((algorithm.ec_group_fn)())
44
- }));
45
- Ok(EphemeralKeyPair { key: key, algorithm: algorithm })
46
- }
47
-
48
- /// The size in bytes of the encoded public key returned from `public_key`.
49
- #[inline(always)]
50
- pub fn public_point_len(&self) -> usize {
51
- self.algorithm.encoded_public_key_len
52
- }
53
-
54
- /// Fills `out` with the public point encoded in the standard form for the
55
- /// algorithm.
56
- ///
57
- /// `out.len()` must be equal to the value returned by `public_point_len`.
58
- pub fn fill_with_encoded_public_key(&self, out: &mut [u8])
59
- -> Result<(), ()> {
60
- match unsafe {
61
- EC_KEY_public_key_to_oct(self.key, out.as_mut_ptr(), out.len())
62
- } {
63
- n if n == self.public_point_len() => Ok(()),
64
- _ => Err(())
65
- }
66
- }
67
- }
68
-
69
- impl Drop for EphemeralKeyPair {
70
- fn drop(&mut self) {
71
- unsafe {
72
- EC_KEY_free(self.key);
73
- }
74
- }
75
- }
76
-
77
- /// Performs a key agreement with an ephemeral key pair's private key and the
78
- /// given public key.
79
- ///
80
- /// `my_key_pair` is the ephemeral key pair to use. Since `my_key_pair` is
81
- /// moved, it will not be usable after calling `agree_ephemeral`, thus
82
- /// guaranteeing that the key is used for only one key agreement.
83
- /// `peer_algorithm` is the algorithm/curve for the peer's public key point;
84
- /// `agree_ephemeral` will return `Err(())` if it does not match `my_key_pair's`
85
- /// algorithm/curve. `peer_encoded_pubic_key` is the peer's public key. It
86
- /// must be encoded in the standard form for the algorithm; see the algorithm's
87
- /// documentation for details. `error_value` is the value to return if an error
88
- /// occurs before `kdf` is called, e.g. when decoding of the peer's public key
89
- /// fails. After the key agreement is done, `agree_ephemeral` calls `kdf` with
90
- /// the raw key material from the key agrement operation and then returns what
91
- /// `kdf` returns.
92
- ///
93
- /// C analogs: `ECDH_compute_key_ex` (*ring* only), `EC_POINT_oct2point` +
94
- /// `ECDH_compute_key`.
95
- //
96
- // TODO: If the key is authenticated then we don't necessarily need to verify
97
- // that the peer's public point is on the curve since a malicious
98
- // authenticated peer could just as easily give us a bad public point that is
99
- // on the curve. Also, given that our key pair is ephemeral, we're not risking
100
- // the leakage of a long-term key via invalid point attacks. Accordingly, even
101
- // though the lower-level C code does check that the peer's point is on the
102
- // curve, that check seems like overkill, at least for the most typical uses
103
- // of this function. On the other hand, some users may feel that it is
104
- // worthwhile to do point validity check even if it seems to be unnecssary.
105
- // Accordingly, it might be worthwhile to change this interface in the future
106
- // so that the caller can choose how much validation of the peer's public
107
- // point is done.
108
- pub fn agree_ephemeral<F, R, E>(my_key_pair: EphemeralKeyPair,
109
- peer_alg: &Algorithm,
110
- peer_encoded_public_point: Input,
111
- error_value: E, kdf: F) -> Result<R, E>
112
- where F: FnOnce(&[u8]) -> Result<R, E> {
113
- let mut shared_key = [0u8; MAX_COORDINATE_LEN];
114
- let mut shared_key_len = 0;
115
- let peer_encoded_public_point =
116
- peer_encoded_public_point.as_slice_less_safe();
117
- match unsafe {
118
- ECDH_compute_key_ex(shared_key.as_mut_ptr(), &mut shared_key_len,
119
- shared_key.len(), my_key_pair.key, peer_alg.nid,
120
- peer_encoded_public_point.as_ptr(),
121
- peer_encoded_public_point.len())
122
- } {
123
- 1 => kdf(&shared_key[0..shared_key_len]),
124
- _ => Err(error_value)
125
- }
126
- }
127
-
128
- // TODO: After ecdsa_test.cc is removed, this function should be removed and
129
- // the caller should be changed to call `SHA512_5` directly. Also, the
130
- // alternative implementation of this in crypto/test should be removed at
131
- // that time.
132
- #[allow(non_snake_case)]
133
- #[doc(hidden)]
134
- #[no_mangle]
135
- pub extern fn BN_generate_dsa_nonce_digest(
136
- out: *mut u8, out_len: c::size_t,
137
- part1: *const u8, part1_len: c::size_t,
138
- part2: *const u8, part2_len: c::size_t,
139
- part3: *const u8, part3_len: c::size_t,
140
- part4: *const u8, part4_len: c::size_t,
141
- part5: *const u8, part5_len: c::size_t)
142
- -> c::int {
143
- SHA512_5(out, out_len, part1, part1_len, part2, part2_len, part3,
144
- part3_len, part4, part4_len, part5, part5_len);
145
- 1
146
- }
147
-
148
- /// SHA512_5 calculates the SHA-512 digest of the concatenation of |part1|
149
- /// through |part5|. Any part<N> may be null if and only if the corresponding
150
- /// part<N>_len is zero. This ugliness exists in order to allow some of the
151
- /// C ECC code to calculate SHA-512 digests.
152
- #[allow(non_snake_case)]
153
- #[doc(hidden)]
154
- #[no_mangle]
155
- pub extern fn SHA512_5(out: *mut u8, out_len: c::size_t,
156
- part1: *const u8, part1_len: c::size_t,
157
- part2: *const u8, part2_len: c::size_t,
158
- part3: *const u8, part3_len: c::size_t,
159
- part4: *const u8, part4_len: c::size_t,
160
- part5: *const u8, part5_len: c::size_t) {
161
- fn maybe_update(ctx: &mut digest::Context, part: *const u8,
162
- part_len: c::size_t) {
163
- if part_len != 0 {
164
- assert!(!part.is_null());
165
- ctx.update(unsafe { std::slice::from_raw_parts(part, part_len) });
166
- }
167
- }
168
-
169
- let mut ctx = digest::Context::new(&digest::SHA512);
170
- maybe_update(&mut ctx, part1, part1_len);
171
- maybe_update(&mut ctx, part2, part2_len);
172
- maybe_update(&mut ctx, part3, part3_len);
173
- maybe_update(&mut ctx, part4, part4_len);
174
- maybe_update(&mut ctx, part5, part5_len);
175
- let digest = ctx.finish();
176
- let digest = digest.as_ref();
177
- let out = unsafe { std::slice::from_raw_parts_mut(out, out_len) };
178
- assert_eq!(out.len(), digest.len());
179
- for i in 0..digest.len() {
180
- out[i] = digest[i];
181
- }
182
- }
183
-
184
- // XXX: Replace with `const fn` when `const fn` is stable:
185
- // https://github.com/rust-lang/rust/issues/24111
186
- macro_rules! encoded_public_key_len {
187
- ( $bits:expr ) => ( 1 + (2 * (($bits + 7) / 8)) )
188
- }
189
-
190
- /// ECDH using the NIST P-256 (secp256r1) curve.
191
- ///
192
- /// Public keys are encoding in uncompressed form using the
193
- /// Octet-String-to-Elliptic-Curve-Point algorithm in [SEC 1: Elliptic Curve
194
- /// Cryptography, Version 2.0](http://www.secg.org/sec1-v2.pdf).
195
- ///
196
- /// C analogs: `EC_GROUP_P256` (*ring* only),
197
- /// `EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1)`")
198
- pub static ECDH_P256: Algorithm = Algorithm {
199
- ec_group_fn: ecc::EC_GROUP_P256,
200
- encoded_public_key_len: encoded_public_key_len!(256),
201
- nid: 415, // NID_X9_62_prime256v1
202
- };
203
-
204
- /// ECDH using the NIST P-384 (secp384r1) curve.
205
- ///
206
- /// Public keys are encoding in uncompressed form using the
207
- /// Octet-String-to-Elliptic-Curve-Point algorithm in [SEC 1: Elliptic Curve
208
- /// Cryptography, Version 2.0](http://www.secg.org/sec1-v2.pdf).
209
- ///
210
- /// C analogs: `EC_GROUP_P384` (*ring* only),
211
- /// `EC_GROUP_new_by_curve_name(NID_secp384r1)`")
212
- pub static ECDH_P384: Algorithm = Algorithm {
213
- ec_group_fn: ecc::EC_GROUP_P384,
214
- encoded_public_key_len: encoded_public_key_len!(384),
215
- nid: 715, // NID_secp384r1
216
- };
217
-
218
- /// ECDH using the NIST P-521 (secp521r1) curve.
219
- ///
220
- /// Public keys are encoding in uncompressed form using the
221
- /// Octet-String-to-Elliptic-Curve-Point algorithm in [SEC 1: Elliptic Curve
222
- /// Cryptography, Version 2.0](http://www.secg.org/sec1-v2.pdf).
223
- ///
224
- /// C analogs: `EC_GROUP_new_p521` (*ring* only),
225
- /// `EC_GROUP_new_by_curve_name(NID_secp521r1)`")
226
- pub static ECDH_P521: Algorithm = Algorithm {
227
- ec_group_fn: ecc::EC_GROUP_P521,
228
- encoded_public_key_len: encoded_public_key_len!(521),
229
- nid: 716, // NID_secp521r1
230
- };
231
-
232
- const MAX_COORDINATE_LEN: usize = (521 + 7) / 8;
233
-
234
- #[allow(non_camel_case_types)]
235
- enum EC_KEY { }
236
-
237
- extern {
238
- fn EC_KEY_generate_key_ex(group: *const ecc::EC_GROUP) -> *mut EC_KEY;
239
- fn EC_KEY_public_key_to_oct(key: *const EC_KEY, out: *mut u8,
240
- out_len: c::size_t) -> c::size_t;
241
- fn EC_KEY_free(key: *mut EC_KEY);
242
-
243
- fn ECDH_compute_key_ex(out: *mut u8, out_len: *mut c::size_t,
244
- max_out_len: c::size_t, my_key_pair: *const EC_KEY,
245
- peer_curve_nid: c::int,
246
- peer_pub_point_bytes: *const u8,
247
- peer_pub_point_bytes_len: c::size_t) -> c::int;
248
- }
@@ -1,129 +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
- //! TODO: Module-level documentation.
16
-
17
- #![allow(non_camel_case_types)]
18
-
19
- macro_rules! define_type {
20
- ( $name:ident, $builtin:ty, $test_c_metrics:ident, $get_c_align_fn:ident,
21
- $get_c_size_fn:ident, $doc:expr ) =>
22
- {
23
- #[doc = $doc]
24
- pub type $name = $builtin;
25
-
26
- define_metrics_tests!($name, $test_c_metrics, $get_c_align_fn,
27
- $get_c_size_fn);
28
- }
29
- }
30
-
31
- macro_rules! define_metrics_tests {
32
- ( $name:ident, $test_c_metrics:ident, $get_c_align_fn:ident,
33
- $get_c_size_fn:ident ) =>
34
- {
35
- #[cfg(test)]
36
- extern {
37
- // We can't use `size_t` because we need to test that our
38
- // definition of `size_t` is correct using this code! We use `u16`
39
- // because even 8-bit and 16-bit microcontrollers have no trouble
40
- // with it, and because `u16` is always as smaller or smaller than
41
- // `usize`.
42
- fn $get_c_align_fn() -> u16;
43
- fn $get_c_size_fn() -> u16;
44
- }
45
-
46
- #[cfg(test)]
47
- #[test]
48
- fn $test_c_metrics() {
49
- use std::mem;
50
-
51
- let c_align = unsafe { $get_c_align_fn() };
52
- let c_size = unsafe { $get_c_size_fn() };
53
-
54
- // XXX: Remove these assertions and these uses of `as` when Rust
55
- // supports implicit coercion of `u16` to `usize`.
56
- assert!(mem::size_of_val(&c_align) <= mem::size_of::<usize>());
57
- assert!(mem::size_of_val(&c_size) <= mem::size_of::<usize>());
58
- assert_eq!((mem::align_of::<$name>(), mem::size_of::<$name>()),
59
- (c_align as usize, c_size as usize));
60
- }
61
- }
62
- }
63
-
64
- define_type!(int, i32, test_int_metrics, ring_int_align, ring_int_size,
65
- "The C `int` type. Equivalent to `libc::int`.");
66
-
67
- define_type!(
68
- size_t, usize, test_size_t_metrics, ring_size_t_align, ring_size_t_size,
69
- "The C `size_t` type from `<stdint.h>`.
70
-
71
- ISO C's `size_t` is defined to be the type of the result of the
72
- `sizeof` operator and the type of the size parameter to `malloc`. That
73
- is, C's `size_t` is only required to hold the size of the largest object
74
- that can be allocated. In particular, it is legal for a C implementation
75
- to have a maximum object size smaller than the entire address space. For
76
- example, a C implementation may have an maximum object size of 2^32
77
- bytes with a 64-bit address space, and typedef `size_t` as `uint32_t` so
78
- that `sizeof(size_t) == 4` and `sizeof(void*) == 8`.
79
-
80
- Rust's `usize`, on the other hand, is defined to always be the same size
81
- as a pointer. This means that it is possible, in theory, to have a platform
82
- where `usize` can represent values that `size_t` cannot represent. However,
83
- on the vast majority of systems, `usize` and `size_t` are represented the
84
- same way. If it were required to explicitly cast `usize` to `size_t` on
85
- common platforms, then many programmers would habitually write expressions
86
- such as `my_slice.len() as libc::size_t` expecting this to always work and
87
- be safe. But such a cast is *not* safe on the uncommon platforms where
88
- `mem::sizeof(libc::size_t) < mem::size_t(usize)`. Consequently, to reduce
89
- the chances of programmers becoming habituated to such casts that would be
90
- unsafe on unusual platforms, we have adopted the following convention:
91
-
92
- * On common platforms where C's `size_t` is the same size as `usize`,
93
- `ring::c::size_t` must be a type alias of `usize`.
94
-
95
- * On uncommon platforms where C's `size_t` is not the same size as `usize`,
96
- `ring::c::size_t` must be a type alias for a type other than `usize`.
97
-
98
- * Code that was written without consideration for the uncommon platforms
99
- should not do any explicit casting between `size_t` and `usize`. Such
100
- code will fail to compile on the uncommon platforms; this is better than
101
- executing with unsafe truncations.
102
-
103
- * Code that was written with full consideration of the uncommon platforms
104
- should have explicit casts using `num::cast` or other methods that avoid
105
- unintended truncation. Such code will then work on all platforms.");
106
-
107
- // XXX: MSVC's `alignof` returns strange values for `int8_t`.
108
- #[cfg(not(windows))]
109
- define_metrics_tests!(i8, test_i8_metrics, ring_int8_t_align, ring_int8_t_size);
110
-
111
- // XXX: MSVC's `alignof` returns strange values for `uint8_t`.
112
- #[cfg(not(windows))]
113
- define_metrics_tests!(u8, test_u8_metrics, ring_uint8_t_align,
114
- ring_uint8_t_size);
115
-
116
- define_metrics_tests!(i16, test_i16_metrics, ring_int16_t_align,
117
- ring_int16_t_size);
118
- define_metrics_tests!(u16, test_u16_metrics, ring_uint16_t_align,
119
- ring_uint16_t_size);
120
-
121
- define_metrics_tests!(i32, test_i32_metrics, ring_int32_t_align,
122
- ring_int32_t_size);
123
- define_metrics_tests!(u32, test_u32_metrics, ring_uint32_t_align,
124
- ring_uint32_t_size);
125
-
126
- define_metrics_tests!(i64, test_i64_metrics, ring_int64_t_align,
127
- ring_int64_t_size);
128
- define_metrics_tests!(u64, test_u64_metrics, ring_uint64_t_align,
129
- ring_uint64_t_size);
@@ -1,37 +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
- //! Constant-time operations.
16
-
17
- use super::c;
18
-
19
- /// Returns `Ok(())` if `a == b` and `Err(())` otherwise. The comparison of
20
- /// `a` and `b` is done in constant time with respect to the contents of each,
21
- /// but NOT in constant time with respect to the lengths of `a` and `b`.
22
- pub fn verify_slices_are_equal(a: &[u8], b: &[u8]) -> Result<(), ()> {
23
- if a.len() != b.len() {
24
- return Err(());
25
- }
26
- let result = unsafe {
27
- CRYPTO_memcmp(a.as_ptr(), b.as_ptr(), a.len())
28
- };
29
- match result {
30
- 0 => Ok(()),
31
- _ => Err(())
32
- }
33
- }
34
-
35
- extern {
36
- fn CRYPTO_memcmp(a: *const u8, b: *const u8, len: c::size_t) -> c::int;
37
- }
@@ -1,96 +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
- //! Building blocks for parsing DER-encoded ASN.1 structures.
16
- //!
17
- //! This module contains the foundational parts of an ASN.1 DER parser.
18
-
19
- use super::input::*;
20
-
21
- pub const CONSTRUCTED : u8 = 1 << 5;
22
- pub const CONTEXT_SPECIFIC : u8 = 2 << 6;
23
-
24
- #[derive(Clone, Copy, PartialEq)]
25
- #[repr(u8)]
26
- pub enum Tag {
27
- Boolean = 0x01,
28
- Integer = 0x02,
29
- BitString = 0x03,
30
- OctetString = 0x04,
31
- Null = 0x05,
32
- OID = 0x06,
33
- Sequence = CONSTRUCTED | 0x10, // 0x30
34
- UTCTime = 0x17,
35
- GeneralizedTime = 0x18,
36
-
37
- ContextSpecificConstructed0 = CONTEXT_SPECIFIC | CONSTRUCTED | 0,
38
- ContextSpecificConstructed1 = CONTEXT_SPECIFIC | CONSTRUCTED | 1,
39
- ContextSpecificConstructed3 = CONTEXT_SPECIFIC | CONSTRUCTED | 3,
40
- }
41
-
42
- pub fn expect_tag_and_get_value<'a>(input: &mut Reader<'a>, tag: Tag)
43
- -> Result<Input<'a>, ()> {
44
- let (actual_tag, inner) = try!(read_tag_and_get_value(input));
45
- if (tag as usize) != (actual_tag as usize) {
46
- return Err(());
47
- }
48
- Ok(inner)
49
- }
50
-
51
- pub fn read_tag_and_get_value<'a>(input: &mut Reader<'a>)
52
- -> Result<(u8, Input<'a>), ()> {
53
- let tag = try!(input.read_byte());
54
- if (tag & 0x1F) == 0x1F {
55
- return Err(()) // High tag number form is not allowed.
56
- }
57
-
58
- // If the high order bit of the first byte is set to zero then the length
59
- // is encoded in the seven remaining bits of that byte. Otherwise, those
60
- // seven bits represent the number of bytes used to encode the length.
61
- let length = match try!(input.read_byte()) {
62
- n if (n & 0x80) == 0 => n as usize,
63
- 0x81 => {
64
- let second_byte = try!(input.read_byte());
65
- if second_byte < 128 {
66
- return Err(()) // Not the canonical encoding.
67
- }
68
- second_byte as usize
69
- },
70
- 0x82 => {
71
- let second_byte = try!(input.read_byte()) as usize;
72
- let third_byte = try!(input.read_byte()) as usize;
73
- let combined = (second_byte << 8) | third_byte;
74
- if combined < 256 {
75
- return Err(()); // Not the canonical encoding.
76
- }
77
- combined
78
- },
79
- _ => {
80
- return Err(()); // We don't support longer lengths.
81
- }
82
- };
83
-
84
- let inner = try!(input.skip_and_get_input(length));
85
- Ok((tag, inner))
86
- }
87
-
88
- // TODO: investigate taking decoder as a reference to reduce generated code
89
- // size.
90
- pub fn nested<'a, F, R, E: Copy>(input: &mut Reader<'a>, tag: Tag, error: E,
91
- decoder: F) -> Result<R, E>
92
- where F : FnOnce(&mut Reader<'a>)
93
- -> Result<R, E> {
94
- let inner = try!(expect_tag_and_get_value(input, tag).map_err(|_| error));
95
- read_all(inner, error, decoder)
96
- }