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,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>{A8616FF5-8273-4C80-8BF0-1785D8E1DF74}</ProjectGuid>
5
+ <TargetName>gcm_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\modes\</OutDir>
12
+ </PropertyGroup>
13
+ <ItemGroup>
14
+ <ClCompile Include="gcm_test.c" />
15
+ </ItemGroup>
16
+ <ItemGroup>
17
+ <ProjectReference Include="..\libring.Windows.vcxproj">
18
+ <Project>{f4c0a1b6-5e09-41c8-8242-3e1f6762fb18}</Project>
19
+ </ProjectReference>
20
+ <ProjectReference Include="..\test\test.Windows.vcxproj">
21
+ <Project>{1dace503-6498-492d-b1ff-f9ee18624443}</Project>
22
+ </ProjectReference>
23
+ </ItemGroup>
24
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
25
+ </Project>
@@ -0,0 +1,348 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 2008 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 <stdio.h>
50
+ #include <string.h>
51
+
52
+ #include <openssl/aes.h>
53
+ #include <openssl/crypto.h>
54
+ #include <openssl/mem.h>
55
+
56
+ #include "internal.h"
57
+ #include "../test/test_util.h"
58
+
59
+
60
+ struct test_case {
61
+ const char *key;
62
+ const char *plaintext;
63
+ const char *additional_data;
64
+ const char *nonce;
65
+ const char *ciphertext;
66
+ const char *tag;
67
+ };
68
+
69
+ static const struct test_case test_cases[] = {
70
+ {
71
+ "00000000000000000000000000000000",
72
+ NULL,
73
+ NULL,
74
+ "000000000000000000000000",
75
+ NULL,
76
+ "58e2fccefa7e3061367f1d57a4e7455a",
77
+ },
78
+ {
79
+ "00000000000000000000000000000000",
80
+ "00000000000000000000000000000000",
81
+ NULL,
82
+ "000000000000000000000000",
83
+ "0388dace60b6a392f328c2b971b2fe78",
84
+ "ab6e47d42cec13bdf53a67b21257bddf",
85
+ },
86
+ {
87
+ "feffe9928665731c6d6a8f9467308308",
88
+ "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
89
+ NULL,
90
+ "cafebabefacedbaddecaf888",
91
+ "42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091473f5985",
92
+ "4d5c2af327cd64a62cf35abd2ba6fab4",
93
+ },
94
+ {
95
+ "feffe9928665731c6d6a8f9467308308",
96
+ "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
97
+ "feedfacedeadbeeffeedfacedeadbeefabaddad2",
98
+ "cafebabefacedbaddecaf888",
99
+ "42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091",
100
+ "5bc94fbc3221a5db94fae95ae7121a47",
101
+ },
102
+ {
103
+ "000000000000000000000000000000000000000000000000",
104
+ NULL,
105
+ NULL,
106
+ "000000000000000000000000",
107
+ NULL,
108
+ "cd33b28ac773f74ba00ed1f312572435",
109
+ },
110
+ {
111
+ "000000000000000000000000000000000000000000000000",
112
+ "00000000000000000000000000000000",
113
+ NULL,
114
+ "000000000000000000000000",
115
+ "98e7247c07f0fe411c267e4384b0f600",
116
+ "2ff58d80033927ab8ef4d4587514f0fb",
117
+ },
118
+ {
119
+ "feffe9928665731c6d6a8f9467308308feffe9928665731c",
120
+ "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
121
+ NULL,
122
+ "cafebabefacedbaddecaf888",
123
+ "3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c144c525ac619d18c84a3f4718e2448b2fe324d9ccda2710acade256",
124
+ "9924a7c8587336bfb118024db8674a14",
125
+ },
126
+ {
127
+ "feffe9928665731c6d6a8f9467308308feffe9928665731c",
128
+ "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
129
+ "feedfacedeadbeeffeedfacedeadbeefabaddad2",
130
+ "cafebabefacedbaddecaf888",
131
+ "3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c144c525ac619d18c84a3f4718e2448b2fe324d9ccda2710",
132
+ "2519498e80f1478f37ba55bd6d27618c",
133
+ },
134
+ {
135
+ "0000000000000000000000000000000000000000000000000000000000000000",
136
+ NULL,
137
+ NULL,
138
+ "000000000000000000000000",
139
+ NULL,
140
+ "530f8afbc74536b9a963b4f1c4cb738b",
141
+ },
142
+ {
143
+ "0000000000000000000000000000000000000000000000000000000000000000",
144
+ "00000000000000000000000000000000",
145
+ NULL,
146
+ "000000000000000000000000",
147
+ "cea7403d4d606b6e074ec5d3baf39d18",
148
+ "d0d1c8a799996bf0265b98b5d48ab919",
149
+ },
150
+ {
151
+ "feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308",
152
+ "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
153
+ NULL,
154
+ "cafebabefacedbaddecaf888",
155
+ "522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662898015ad",
156
+ "b094dac5d93471bdec1a502270e3cc6c",
157
+ },
158
+ {
159
+ "feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308",
160
+ "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
161
+ "feedfacedeadbeeffeedfacedeadbeefabaddad2",
162
+ "cafebabefacedbaddecaf888",
163
+ "522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662",
164
+ "76fc6ece0f4e1768cddf8853bb2d551b",
165
+ },
166
+ {
167
+ "00000000000000000000000000000000",
168
+ NULL,
169
+ "d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e48590dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662898015ad",
170
+ "000000000000000000000000",
171
+ NULL,
172
+ "5fea793a2d6f974d37e68e0cb8ff9492",
173
+ },
174
+ };
175
+
176
+ static int from_hex(uint8_t *out, char in) {
177
+ if (in >= '0' && in <= '9') {
178
+ *out = in - '0';
179
+ return 1;
180
+ }
181
+ if (in >= 'a' && in <= 'f') {
182
+ *out = in - 'a' + 10;
183
+ return 1;
184
+ }
185
+ if (in >= 'A' && in <= 'F') {
186
+ *out = in - 'A' + 10;
187
+ return 1;
188
+ }
189
+
190
+ return 0;
191
+ }
192
+
193
+ static int decode_hex(uint8_t **out, size_t *out_len, const char *in,
194
+ unsigned test_num, const char *description) {
195
+ uint8_t *buf = NULL;
196
+ size_t i;
197
+
198
+ if (in == NULL) {
199
+ *out = NULL;
200
+ *out_len = 0;
201
+ return 1;
202
+ }
203
+
204
+ size_t len = strlen(in);
205
+ if (len & 1) {
206
+ fprintf(stderr, "%u: Odd-length %s input.\n", test_num, description);
207
+ goto err;
208
+ }
209
+
210
+ buf = OPENSSL_malloc(len / 2);
211
+ if (buf == NULL) {
212
+ fprintf(stderr, "%u: malloc failure.\n", test_num);
213
+ goto err;
214
+ }
215
+
216
+ for (i = 0; i < len; i += 2) {
217
+ uint8_t v, v2;
218
+ if (!from_hex(&v, in[i]) ||
219
+ !from_hex(&v2, in[i+1])) {
220
+ fprintf(stderr,
221
+ "%u: invalid hex digit in %s around offset "
222
+ "%" OPENSSL_PR_SIZE_T ".\n", test_num, description, i);
223
+ goto err;
224
+ }
225
+ buf[i/2] = (v << 4) | v2;
226
+ }
227
+
228
+ *out = buf;
229
+ *out_len = len/2;
230
+ return 1;
231
+
232
+ err:
233
+ OPENSSL_free(buf);
234
+ return 0;
235
+ }
236
+
237
+ static int run_test_case(unsigned test_num, const struct test_case *test) {
238
+ size_t key_len, plaintext_len, additional_data_len, nonce_len, ciphertext_len,
239
+ tag_len;
240
+ uint8_t *key = NULL, *plaintext = NULL, *additional_data = NULL,
241
+ *nonce = NULL, *ciphertext = NULL, *tag = NULL, *out = NULL;
242
+ int ret = 0;
243
+ AES_KEY aes_key;
244
+ GCM128_CONTEXT ctx;
245
+
246
+ if (!decode_hex(&key, &key_len, test->key, test_num, "key") ||
247
+ !decode_hex(&plaintext, &plaintext_len, test->plaintext, test_num,
248
+ "plaintext") ||
249
+ !decode_hex(&additional_data, &additional_data_len, test->additional_data,
250
+ test_num, "additional_data") ||
251
+ !decode_hex(&nonce, &nonce_len, test->nonce, test_num, "nonce") ||
252
+ !decode_hex(&ciphertext, &ciphertext_len, test->ciphertext, test_num,
253
+ "ciphertext") ||
254
+ !decode_hex(&tag, &tag_len, test->tag, test_num, "tag")) {
255
+ goto out;
256
+ }
257
+
258
+ if (plaintext_len != ciphertext_len) {
259
+ fprintf(stderr, "%u: plaintext and ciphertext have differing lengths.\n",
260
+ test_num);
261
+ goto out;
262
+ }
263
+
264
+ if (nonce_len != 12) {
265
+ fprintf(stderr, "%u: bad nonce length.\n", test_num);
266
+ goto out;
267
+ }
268
+
269
+ if (key_len != 16 && key_len != 24 && key_len != 32) {
270
+ fprintf(stderr, "%u: bad key length.\n", test_num);
271
+ goto out;
272
+ }
273
+
274
+ if (tag_len != 16) {
275
+ fprintf(stderr, "%u: bad tag length.\n", test_num);
276
+ goto out;
277
+ }
278
+
279
+ out = OPENSSL_malloc(plaintext_len);
280
+ if (out == NULL) {
281
+ goto out;
282
+ }
283
+ if (AES_set_encrypt_key(key, key_len*8, &aes_key)) {
284
+ fprintf(stderr, "%u: AES_set_encrypt_key failed.\n", test_num);
285
+ goto out;
286
+ }
287
+
288
+ CRYPTO_gcm128_init(&ctx, &aes_key, (block128_f) AES_encrypt);
289
+ CRYPTO_gcm128_set_96_bit_iv(&ctx, &aes_key, nonce);
290
+ memset(out, 0, plaintext_len);
291
+ if (additional_data) {
292
+ CRYPTO_gcm128_aad(&ctx, additional_data, additional_data_len);
293
+ }
294
+ if (plaintext) {
295
+ CRYPTO_gcm128_encrypt(&ctx, &aes_key, plaintext, out, plaintext_len);
296
+ }
297
+ if (!CRYPTO_gcm128_finish(&ctx, tag, tag_len) ||
298
+ (ciphertext && memcmp(out, ciphertext, plaintext_len) != 0)) {
299
+ fprintf(stderr, "%u: encrypt failed.\n", test_num);
300
+ hexdump(stderr, "got :", out, plaintext_len);
301
+ hexdump(stderr, "want:", ciphertext, plaintext_len);
302
+ goto out;
303
+ }
304
+
305
+ CRYPTO_gcm128_set_96_bit_iv(&ctx, &aes_key, nonce);
306
+ memset(out, 0, plaintext_len);
307
+ if (additional_data) {
308
+ CRYPTO_gcm128_aad(&ctx, additional_data, additional_data_len);
309
+ }
310
+ if (ciphertext) {
311
+ CRYPTO_gcm128_decrypt(&ctx, &aes_key, ciphertext, out, plaintext_len);
312
+ }
313
+ if (!CRYPTO_gcm128_finish(&ctx, tag, tag_len)) {
314
+ fprintf(stderr, "%u: decrypt failed.\n", test_num);
315
+ goto out;
316
+ }
317
+ if (plaintext && memcmp(out, plaintext, plaintext_len)) {
318
+ fprintf(stderr, "%u: plaintext doesn't match.\n", test_num);
319
+ goto out;
320
+ }
321
+
322
+ ret = 1;
323
+
324
+ out:
325
+ OPENSSL_free(key);
326
+ OPENSSL_free(plaintext);
327
+ OPENSSL_free(additional_data);
328
+ OPENSSL_free(nonce);
329
+ OPENSSL_free(ciphertext);
330
+ OPENSSL_free(tag);
331
+ OPENSSL_free(out);
332
+ return ret;
333
+ }
334
+
335
+ int main(void) {
336
+ int ret = 0;
337
+ unsigned i;
338
+
339
+ CRYPTO_library_init();
340
+
341
+ for (i = 0; i < sizeof(test_cases) / sizeof(struct test_case); i++) {
342
+ if (!run_test_case(i, &test_cases[i])) {
343
+ ret = 1;
344
+ }
345
+ }
346
+
347
+ return ret;
348
+ }
@@ -0,0 +1,299 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 2008 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
+ #ifndef OPENSSL_HEADER_MODES_INTERNAL_H
50
+ #define OPENSSL_HEADER_MODES_INTERNAL_H
51
+
52
+ #include <openssl/base.h>
53
+
54
+ #if defined(__cplusplus)
55
+ extern "C" {
56
+ #endif
57
+
58
+
59
+ #define asm __asm__
60
+
61
+ #define STRICT_ALIGNMENT 1
62
+ #if defined(OPENSSL_X86_64) || defined(OPENSSL_X86) || defined(OPENSSL_AARCH64)
63
+ #undef STRICT_ALIGNMENT
64
+ #define STRICT_ALIGNMENT 0
65
+ #endif
66
+
67
+ #if !defined(PEDANTIC) && !defined(OPENSSL_NO_ASM)
68
+ #if defined(__GNUC__) && __GNUC__ >= 2
69
+ #if defined(OPENSSL_X86_64)
70
+ #define BSWAP8(x) \
71
+ ({ \
72
+ uint64_t ret = (x); \
73
+ asm("bswapq %0" : "+r"(ret)); \
74
+ ret; \
75
+ })
76
+ #define BSWAP4(x) \
77
+ ({ \
78
+ uint32_t ret = (x); \
79
+ asm("bswapl %0" : "+r"(ret)); \
80
+ ret; \
81
+ })
82
+ #elif defined(OPENSSL_X86)
83
+ #define BSWAP8(x) \
84
+ ({ \
85
+ uint32_t lo = (uint64_t)(x) >> 32, hi = (x); \
86
+ asm("bswapl %0; bswapl %1" : "+r"(hi), "+r"(lo)); \
87
+ (uint64_t) hi << 32 | lo; \
88
+ })
89
+ #define BSWAP4(x) \
90
+ ({ \
91
+ uint32_t ret = (x); \
92
+ asm("bswapl %0" : "+r"(ret)); \
93
+ ret; \
94
+ })
95
+ #elif defined(OPENSSL_AARCH64)
96
+ #define BSWAP8(x) \
97
+ ({ \
98
+ uint64_t ret; \
99
+ asm("rev %0,%1" : "=r"(ret) : "r"(x)); \
100
+ ret; \
101
+ })
102
+ #define BSWAP4(x) \
103
+ ({ \
104
+ uint32_t ret; \
105
+ asm("rev %w0,%w1" : "=r"(ret) : "r"(x)); \
106
+ ret; \
107
+ })
108
+ #elif defined(OPENSSL_ARM) && !defined(STRICT_ALIGNMENT)
109
+ #define BSWAP8(x) \
110
+ ({ \
111
+ uint32_t lo = (uint64_t)(x) >> 32, hi = (x); \
112
+ asm("rev %0,%0; rev %1,%1" : "+r"(hi), "+r"(lo)); \
113
+ (uint64_t) hi << 32 | lo; \
114
+ })
115
+ #define BSWAP4(x) \
116
+ ({ \
117
+ uint32_t ret; \
118
+ asm("rev %0,%1" : "=r"(ret) : "r"((uint32_t)(x))); \
119
+ ret; \
120
+ })
121
+ #endif
122
+ #elif defined(_MSC_VER)
123
+ #if _MSC_VER >= 1300
124
+ #pragma warning(push, 3)
125
+ #include <intrin.h>
126
+ #pragma warning(pop)
127
+ #pragma intrinsic(_byteswap_uint64, _byteswap_ulong)
128
+ #define BSWAP8(x) _byteswap_uint64((uint64_t)(x))
129
+ #define BSWAP4(x) _byteswap_ulong((uint32_t)(x))
130
+ #elif defined(OPENSSL_X86)
131
+ __inline uint32_t _bswap4(uint32_t val) {
132
+ _asm mov eax, val
133
+ _asm bswap eax
134
+ }
135
+ #define BSWAP4(x) _bswap4(x)
136
+ #endif
137
+ #endif
138
+ #endif
139
+
140
+ #if defined(BSWAP4) && !defined(STRICT_ALIGNMENT)
141
+ #define GETU32(p) BSWAP4(*(const uint32_t *)(p))
142
+ #define PUTU32(p, v) *(uint32_t *)(p) = BSWAP4(v)
143
+ #else
144
+ #define GETU32(p) \
145
+ ((uint32_t)(p)[0] << 24 | (uint32_t)(p)[1] << 16 | (uint32_t)(p)[2] << 8 | (uint32_t)(p)[3])
146
+ #define PUTU32(p, v) \
147
+ ((p)[0] = (uint8_t)((v) >> 24), (p)[1] = (uint8_t)((v) >> 16), \
148
+ (p)[2] = (uint8_t)((v) >> 8), (p)[3] = (uint8_t)(v))
149
+ #endif
150
+
151
+
152
+ /* block128_f is the type of a 128-bit, block cipher. */
153
+ typedef void (*block128_f)(const uint8_t in[16], uint8_t out[16],
154
+ const void *key);
155
+
156
+ /* GCM definitions */
157
+ typedef struct { uint64_t hi,lo; } u128;
158
+
159
+ /* This differs from OpenSSL's |gcm128_context| in that it does not have the
160
+ * |key| pointer, in order to make it |memcpy|-friendly. See openssl/modes.h
161
+ * for more info. */
162
+ struct gcm128_context {
163
+ /* Following 6 names follow names in GCM specification */
164
+ union {
165
+ uint64_t u[2];
166
+ uint32_t d[4];
167
+ uint8_t c[16];
168
+ size_t t[16 / sizeof(size_t)];
169
+ } Yi, EKi, EK0, len, Xi, H;
170
+
171
+ /* Relative position of Xi, H and pre-computed Htable is used in some
172
+ * assembler modules, i.e. don't change the order! */
173
+ u128 Htable[16];
174
+ void (*gmult)(uint64_t Xi[2], const u128 Htable[16]);
175
+ void (*ghash)(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp,
176
+ size_t len);
177
+
178
+ unsigned int mres, ares;
179
+ block128_f block;
180
+ };
181
+
182
+ #if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
183
+ /* crypto_gcm_clmul_enabled returns one if the CLMUL implementation of GCM is
184
+ * used. */
185
+ int crypto_gcm_clmul_enabled(void);
186
+ #endif
187
+
188
+
189
+ /* CTR. */
190
+
191
+ /* ctr128_f is the type of a function that performs CTR-mode encryption. */
192
+ typedef void (*ctr128_f)(const uint8_t *in, uint8_t *out, size_t blocks,
193
+ const void *key, const uint8_t ivec[16]);
194
+
195
+ /* CRYPTO_ctr128_encrypt encrypts (or decrypts, it's the same in CTR mode)
196
+ * |len| bytes from |in| to |out| using |block| in counter mode. There's no
197
+ * requirement that |len| be a multiple of any value and any partial blocks are
198
+ * stored in |ecount_buf| and |*num|, which must be zeroed before the initial
199
+ * call. The counter is a 128-bit, big-endian value in |ivec| and is
200
+ * incremented by this function. */
201
+ void CRYPTO_ctr128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
202
+ const void *key, uint8_t ivec[16],
203
+ uint8_t ecount_buf[16], unsigned int *num,
204
+ block128_f block);
205
+
206
+ /* CRYPTO_ctr128_encrypt_ctr32 acts like |CRYPTO_ctr128_encrypt| but takes
207
+ * |ctr|, a function that performs CTR mode but only deals with the lower 32
208
+ * bits of the counter. This is useful when |ctr| can be an optimised
209
+ * function. */
210
+ void CRYPTO_ctr128_encrypt_ctr32(const uint8_t *in, uint8_t *out, size_t len,
211
+ const void *key, uint8_t ivec[16],
212
+ uint8_t ecount_buf[16], unsigned int *num,
213
+ ctr128_f ctr);
214
+
215
+
216
+ /* GCM.
217
+ *
218
+ * This API differs from the OpenSSL API slightly. The |GCM128_CONTEXT| does
219
+ * not have a |key| pointer that points to the key as OpenSSL's version does.
220
+ * Instead, every function takes a |key| parameter. This way |GCM128_CONTEXT|
221
+ * can be safely copied. */
222
+
223
+ typedef struct gcm128_context GCM128_CONTEXT;
224
+
225
+ /* CRYPTO_gcm128_new allocates a fresh |GCM128_CONTEXT| and calls
226
+ * |CRYPTO_gcm128_init|. It returns the new context, or NULL on error. */
227
+ OPENSSL_EXPORT GCM128_CONTEXT *CRYPTO_gcm128_new(const void *key,
228
+ block128_f block);
229
+
230
+ /* CRYPTO_gcm128_init initialises |ctx| to use |block| (typically AES) with
231
+ * the given key. */
232
+ OPENSSL_EXPORT void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, const void *key,
233
+ block128_f block);
234
+
235
+ /* CRYPTO_gcm128_set_96_bit_iv sets the IV (nonce) for |ctx|. The |key| must be
236
+ * the same key that was passed to |CRYPTO_gcm128_init|. */
237
+ OPENSSL_EXPORT void CRYPTO_gcm128_set_96_bit_iv(GCM128_CONTEXT *ctx,
238
+ const void *key,
239
+ const uint8_t *iv);
240
+
241
+ /* CRYPTO_gcm128_aad sets the authenticated data for an instance of GCM.
242
+ * This must be called before and data is encrypted. It returns one on success
243
+ * and zero otherwise. */
244
+ OPENSSL_EXPORT int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const uint8_t *aad,
245
+ size_t len);
246
+
247
+ /* CRYPTO_gcm128_encrypt encrypts |len| bytes from |in| to |out|. The |key|
248
+ * must be the same key that was passed to |CRYPTO_gcm128_init|. It returns one
249
+ * on success and zero otherwise. */
250
+ OPENSSL_EXPORT int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx, const void *key,
251
+ const uint8_t *in, uint8_t *out,
252
+ size_t len);
253
+
254
+ /* CRYPTO_gcm128_decrypt decrypts |len| bytes from |in| to |out|. The |key|
255
+ * must be the same key that was passed to |CRYPTO_gcm128_init|. It returns one
256
+ * on success and zero otherwise. */
257
+ OPENSSL_EXPORT int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx, const void *key,
258
+ const uint8_t *in, uint8_t *out,
259
+ size_t len);
260
+
261
+ /* CRYPTO_gcm128_encrypt_ctr32 encrypts |len| bytes from |in| to |out| using
262
+ * a CTR function that only handles the bottom 32 bits of the nonce, like
263
+ * |CRYPTO_ctr128_encrypt_ctr32|. The |key| must be the same key that was
264
+ * passed to |CRYPTO_gcm128_init|. It returns one on success and zero
265
+ * otherwise. */
266
+ OPENSSL_EXPORT int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
267
+ const void *key,
268
+ const uint8_t *in, uint8_t *out,
269
+ size_t len, ctr128_f stream);
270
+
271
+ /* CRYPTO_gcm128_decrypt_ctr32 decrypts |len| bytes from |in| to |out| using
272
+ * a CTR function that only handles the bottom 32 bits of the nonce, like
273
+ * |CRYPTO_ctr128_encrypt_ctr32|. The |key| must be the same key that was
274
+ * passed to |CRYPTO_gcm128_init|. It returns one on success and zero
275
+ * otherwise. */
276
+ OPENSSL_EXPORT int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
277
+ const void *key,
278
+ const uint8_t *in, uint8_t *out,
279
+ size_t len, ctr128_f stream);
280
+
281
+ /* CRYPTO_gcm128_finish calculates the authenticator and compares it against
282
+ * |len| bytes of |tag|. It returns one on success and zero otherwise. */
283
+ OPENSSL_EXPORT int CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx, const uint8_t *tag,
284
+ size_t len);
285
+
286
+ /* CRYPTO_gcm128_tag calculates the authenticator and copies it into |tag|.
287
+ * The minimum of |len| and 16 bytes are copied into |tag|. */
288
+ OPENSSL_EXPORT void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, uint8_t *tag,
289
+ size_t len);
290
+
291
+ /* CRYPTO_gcm128_release clears and frees |ctx|. */
292
+ OPENSSL_EXPORT void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
293
+
294
+
295
+ #if defined(__cplusplus)
296
+ } /* extern C */
297
+ #endif
298
+
299
+ #endif /* OPENSSL_HEADER_MODES_INTERNAL_H */