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,153 @@
1
+ // Copyright (c) 2014, Google Inc.
2
+ //
3
+ // Permission to use, copy, modify, and/or distribute this software for any
4
+ // purpose with or without fee is hereby granted, provided that the above
5
+ // copyright notice and this permission notice appear in all copies.
6
+ //
7
+ // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
+ // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
+ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
+ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ // This package generates chacha_vec_arm.S from chacha_vec.c. Install the
16
+ // arm-linux-gnueabihf-gcc compiler as described in BUILDING.md. Then:
17
+ // `(cd crypto/chacha && go run chacha_vec_arm_generate.go)`.
18
+
19
+ package main
20
+
21
+ import (
22
+ "bufio"
23
+ "bytes"
24
+ "os"
25
+ "os/exec"
26
+ "strings"
27
+ )
28
+
29
+ const defaultCompiler = "/opt/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc"
30
+
31
+ func main() {
32
+ compiler := defaultCompiler
33
+ if len(os.Args) > 1 {
34
+ compiler = os.Args[1]
35
+ }
36
+
37
+ args := []string{
38
+ "-O3",
39
+ "-mcpu=cortex-a8",
40
+ "-mfpu=neon",
41
+ "-fpic",
42
+ "-DASM_GEN",
43
+ "-I", "../../include",
44
+ "-S", "chacha_vec.c",
45
+ "-o", "-",
46
+ }
47
+
48
+ output, err := os.OpenFile("chacha_vec_arm.S", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
49
+ if err != nil {
50
+ panic(err)
51
+ }
52
+ defer output.Close()
53
+
54
+ output.WriteString(preamble)
55
+ output.WriteString(compiler)
56
+ output.WriteString(" ")
57
+ output.WriteString(strings.Join(args, " "))
58
+ output.WriteString("\n\n#if !defined(OPENSSL_NO_ASM)\n")
59
+ output.WriteString("#if defined(__arm__)\n\n")
60
+
61
+ cmd := exec.Command(compiler, args...)
62
+ cmd.Stderr = os.Stderr
63
+ asm, err := cmd.StdoutPipe()
64
+ if err != nil {
65
+ panic(err)
66
+ }
67
+ if err := cmd.Start(); err != nil {
68
+ panic(err)
69
+ }
70
+
71
+ attr28 := []byte(".eabi_attribute 28,")
72
+ globalDirective := []byte(".global\t")
73
+ newLine := []byte("\n")
74
+ attr28Handled := false
75
+
76
+ scanner := bufio.NewScanner(asm)
77
+ for scanner.Scan() {
78
+ line := scanner.Bytes()
79
+
80
+ if bytes.Contains(line, attr28) {
81
+ output.WriteString(attr28Block)
82
+ attr28Handled = true
83
+ continue
84
+ }
85
+
86
+ output.Write(line)
87
+ output.Write(newLine)
88
+
89
+ if i := bytes.Index(line, globalDirective); i >= 0 {
90
+ output.Write(line[:i])
91
+ output.WriteString(".hidden\t")
92
+ output.Write(line[i+len(globalDirective):])
93
+ output.Write(newLine)
94
+ }
95
+ }
96
+
97
+ if err := scanner.Err(); err != nil {
98
+ panic(err)
99
+ }
100
+
101
+ if !attr28Handled {
102
+ panic("EABI attribute 28 not seen in processing")
103
+ }
104
+
105
+ if err := cmd.Wait(); err != nil {
106
+ panic(err)
107
+ }
108
+
109
+ output.WriteString(trailer)
110
+ }
111
+
112
+ const preamble = `# Copyright (c) 2014, Google Inc.
113
+ #
114
+ # Permission to use, copy, modify, and/or distribute this software for any
115
+ # purpose with or without fee is hereby granted, provided that the above
116
+ # copyright notice and this permission notice appear in all copies.
117
+ #
118
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
119
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
120
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
121
+ # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
122
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
123
+ # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
124
+ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
125
+
126
+ # This file contains a pre-compiled version of chacha_vec.c for ARM. This is
127
+ # needed to support switching on NEON code at runtime. If the whole of OpenSSL
128
+ # were to be compiled with the needed flags to build chacha_vec.c, then it
129
+ # wouldn't be possible to run on non-NEON systems.
130
+ #
131
+ # This file was generated by chacha_vec_arm_generate.go using the following
132
+ # compiler command:
133
+ #
134
+ # `
135
+
136
+ const attr28Block = `
137
+ # EABI attribute 28 sets whether VFP register arguments were used to build this
138
+ # file. If object files are inconsistent on this point, the linker will refuse
139
+ # to link them. Thus we report whatever the compiler expects since we don't use
140
+ # VFP arguments.
141
+
142
+ #if defined(__ARM_PCS_VFP)
143
+ .eabi_attribute 28, 1
144
+ #else
145
+ .eabi_attribute 28, 0
146
+ #endif
147
+
148
+ `
149
+
150
+ const trailer = `
151
+ #endif /* __arm__ */
152
+ #endif /* !OPENSSL_NO_ASM */
153
+ `
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup Label="Globals">
4
+ <ProjectGuid>{E9BBE9B6-8361-4007-B523-E59FDB775D01}</ProjectGuid>
5
+ <TargetName>cipher_test</TargetName>
6
+ </PropertyGroup>
7
+ <ImportGroup Label="PropertySheets">
8
+ <Import Project="..\..\mk\WindowsTest.props" />
9
+ </ImportGroup>
10
+ <PropertyGroup Label="Configuration">
11
+ <OutDir>$(OutRootDir)test\ring\crypto\cipher\</OutDir>
12
+ </PropertyGroup>
13
+ <ItemGroup>
14
+ <ClCompile Include="cipher_test.cc" />
15
+ </ItemGroup>
16
+ <ItemGroup>
17
+ <ProjectReference Include="..\libring.Windows.vcxproj">
18
+ <Project>{f4c0a1b6-5e09-41c8-8242-3e1f6762fb18}</Project>
19
+ </ProjectReference>
20
+ <ProjectReference Include="..\test\test.Windows.vcxproj">
21
+ <Project>{1dace503-6498-492d-b1ff-f9ee18624443}</Project>
22
+ </ProjectReference>
23
+ </ItemGroup>
24
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
25
+ </Project>
@@ -0,0 +1,390 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. All advertising materials mentioning features or use of this
17
+ * software must display the following acknowledgment:
18
+ * "This product includes software developed by the OpenSSL Project
19
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20
+ *
21
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22
+ * endorse or promote products derived from this software without
23
+ * prior written permission. For written permission, please contact
24
+ * openssl-core@openssl.org.
25
+ *
26
+ * 5. Products derived from this software may not be called "OpenSSL"
27
+ * nor may "OpenSSL" appear in their names without prior written
28
+ * permission of the OpenSSL Project.
29
+ *
30
+ * 6. Redistributions of any form whatsoever must retain the following
31
+ * acknowledgment:
32
+ * "This product includes software developed by the OpenSSL Project
33
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34
+ *
35
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
47
+ * ==================================================================== */
48
+
49
+ #include <string.h>
50
+
51
+ #include <openssl/aes.h>
52
+ #include <openssl/cpu.h>
53
+ #include <openssl/err.h>
54
+ #include <openssl/mem.h>
55
+ #include <openssl/obj_mac.h>
56
+ #include <openssl/rand.h>
57
+
58
+ #include "internal.h"
59
+ #include "../internal.h"
60
+ #include "../modes/internal.h"
61
+
62
+ #if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
63
+ #include <openssl/arm_arch.h>
64
+ #endif
65
+
66
+
67
+ #define EVP_AEAD_AES_GCM_NONCE_LEN 12
68
+ #define EVP_AEAD_AES_GCM_TAG_LEN 16
69
+
70
+ #if !defined(OPENSSL_NO_ASM) && \
71
+ (defined(OPENSSL_X86_64) || defined(OPENSSL_X86))
72
+ #define VPAES
73
+ static char vpaes_capable(void) {
74
+ return (OPENSSL_ia32cap_P[1] & (1 << (41 - 32))) != 0;
75
+ }
76
+
77
+ #if defined(OPENSSL_X86_64)
78
+ #define BSAES
79
+ static char bsaes_capable(void) {
80
+ return vpaes_capable();
81
+ }
82
+ #endif
83
+
84
+ #elif !defined(OPENSSL_NO_ASM) && \
85
+ (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
86
+
87
+ #if defined(OPENSSL_ARM) && __ARM_MAX_ARCH__ >= 7
88
+ #define BSAES
89
+ static char bsaes_capable(void) {
90
+ return CRYPTO_is_NEON_capable();
91
+ }
92
+ #endif
93
+
94
+ #define HWAES
95
+ static int hwaes_capable(void) {
96
+ return CRYPTO_is_ARMv8_AES_capable();
97
+ }
98
+
99
+ int aes_v8_set_encrypt_key(const uint8_t *user_key, const int bits,
100
+ AES_KEY *key);
101
+ void aes_v8_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
102
+ void aes_v8_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t len,
103
+ const AES_KEY *key, const uint8_t ivec[16]);
104
+
105
+ #endif /* OPENSSL_ARM */
106
+
107
+ #if defined(BSAES)
108
+ /* On platforms where BSAES gets defined (just above), then these functions are
109
+ * provided by asm. */
110
+ void bsaes_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t len,
111
+ const AES_KEY *key, const uint8_t ivec[16]);
112
+ #else
113
+ static char bsaes_capable(void) {
114
+ return 0;
115
+ }
116
+
117
+ /* On other platforms, bsaes_capable() will always return false and so the
118
+ * following will never be called. */
119
+ void bsaes_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t len,
120
+ const AES_KEY *key, const uint8_t ivec[16]) {
121
+ abort();
122
+ }
123
+ #endif
124
+
125
+ #if defined(VPAES)
126
+ /* On platforms where VPAES gets defined (just above), then these functions are
127
+ * provided by asm. */
128
+ int vpaes_set_encrypt_key(const uint8_t *userKey, int bits, AES_KEY *key);
129
+
130
+ void vpaes_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
131
+ #else
132
+ static char vpaes_capable(void) {
133
+ return 0;
134
+ }
135
+
136
+ /* On other platforms, vpaes_capable() will always return false and so the
137
+ * following will never be called. */
138
+ static int vpaes_set_encrypt_key(const uint8_t *userKey, int bits,
139
+ AES_KEY *key) {
140
+ abort();
141
+ }
142
+ static void vpaes_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
143
+ abort();
144
+ }
145
+ #endif
146
+
147
+ #if !defined(HWAES)
148
+ /* If HWAES isn't defined then we provide dummy functions for each of the hwaes
149
+ * functions. */
150
+ static int hwaes_capable(void) {
151
+ return 0;
152
+ }
153
+
154
+ static int aes_v8_set_encrypt_key(const uint8_t *user_key, int bits,
155
+ AES_KEY *key) {
156
+ abort();
157
+ }
158
+
159
+ static void aes_v8_encrypt(const uint8_t *in, uint8_t *out,
160
+ const AES_KEY *key) {
161
+ abort();
162
+ }
163
+
164
+ static void aes_v8_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out,
165
+ size_t len, const AES_KEY *key,
166
+ const uint8_t ivec[16]) {
167
+ abort();
168
+ }
169
+ #endif
170
+
171
+ #if !defined(OPENSSL_NO_ASM) && \
172
+ (defined(OPENSSL_X86_64) || defined(OPENSSL_X86))
173
+ int aesni_set_encrypt_key(const uint8_t *userKey, int bits, AES_KEY *key);
174
+
175
+ void aesni_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
176
+
177
+ void aesni_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t blocks,
178
+ const void *key, const uint8_t *ivec);
179
+
180
+ #else
181
+
182
+ /* On other platforms, aesni_capable() will always return false and so the
183
+ * following will never be called. */
184
+ static void aesni_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
185
+ abort();
186
+ }
187
+ static int aesni_set_encrypt_key(const uint8_t *userKey, int bits,
188
+ AES_KEY *key) {
189
+ abort();
190
+ }
191
+ static void aesni_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out,
192
+ size_t blocks, const void *key,
193
+ const uint8_t *ivec) {
194
+ abort();
195
+ }
196
+
197
+ #endif
198
+
199
+ static char aesni_capable(void);
200
+
201
+ static ctr128_f aes_ctr_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx,
202
+ block128_f *out_block, const uint8_t *key,
203
+ size_t key_len)
204
+ OPENSSL_SUPPRESS_UNREACHABLE_CODE_WARNINGS {
205
+ #if !defined(OPENSSL_NO_ASM)
206
+ if (aesni_capable()) {
207
+ aesni_set_encrypt_key(key, key_len * 8, aes_key);
208
+ if (gcm_ctx != NULL) {
209
+ CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aesni_encrypt);
210
+ }
211
+ if (out_block) {
212
+ *out_block = (block128_f) aesni_encrypt;
213
+ }
214
+ return (ctr128_f)aesni_ctr32_encrypt_blocks;
215
+ }
216
+
217
+ if (hwaes_capable()) {
218
+ aes_v8_set_encrypt_key(key, key_len * 8, aes_key);
219
+ if (gcm_ctx != NULL) {
220
+ CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aes_v8_encrypt);
221
+ }
222
+ if (out_block) {
223
+ *out_block = (block128_f) aes_v8_encrypt;
224
+ }
225
+ return (ctr128_f)aes_v8_ctr32_encrypt_blocks;
226
+ }
227
+
228
+ if (bsaes_capable()) {
229
+ AES_set_encrypt_key(key, key_len * 8, aes_key);
230
+ if (gcm_ctx != NULL) {
231
+ CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
232
+ }
233
+ if (out_block) {
234
+ *out_block = (block128_f) AES_encrypt;
235
+ }
236
+ return (ctr128_f)bsaes_ctr32_encrypt_blocks;
237
+ }
238
+
239
+ if (vpaes_capable()) {
240
+ vpaes_set_encrypt_key(key, key_len * 8, aes_key);
241
+ if (out_block) {
242
+ *out_block = (block128_f) vpaes_encrypt;
243
+ }
244
+ if (gcm_ctx != NULL) {
245
+ CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)vpaes_encrypt);
246
+ }
247
+ return NULL;
248
+ }
249
+ #endif
250
+
251
+ AES_set_encrypt_key(key, key_len * 8, aes_key);
252
+ if (gcm_ctx != NULL) {
253
+ CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
254
+ }
255
+ if (out_block) {
256
+ *out_block = (block128_f) AES_encrypt;
257
+ }
258
+ return NULL;
259
+ }
260
+
261
+ static char aesni_capable(void) {
262
+ return (OPENSSL_ia32cap_P[1] & (1 << (57 - 32))) != 0;
263
+ }
264
+
265
+
266
+ struct aead_aes_gcm_ctx {
267
+ union {
268
+ double align;
269
+ AES_KEY ks;
270
+ } ks;
271
+ GCM128_CONTEXT gcm;
272
+ ctr128_f ctr;
273
+ };
274
+
275
+ int evp_aead_aes_gcm_init(void *ctx_buf, size_t ctx_buf_len, const uint8_t *key,
276
+ size_t key_len) {
277
+ aead_assert_init_preconditions(alignof(struct aead_aes_gcm_ctx),
278
+ sizeof(struct aead_aes_gcm_ctx), ctx_buf,
279
+ ctx_buf_len, key);
280
+
281
+ struct aead_aes_gcm_ctx *gcm_ctx = ctx_buf;
282
+ gcm_ctx->ctr =
283
+ aes_ctr_set_key(&gcm_ctx->ks.ks, &gcm_ctx->gcm, NULL, key, key_len);
284
+ return 1;
285
+ }
286
+
287
+ int evp_aead_aes_gcm_seal(const void *ctx_buf, uint8_t *out, size_t *out_len,
288
+ size_t max_out_len, const uint8_t *nonce,
289
+ const uint8_t *in, size_t in_len, const uint8_t *ad,
290
+ size_t ad_len) {
291
+ aead_assert_open_seal_preconditions(alignof(struct aead_aes_gcm_ctx), ctx_buf,
292
+ out, out_len, nonce, in, in_len, ad,
293
+ ad_len);
294
+
295
+ const struct aead_aes_gcm_ctx *gcm_ctx = ctx_buf;
296
+
297
+ if (!aead_seal_out_max_out_in_tag_len(out_len, max_out_len, in_len,
298
+ EVP_AEAD_AES_GCM_TAG_LEN)) {
299
+ /* |aead_seal_out_max_out_in_tag_len| already called |OPENSSL_PUT_ERROR|. */
300
+ return 0;
301
+ }
302
+
303
+ GCM128_CONTEXT gcm;
304
+
305
+ const AES_KEY *key = &gcm_ctx->ks.ks;
306
+
307
+ memcpy(&gcm, &gcm_ctx->gcm, sizeof(gcm));
308
+ CRYPTO_gcm128_set_96_bit_iv(&gcm, key, nonce);
309
+
310
+ if (ad_len > 0 && !CRYPTO_gcm128_aad(&gcm, ad, ad_len)) {
311
+ return 0;
312
+ }
313
+
314
+ if (gcm_ctx->ctr) {
315
+ if (!CRYPTO_gcm128_encrypt_ctr32(&gcm, key, in, out, in_len, gcm_ctx->ctr)) {
316
+ return 0;
317
+ }
318
+ } else {
319
+ if (!CRYPTO_gcm128_encrypt(&gcm, key, in, out, in_len)) {
320
+ return 0;
321
+ }
322
+ }
323
+
324
+ CRYPTO_gcm128_tag(&gcm, out + in_len, EVP_AEAD_AES_GCM_TAG_LEN);
325
+ return 1;
326
+ }
327
+
328
+ int evp_aead_aes_gcm_open(const void *ctx_buf, uint8_t *out, size_t *out_len,
329
+ size_t max_out_len, const uint8_t *nonce,
330
+ const uint8_t *in, size_t in_len, const uint8_t *ad,
331
+ size_t ad_len) {
332
+ aead_assert_open_seal_preconditions(alignof(struct aead_aes_gcm_ctx), ctx_buf,
333
+ out, out_len, nonce, in, in_len, ad,
334
+ ad_len);
335
+
336
+ const struct aead_aes_gcm_ctx *gcm_ctx = ctx_buf;
337
+
338
+ if (!aead_open_out_max_out_in_tag_len(out_len, max_out_len, in_len,
339
+ EVP_AEAD_AES_GCM_TAG_LEN)) {
340
+ /* |aead_open_out_max_out_in_tag_len| already called |OPENSSL_PUT_ERROR|. */
341
+ return 0;
342
+ }
343
+
344
+ uint8_t tag[EVP_AEAD_AES_GCM_TAG_LEN];
345
+ size_t plaintext_len;
346
+ GCM128_CONTEXT gcm;
347
+
348
+ plaintext_len = in_len - EVP_AEAD_AES_GCM_TAG_LEN;
349
+
350
+ const AES_KEY *key = &gcm_ctx->ks.ks;
351
+
352
+ memcpy(&gcm, &gcm_ctx->gcm, sizeof(gcm));
353
+ CRYPTO_gcm128_set_96_bit_iv(&gcm, key, nonce);
354
+
355
+ if (!CRYPTO_gcm128_aad(&gcm, ad, ad_len)) {
356
+ return 0;
357
+ }
358
+
359
+ if (gcm_ctx->ctr) {
360
+ if (!CRYPTO_gcm128_decrypt_ctr32(&gcm, key, in, out,
361
+ in_len - EVP_AEAD_AES_GCM_TAG_LEN,
362
+ gcm_ctx->ctr)) {
363
+ return 0;
364
+ }
365
+ } else {
366
+ if (!CRYPTO_gcm128_decrypt(&gcm, key, in, out,
367
+ in_len - EVP_AEAD_AES_GCM_TAG_LEN)) {
368
+ return 0;
369
+ }
370
+ }
371
+
372
+ CRYPTO_gcm128_tag(&gcm, tag, EVP_AEAD_AES_GCM_TAG_LEN);
373
+ if (CRYPTO_memcmp(tag, in + plaintext_len, EVP_AEAD_AES_GCM_TAG_LEN) != 0) {
374
+ OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
375
+ return 0;
376
+ }
377
+
378
+ return 1;
379
+ }
380
+
381
+
382
+ int EVP_has_aes_hardware(void) {
383
+ #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
384
+ return aesni_capable() && crypto_gcm_clmul_enabled();
385
+ #elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
386
+ return hwaes_capable() && CRYPTO_is_ARMv8_PMULL_capable();
387
+ #else
388
+ return 0;
389
+ #endif
390
+ }