rbnacl-libsodium 1.0.13 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +5 -0
  3. data/lib/rbnacl/libsodium.rb +1 -0
  4. data/lib/rbnacl/libsodium/version.rb +1 -1
  5. data/vendor/libsodium/AUTHORS +2 -2
  6. data/vendor/libsodium/ChangeLog +64 -0
  7. data/vendor/libsodium/Makefile.am +1 -0
  8. data/vendor/libsodium/README.markdown +1 -3
  9. data/vendor/libsodium/THANKS +13 -3
  10. data/vendor/libsodium/builds/Makefile.am +65 -0
  11. data/vendor/libsodium/builds/msvc/resource.rc +2 -2
  12. data/vendor/libsodium/builds/msvc/version.h +3 -3
  13. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +168 -173
  14. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +382 -394
  15. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +168 -173
  16. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +382 -394
  17. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +168 -173
  18. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +382 -394
  19. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +168 -173
  20. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +382 -394
  21. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj +168 -173
  22. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters +382 -394
  23. data/vendor/libsodium/configure.ac +59 -10
  24. data/vendor/libsodium/contrib/Findsodium.cmake +2 -0
  25. data/vendor/libsodium/dist-build/emscripten-symbols.def +72 -32
  26. data/vendor/libsodium/dist-build/emscripten.sh +33 -6
  27. data/vendor/libsodium/dist-build/generate-emscripten-symbols.sh +52 -38
  28. data/vendor/libsodium/dist-build/ios.sh +2 -2
  29. data/vendor/libsodium/libsodium.vcxproj +168 -173
  30. data/vendor/libsodium/libsodium.vcxproj.filters +220 -235
  31. data/vendor/libsodium/m4/ax_check_catchable_abrt.m4 +57 -0
  32. data/vendor/libsodium/m4/ax_check_gnu_make.m4 +2 -2
  33. data/vendor/libsodium/m4/ax_pthread.m4 +2 -2
  34. data/vendor/libsodium/msvc-scripts/process.bat +3 -3
  35. data/vendor/libsodium/packaging/dotnet-core/README.md +5 -5
  36. data/vendor/libsodium/packaging/dotnet-core/libsodium.props +5 -2
  37. data/vendor/libsodium/packaging/dotnet-core/prepare.py +13 -31
  38. data/vendor/libsodium/packaging/dotnet-core/recipes/linux-x64 +4 -0
  39. data/vendor/libsodium/packaging/nuget/package.config +1 -1
  40. data/vendor/libsodium/src/libsodium/Makefile.am +11 -12
  41. data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +11 -4
  42. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +17 -4
  43. data/vendor/libsodium/src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c +8 -1
  44. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box.c +6 -0
  45. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +5 -4
  46. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c +11 -4
  47. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c +6 -0
  48. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +78 -17
  49. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c +74 -64
  50. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c +2 -0
  51. data/vendor/libsodium/src/libsodium/crypto_kx/crypto_kx.c +7 -0
  52. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +1 -1
  53. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +1 -0
  54. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +17 -17
  55. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c +53 -48
  56. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.h +37 -11
  57. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +23 -179
  58. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx2.c +4 -12
  59. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx512f.c +244 -0
  60. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c +3 -12
  61. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c +4 -12
  62. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +1 -5
  63. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.h +1 -1
  64. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-avx512f.h +145 -0
  65. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +91 -14
  66. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c +35 -14
  67. data/vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c +41 -4
  68. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +31 -17
  69. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +4 -0
  70. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +5 -1
  71. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +30 -1
  72. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +8 -0
  73. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c +3 -3
  74. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox.c +6 -0
  75. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +5 -4
  76. data/vendor/libsodium/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c +11 -4
  77. data/vendor/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305.c +6 -0
  78. data/vendor/libsodium/src/libsodium/crypto_secretstream/xchacha20poly1305/secretstream_xchacha20poly1305.c +311 -0
  79. data/vendor/libsodium/src/libsodium/crypto_sign/crypto_sign.c +6 -0
  80. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ed25519_ref10.h +3 -0
  81. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +9 -2
  82. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c +1 -1
  83. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +6 -5
  84. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519.c +6 -0
  85. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c +3 -2
  86. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c +3 -2
  87. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/u0.h +1 -1
  88. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c +3 -2
  89. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c +12 -0
  90. data/vendor/libsodium/src/libsodium/crypto_stream/crypto_stream.c +6 -0
  91. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.c +7 -1
  92. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u0.h +1 -1
  93. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/stream_salsa2012.c +6 -0
  94. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/stream_salsa208.c +6 -0
  95. data/vendor/libsodium/src/libsodium/crypto_stream/xchacha20/stream_xchacha20.c +6 -0
  96. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c +6 -0
  97. data/vendor/libsodium/src/libsodium/crypto_verify/sodium/verify.c +66 -29
  98. data/vendor/libsodium/src/libsodium/include/Makefile.am +1 -1
  99. data/vendor/libsodium/src/libsodium/include/sodium.h +2 -2
  100. data/vendor/libsodium/src/libsodium/include/sodium/core.h +9 -0
  101. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +26 -0
  102. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +16 -4
  103. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h +10 -4
  104. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +4 -0
  105. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h +6 -0
  106. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +24 -15
  107. data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_salsa208.h +8 -4
  108. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +40 -18
  109. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +8 -2
  110. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2id.h +8 -2
  111. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +11 -3
  112. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +4 -0
  113. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h +6 -0
  114. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +17 -8
  115. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretstream_xchacha20poly1305.h +102 -0
  116. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign.h +4 -0
  117. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +4 -0
  118. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +1 -0
  119. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream.h +4 -0
  120. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +10 -0
  121. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa20.h +4 -0
  122. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa2012.h +4 -0
  123. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa208.h +15 -5
  124. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xchacha20.h +4 -0
  125. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xsalsa20.h +4 -0
  126. data/vendor/libsodium/src/libsodium/include/sodium/export.h +9 -0
  127. data/vendor/libsodium/src/libsodium/include/sodium/private/common.h +11 -0
  128. data/vendor/libsodium/src/libsodium/include/sodium/private/curve25519_ref10.h +2 -30
  129. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +2 -0
  130. data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +12 -9
  131. data/vendor/libsodium/src/libsodium/include/sodium/utils.h +36 -0
  132. data/vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +3 -2
  133. data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +18 -14
  134. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +11 -10
  135. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +20 -8
  136. data/vendor/libsodium/src/libsodium/sodium/codecs.c +333 -0
  137. data/vendor/libsodium/src/libsodium/sodium/core.c +36 -4
  138. data/vendor/libsodium/src/libsodium/sodium/runtime.c +18 -0
  139. data/vendor/libsodium/src/libsodium/sodium/utils.c +87 -100
  140. data/vendor/libsodium/test/constcheck.sh +19 -0
  141. data/vendor/libsodium/test/default/Makefile.am +39 -7
  142. data/vendor/libsodium/test/default/aead_aes256gcm.c +6 -0
  143. data/vendor/libsodium/test/default/aead_chacha20poly1305.c +16 -0
  144. data/vendor/libsodium/test/default/aead_xchacha20poly1305.c +25 -15
  145. data/vendor/libsodium/test/default/auth.c +13 -0
  146. data/vendor/libsodium/test/default/auth.exp +8 -0
  147. data/vendor/libsodium/test/default/box.c +3 -0
  148. data/vendor/libsodium/test/default/box2.c +2 -0
  149. data/vendor/libsodium/test/default/box_easy.c +1 -4
  150. data/vendor/libsodium/test/default/box_easy2.c +7 -3
  151. data/vendor/libsodium/test/default/chacha20.c +9 -2
  152. data/vendor/libsodium/test/default/cmptest.h +47 -1
  153. data/vendor/libsodium/test/default/codecs.c +226 -0
  154. data/vendor/libsodium/test/default/codecs.exp +28 -0
  155. data/vendor/libsodium/test/default/core3.c +42 -15
  156. data/vendor/libsodium/test/default/ed25519_convert.c +17 -0
  157. data/vendor/libsodium/test/default/kdf.c +8 -4
  158. data/vendor/libsodium/test/default/keygen.c +5 -2
  159. data/vendor/libsodium/test/default/kx.c +30 -0
  160. data/vendor/libsodium/test/default/metamorphic.c +187 -0
  161. data/vendor/libsodium/test/default/metamorphic.exp +1 -0
  162. data/vendor/libsodium/test/default/misuse.c +145 -0
  163. data/vendor/libsodium/test/default/misuse.exp +0 -0
  164. data/vendor/libsodium/test/default/onetimeauth.c +2 -0
  165. data/vendor/libsodium/test/default/{pwhash.c → pwhash_argon2i.c} +133 -106
  166. data/vendor/libsodium/test/default/{pwhash.exp → pwhash_argon2i.exp} +0 -1
  167. data/vendor/libsodium/test/default/pwhash_argon2id.c +254 -144
  168. data/vendor/libsodium/test/default/pwhash_argon2id.exp +2 -3
  169. data/vendor/libsodium/test/default/pwhash_scrypt.c +61 -18
  170. data/vendor/libsodium/test/default/pwhash_scrypt.exp +6 -0
  171. data/vendor/libsodium/test/default/randombytes.c +8 -3
  172. data/vendor/libsodium/test/default/secretbox.c +8 -0
  173. data/vendor/libsodium/test/default/secretbox2.c +5 -0
  174. data/vendor/libsodium/test/default/secretbox_easy.c +19 -1
  175. data/vendor/libsodium/test/default/secretbox_easy.exp +2 -0
  176. data/vendor/libsodium/test/default/secretbox_easy2.c +4 -0
  177. data/vendor/libsodium/test/default/secretstream.c +280 -0
  178. data/vendor/libsodium/test/default/secretstream.exp +1 -0
  179. data/vendor/libsodium/test/default/sign.c +31 -0
  180. data/vendor/libsodium/test/default/sodium_core.c +23 -1
  181. data/vendor/libsodium/test/default/sodium_core.exp +1 -1
  182. data/vendor/libsodium/test/default/sodium_utils.c +45 -56
  183. data/vendor/libsodium/test/default/sodium_utils.exp +0 -8
  184. data/vendor/libsodium/test/default/stream.c +2 -0
  185. data/vendor/libsodium/test/default/stream2.c +1 -0
  186. data/vendor/libsodium/test/default/xchacha20.c +58 -7
  187. metadata +21 -18
  188. data/vendor/libsodium/dist-build/emscripten-wasm.sh +0 -132
  189. data/vendor/libsodium/m4/pkg.m4 +0 -214
  190. data/vendor/libsodium/packaging/dotnet-core/desktop.targets +0 -16
  191. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/afternm_aes128ctr.c +0 -174
  192. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/beforenm_aes128ctr.c +0 -66
  193. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/common.h +0 -766
  194. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/consts.h +0 -28
  195. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/consts_aes128ctr.c +0 -28
  196. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/int128.h +0 -50
  197. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/int128_aes128ctr.c +0 -149
  198. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/stream_aes128ctr_nacl.c +0 -31
  199. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/xor_afternm_aes128ctr.c +0 -195
  200. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/stream_aes128ctr.c +0 -19
  201. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes128ctr.h +0 -65
@@ -1,66 +0,0 @@
1
- /* Author: Peter Schwabe, ported from an assembly implementation by Emilia
2
- * Käsper
3
- * Date: 2009-03-19
4
- * Public domain */
5
-
6
- #include "common.h"
7
- #include "consts.h"
8
- #include "crypto_stream_aes128ctr.h"
9
- #include "int128.h"
10
-
11
- int
12
- crypto_stream_aes128ctr_beforenm(unsigned char *c, const unsigned char *k)
13
- {
14
- aes_uint128_t xmm0;
15
- aes_uint128_t xmm1;
16
- aes_uint128_t xmm2;
17
- aes_uint128_t xmm3;
18
- aes_uint128_t xmm4;
19
- aes_uint128_t xmm5;
20
- aes_uint128_t xmm6;
21
- aes_uint128_t xmm7;
22
- aes_uint128_t xmm8;
23
- aes_uint128_t xmm9;
24
- aes_uint128_t xmm10;
25
- aes_uint128_t xmm11;
26
- aes_uint128_t xmm12;
27
- aes_uint128_t xmm13;
28
- aes_uint128_t xmm14;
29
- aes_uint128_t xmm15;
30
- aes_uint128_t t;
31
-
32
- bitslicekey0(k, c);
33
-
34
- keyexpbs1(xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10,
35
- xmm11, xmm12, xmm13, xmm14, xmm15, c);
36
- keyexpbs(xmm0, xmm1, xmm4, xmm6, xmm3, xmm7, xmm2, xmm5, xmm8, xmm9, xmm10,
37
- xmm11, xmm12, xmm13, xmm14, xmm15, xor_rcon(&xmm1);
38
- , 2, c);
39
- keyexpbs(xmm0, xmm1, xmm3, xmm2, xmm6, xmm5, xmm4, xmm7, xmm8, xmm9, xmm10,
40
- xmm11, xmm12, xmm13, xmm14, xmm15, xor_rcon(&xmm6);
41
- , 3, c);
42
- keyexpbs(xmm0, xmm1, xmm6, xmm4, xmm2, xmm7, xmm3, xmm5, xmm8, xmm9, xmm10,
43
- xmm11, xmm12, xmm13, xmm14, xmm15, xor_rcon(&xmm3);
44
- , 4, c);
45
-
46
- keyexpbs(xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10,
47
- xmm11, xmm12, xmm13, xmm14, xmm15, xor_rcon(&xmm3);
48
- , 5, c);
49
- keyexpbs(xmm0, xmm1, xmm4, xmm6, xmm3, xmm7, xmm2, xmm5, xmm8, xmm9, xmm10,
50
- xmm11, xmm12, xmm13, xmm14, xmm15, xor_rcon(&xmm5);
51
- , 6, c);
52
- keyexpbs(xmm0, xmm1, xmm3, xmm2, xmm6, xmm5, xmm4, xmm7, xmm8, xmm9, xmm10,
53
- xmm11, xmm12, xmm13, xmm14, xmm15, xor_rcon(&xmm3);
54
- , 7, c);
55
- keyexpbs(xmm0, xmm1, xmm6, xmm4, xmm2, xmm7, xmm3, xmm5, xmm8, xmm9, xmm10,
56
- xmm11, xmm12, xmm13, xmm14, xmm15, xor_rcon(&xmm7);
57
- , 8, c);
58
-
59
- keyexpbs(xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10,
60
- xmm11, xmm12, xmm13, xmm14, xmm15, xor_rcon(&xmm0);
61
- xor_rcon(&xmm1); xor_rcon(&xmm6); xor_rcon(&xmm3);, 9, c);
62
- keyexpbs10(xmm0, xmm1, xmm4, xmm6, xmm3, xmm7, xmm2, xmm5, xmm8, xmm9,
63
- xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, c);
64
-
65
- return 0;
66
- }
@@ -1,766 +0,0 @@
1
- /* Author: Peter Schwabe, ported from an assembly implementation by Emilia
2
- Käsper
3
- Date: 2009-03-19
4
- Public domain */
5
- #ifndef aes128ctr_nacl_common_H
6
- #define aes128ctr_nacl_common_H
7
-
8
- #include "private/common.h"
9
-
10
- /* Macros required only for key expansion */
11
-
12
- #define keyexpbs1(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, \
13
- t7, bskey) \
14
- rotbyte(&b0); \
15
- rotbyte(&b1); \
16
- rotbyte(&b2); \
17
- rotbyte(&b3); \
18
- rotbyte(&b4); \
19
- rotbyte(&b5); \
20
- rotbyte(&b6); \
21
- rotbyte(&b7); \
22
- \
23
- sbox(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7); \
24
- \
25
- xor_rcon(&b0); \
26
- shufb(&b0, EXPB0); \
27
- shufb(&b1, EXPB0); \
28
- shufb(&b4, EXPB0); \
29
- shufb(&b6, EXPB0); \
30
- shufb(&b3, EXPB0); \
31
- shufb(&b7, EXPB0); \
32
- shufb(&b2, EXPB0); \
33
- shufb(&b5, EXPB0); \
34
- shufb(&b0, EXPB0); \
35
- \
36
- t0 = *(aes_uint128_t *) (bskey + 0); \
37
- t1 = *(aes_uint128_t *) (bskey + 16); \
38
- t2 = *(aes_uint128_t *) (bskey + 32); \
39
- t3 = *(aes_uint128_t *) (bskey + 48); \
40
- t4 = *(aes_uint128_t *) (bskey + 64); \
41
- t5 = *(aes_uint128_t *) (bskey + 80); \
42
- t6 = *(aes_uint128_t *) (bskey + 96); \
43
- t7 = *(aes_uint128_t *) (bskey + 112); \
44
- \
45
- xor2(&b0, &t0); \
46
- xor2(&b1, &t1); \
47
- xor2(&b4, &t2); \
48
- xor2(&b6, &t3); \
49
- xor2(&b3, &t4); \
50
- xor2(&b7, &t5); \
51
- xor2(&b2, &t6); \
52
- xor2(&b5, &t7); \
53
- \
54
- rshift32_littleendian(&t0, 8); \
55
- rshift32_littleendian(&t1, 8); \
56
- rshift32_littleendian(&t2, 8); \
57
- rshift32_littleendian(&t3, 8); \
58
- rshift32_littleendian(&t4, 8); \
59
- rshift32_littleendian(&t5, 8); \
60
- rshift32_littleendian(&t6, 8); \
61
- rshift32_littleendian(&t7, 8); \
62
- \
63
- xor2(&b0, &t0); \
64
- xor2(&b1, &t1); \
65
- xor2(&b4, &t2); \
66
- xor2(&b6, &t3); \
67
- xor2(&b3, &t4); \
68
- xor2(&b7, &t5); \
69
- xor2(&b2, &t6); \
70
- xor2(&b5, &t7); \
71
- \
72
- rshift32_littleendian(&t0, 8); \
73
- rshift32_littleendian(&t1, 8); \
74
- rshift32_littleendian(&t2, 8); \
75
- rshift32_littleendian(&t3, 8); \
76
- rshift32_littleendian(&t4, 8); \
77
- rshift32_littleendian(&t5, 8); \
78
- rshift32_littleendian(&t6, 8); \
79
- rshift32_littleendian(&t7, 8); \
80
- \
81
- xor2(&b0, &t0); \
82
- xor2(&b1, &t1); \
83
- xor2(&b4, &t2); \
84
- xor2(&b6, &t3); \
85
- xor2(&b3, &t4); \
86
- xor2(&b7, &t5); \
87
- xor2(&b2, &t6); \
88
- xor2(&b5, &t7); \
89
- \
90
- rshift32_littleendian(&t0, 8); \
91
- rshift32_littleendian(&t1, 8); \
92
- rshift32_littleendian(&t2, 8); \
93
- rshift32_littleendian(&t3, 8); \
94
- rshift32_littleendian(&t4, 8); \
95
- rshift32_littleendian(&t5, 8); \
96
- rshift32_littleendian(&t6, 8); \
97
- rshift32_littleendian(&t7, 8); \
98
- \
99
- xor2(&b0, &t0); \
100
- xor2(&b1, &t1); \
101
- xor2(&b4, &t2); \
102
- xor2(&b6, &t3); \
103
- xor2(&b3, &t4); \
104
- xor2(&b7, &t5); \
105
- xor2(&b2, &t6); \
106
- xor2(&b5, &t7); \
107
- \
108
- *(aes_uint128_t *) (bskey + 128) = b0; \
109
- *(aes_uint128_t *) (bskey + 144) = b1; \
110
- *(aes_uint128_t *) (bskey + 160) = b4; \
111
- *(aes_uint128_t *) (bskey + 176) = b6; \
112
- *(aes_uint128_t *) (bskey + 192) = b3; \
113
- *(aes_uint128_t *) (bskey + 208) = b7; \
114
- *(aes_uint128_t *) (bskey + 224) = b2; \
115
- *(aes_uint128_t *) (bskey + 240) = b5
116
-
117
- #define keyexpbs10(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, \
118
- t7, bskey) \
119
- toggle(&b0); \
120
- toggle(&b1); \
121
- toggle(&b5); \
122
- toggle(&b6); \
123
- rotbyte(&b0); \
124
- rotbyte(&b1); \
125
- rotbyte(&b2); \
126
- rotbyte(&b3); \
127
- rotbyte(&b4); \
128
- rotbyte(&b5); \
129
- rotbyte(&b6); \
130
- rotbyte(&b7); \
131
- \
132
- sbox(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7); \
133
- \
134
- xor_rcon(&b1); \
135
- xor_rcon(&b4); \
136
- xor_rcon(&b3); \
137
- xor_rcon(&b7); \
138
- shufb(&b0, EXPB0); \
139
- shufb(&b1, EXPB0); \
140
- shufb(&b4, EXPB0); \
141
- shufb(&b6, EXPB0); \
142
- shufb(&b3, EXPB0); \
143
- shufb(&b7, EXPB0); \
144
- shufb(&b2, EXPB0); \
145
- shufb(&b5, EXPB0); \
146
- \
147
- t0 = *(aes_uint128_t *) (bskey + 9 * 128 + 0); \
148
- t1 = *(aes_uint128_t *) (bskey + 9 * 128 + 16); \
149
- t2 = *(aes_uint128_t *) (bskey + 9 * 128 + 32); \
150
- t3 = *(aes_uint128_t *) (bskey + 9 * 128 + 48); \
151
- t4 = *(aes_uint128_t *) (bskey + 9 * 128 + 64); \
152
- t5 = *(aes_uint128_t *) (bskey + 9 * 128 + 80); \
153
- t6 = *(aes_uint128_t *) (bskey + 9 * 128 + 96); \
154
- t7 = *(aes_uint128_t *) (bskey + 9 * 128 + 112); \
155
- \
156
- toggle(&t0); \
157
- toggle(&t1); \
158
- toggle(&t5); \
159
- toggle(&t6); \
160
- \
161
- xor2(&b0, &t0); \
162
- xor2(&b1, &t1); \
163
- xor2(&b4, &t2); \
164
- xor2(&b6, &t3); \
165
- xor2(&b3, &t4); \
166
- xor2(&b7, &t5); \
167
- xor2(&b2, &t6); \
168
- xor2(&b5, &t7); \
169
- \
170
- rshift32_littleendian(&t0, 8); \
171
- rshift32_littleendian(&t1, 8); \
172
- rshift32_littleendian(&t2, 8); \
173
- rshift32_littleendian(&t3, 8); \
174
- rshift32_littleendian(&t4, 8); \
175
- rshift32_littleendian(&t5, 8); \
176
- rshift32_littleendian(&t6, 8); \
177
- rshift32_littleendian(&t7, 8); \
178
- \
179
- xor2(&b0, &t0); \
180
- xor2(&b1, &t1); \
181
- xor2(&b4, &t2); \
182
- xor2(&b6, &t3); \
183
- xor2(&b3, &t4); \
184
- xor2(&b7, &t5); \
185
- xor2(&b2, &t6); \
186
- xor2(&b5, &t7); \
187
- \
188
- rshift32_littleendian(&t0, 8); \
189
- rshift32_littleendian(&t1, 8); \
190
- rshift32_littleendian(&t2, 8); \
191
- rshift32_littleendian(&t3, 8); \
192
- rshift32_littleendian(&t4, 8); \
193
- rshift32_littleendian(&t5, 8); \
194
- rshift32_littleendian(&t6, 8); \
195
- rshift32_littleendian(&t7, 8); \
196
- \
197
- xor2(&b0, &t0); \
198
- xor2(&b1, &t1); \
199
- xor2(&b4, &t2); \
200
- xor2(&b6, &t3); \
201
- xor2(&b3, &t4); \
202
- xor2(&b7, &t5); \
203
- xor2(&b2, &t6); \
204
- xor2(&b5, &t7); \
205
- \
206
- rshift32_littleendian(&t0, 8); \
207
- rshift32_littleendian(&t1, 8); \
208
- rshift32_littleendian(&t2, 8); \
209
- rshift32_littleendian(&t3, 8); \
210
- rshift32_littleendian(&t4, 8); \
211
- rshift32_littleendian(&t5, 8); \
212
- rshift32_littleendian(&t6, 8); \
213
- rshift32_littleendian(&t7, 8); \
214
- \
215
- xor2(&b0, &t0); \
216
- xor2(&b1, &t1); \
217
- xor2(&b4, &t2); \
218
- xor2(&b6, &t3); \
219
- xor2(&b3, &t4); \
220
- xor2(&b7, &t5); \
221
- xor2(&b2, &t6); \
222
- xor2(&b5, &t7); \
223
- \
224
- shufb(&b0, M0); \
225
- shufb(&b1, M0); \
226
- shufb(&b2, M0); \
227
- shufb(&b3, M0); \
228
- shufb(&b4, M0); \
229
- shufb(&b5, M0); \
230
- shufb(&b6, M0); \
231
- shufb(&b7, M0); \
232
- \
233
- *(aes_uint128_t *) (bskey + 1280) = b0; \
234
- *(aes_uint128_t *) (bskey + 1296) = b1; \
235
- *(aes_uint128_t *) (bskey + 1312) = b4; \
236
- *(aes_uint128_t *) (bskey + 1328) = b6; \
237
- *(aes_uint128_t *) (bskey + 1344) = b3; \
238
- *(aes_uint128_t *) (bskey + 1360) = b7; \
239
- *(aes_uint128_t *) (bskey + 1376) = b2; \
240
- *(aes_uint128_t *) (bskey + 1392) = b5
241
-
242
- #define keyexpbs(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, \
243
- t7, rcon, i, bskey) \
244
- toggle(&b0); \
245
- toggle(&b1); \
246
- toggle(&b5); \
247
- toggle(&b6); \
248
- rotbyte(&b0); \
249
- rotbyte(&b1); \
250
- rotbyte(&b2); \
251
- rotbyte(&b3); \
252
- rotbyte(&b4); \
253
- rotbyte(&b5); \
254
- rotbyte(&b6); \
255
- rotbyte(&b7); \
256
- \
257
- sbox(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7); \
258
- \
259
- rcon; \
260
- shufb(&b0, EXPB0); \
261
- shufb(&b1, EXPB0); \
262
- shufb(&b4, EXPB0); \
263
- shufb(&b6, EXPB0); \
264
- shufb(&b3, EXPB0); \
265
- shufb(&b7, EXPB0); \
266
- shufb(&b2, EXPB0); \
267
- shufb(&b5, EXPB0); \
268
- \
269
- t0 = *(aes_uint128_t *) (bskey + (i - 1) * 128 + 0); \
270
- t1 = *(aes_uint128_t *) (bskey + (i - 1) * 128 + 16); \
271
- t2 = *(aes_uint128_t *) (bskey + (i - 1) * 128 + 32); \
272
- t3 = *(aes_uint128_t *) (bskey + (i - 1) * 128 + 48); \
273
- t4 = *(aes_uint128_t *) (bskey + (i - 1) * 128 + 64); \
274
- t5 = *(aes_uint128_t *) (bskey + (i - 1) * 128 + 80); \
275
- t6 = *(aes_uint128_t *) (bskey + (i - 1) * 128 + 96); \
276
- t7 = *(aes_uint128_t *) (bskey + (i - 1) * 128 + 112); \
277
- \
278
- toggle(&t0); \
279
- toggle(&t1); \
280
- toggle(&t5); \
281
- toggle(&t6); \
282
- \
283
- xor2(&b0, &t0); \
284
- xor2(&b1, &t1); \
285
- xor2(&b4, &t2); \
286
- xor2(&b6, &t3); \
287
- xor2(&b3, &t4); \
288
- xor2(&b7, &t5); \
289
- xor2(&b2, &t6); \
290
- xor2(&b5, &t7); \
291
- \
292
- rshift32_littleendian(&t0, 8); \
293
- rshift32_littleendian(&t1, 8); \
294
- rshift32_littleendian(&t2, 8); \
295
- rshift32_littleendian(&t3, 8); \
296
- rshift32_littleendian(&t4, 8); \
297
- rshift32_littleendian(&t5, 8); \
298
- rshift32_littleendian(&t6, 8); \
299
- rshift32_littleendian(&t7, 8); \
300
- \
301
- xor2(&b0, &t0); \
302
- xor2(&b1, &t1); \
303
- xor2(&b4, &t2); \
304
- xor2(&b6, &t3); \
305
- xor2(&b3, &t4); \
306
- xor2(&b7, &t5); \
307
- xor2(&b2, &t6); \
308
- xor2(&b5, &t7); \
309
- \
310
- rshift32_littleendian(&t0, 8); \
311
- rshift32_littleendian(&t1, 8); \
312
- rshift32_littleendian(&t2, 8); \
313
- rshift32_littleendian(&t3, 8); \
314
- rshift32_littleendian(&t4, 8); \
315
- rshift32_littleendian(&t5, 8); \
316
- rshift32_littleendian(&t6, 8); \
317
- rshift32_littleendian(&t7, 8); \
318
- \
319
- xor2(&b0, &t0); \
320
- xor2(&b1, &t1); \
321
- xor2(&b4, &t2); \
322
- xor2(&b6, &t3); \
323
- xor2(&b3, &t4); \
324
- xor2(&b7, &t5); \
325
- xor2(&b2, &t6); \
326
- xor2(&b5, &t7); \
327
- \
328
- rshift32_littleendian(&t0, 8); \
329
- rshift32_littleendian(&t1, 8); \
330
- rshift32_littleendian(&t2, 8); \
331
- rshift32_littleendian(&t3, 8); \
332
- rshift32_littleendian(&t4, 8); \
333
- rshift32_littleendian(&t5, 8); \
334
- rshift32_littleendian(&t6, 8); \
335
- rshift32_littleendian(&t7, 8); \
336
- \
337
- xor2(&b0, &t0); \
338
- xor2(&b1, &t1); \
339
- xor2(&b4, &t2); \
340
- xor2(&b6, &t3); \
341
- xor2(&b3, &t4); \
342
- xor2(&b7, &t5); \
343
- xor2(&b2, &t6); \
344
- xor2(&b5, &t7); \
345
- \
346
- *(aes_uint128_t *) (bskey + i * 128 + 0) = b0; \
347
- *(aes_uint128_t *) (bskey + i * 128 + 16) = b1; \
348
- *(aes_uint128_t *) (bskey + i * 128 + 32) = b4; \
349
- *(aes_uint128_t *) (bskey + i * 128 + 48) = b6; \
350
- *(aes_uint128_t *) (bskey + i * 128 + 64) = b3; \
351
- *(aes_uint128_t *) (bskey + i * 128 + 80) = b7; \
352
- *(aes_uint128_t *) (bskey + i * 128 + 96) = b2; \
353
- *(aes_uint128_t *) (bskey + i * 128 + 112) = b5
354
-
355
- /* Macros used in multiple contexts */
356
-
357
- #define bitslicekey0(key, bskey) \
358
- xmm0 = *(const aes_uint128_t *) (key + 0); \
359
- shufb(&xmm0, M0); \
360
- copy2(&xmm1, &xmm0); \
361
- copy2(&xmm2, &xmm0); \
362
- copy2(&xmm3, &xmm0); \
363
- copy2(&xmm4, &xmm0); \
364
- copy2(&xmm5, &xmm0); \
365
- copy2(&xmm6, &xmm0); \
366
- copy2(&xmm7, &xmm0); \
367
- \
368
- bitslice(xmm7, xmm6, xmm5, xmm4, xmm3, xmm2, xmm1, xmm0, t); \
369
- \
370
- *(aes_uint128_t *) (bskey + 0) = xmm0; \
371
- *(aes_uint128_t *) (bskey + 16) = xmm1; \
372
- *(aes_uint128_t *) (bskey + 32) = xmm2; \
373
- *(aes_uint128_t *) (bskey + 48) = xmm3; \
374
- *(aes_uint128_t *) (bskey + 64) = xmm4; \
375
- *(aes_uint128_t *) (bskey + 80) = xmm5; \
376
- *(aes_uint128_t *) (bskey + 96) = xmm6; \
377
- *(aes_uint128_t *) (bskey + 112) = xmm7
378
-
379
- #define bitslicekey10(key, bskey) \
380
- xmm0 = *(aes_uint128_t *) (key + 0); \
381
- copy2(xmm1, xmm0); \
382
- copy2(xmm2, xmm0); \
383
- copy2(xmm3, xmm0); \
384
- copy2(xmm4, xmm0); \
385
- copy2(xmm5, xmm0); \
386
- copy2(xmm6, xmm0); \
387
- copy2(xmm7, xmm0); \
388
- \
389
- bitslice(xmm7, xmm6, xmm5, xmm4, xmm3, xmm2, xmm1, xmm0, t); \
390
- \
391
- toggle(&xmm6); \
392
- toggle(&xmm5); \
393
- toggle(&xmm1); \
394
- toggle(&xmm0); \
395
- \
396
- *(aes_uint128_t *) (bskey + 0 + 1280) = xmm0; \
397
- *(aes_uint128_t *) (bskey + 16 + 1280) = xmm1; \
398
- *(aes_uint128_t *) (bskey + 32 + 1280) = xmm2; \
399
- *(aes_uint128_t *) (bskey + 48 + 1280) = xmm3; \
400
- *(aes_uint128_t *) (bskey + 64 + 1280) = xmm4; \
401
- *(aes_uint128_t *) (bskey + 80 + 1280) = xmm5; \
402
- *(aes_uint128_t *) (bskey + 96 + 1280) = xmm6; \
403
- *(aes_uint128_t *) (bskey + 112 + 1280) = xmm7
404
-
405
- #define bitslicekey(i, key, bskey) \
406
- xmm0 = *(aes_uint128_t *) (key + 0); \
407
- shufb(&xmm0, M0); \
408
- copy2(&xmm1, &xmm0); \
409
- copy2(&xmm2, &xmm0); \
410
- copy2(&xmm3, &xmm0); \
411
- copy2(&xmm4, &xmm0); \
412
- copy2(&xmm5, &xmm0); \
413
- copy2(&xmm6, &xmm0); \
414
- copy2(&xmm7, &xmm0); \
415
- \
416
- bitslice(xmm7, xmm6, xmm5, xmm4, xmm3, xmm2, xmm1, xmm0, t); \
417
- \
418
- toggle(&xmm6); \
419
- toggle(&xmm5); \
420
- toggle(&xmm1); \
421
- toggle(&xmm0); \
422
- \
423
- *(aes_uint128_t *) (bskey + 0 + 128 * i) = xmm0; \
424
- *(aes_uint128_t *) (bskey + 16 + 128 * i) = xmm1; \
425
- *(aes_uint128_t *) (bskey + 32 + 128 * i) = xmm2; \
426
- *(aes_uint128_t *) (bskey + 48 + 128 * i) = xmm3; \
427
- *(aes_uint128_t *) (bskey + 64 + 128 * i) = xmm4; \
428
- *(aes_uint128_t *) (bskey + 80 + 128 * i) = xmm5; \
429
- *(aes_uint128_t *) (bskey + 96 + 128 * i) = xmm6; \
430
- *(aes_uint128_t *) (bskey + 112 + 128 * i) = xmm7
431
-
432
- #define bitslice(x0, x1, x2, x3, x4, x5, x6, x7, t) \
433
- swapmove(x0, x1, 1, BS0, t); \
434
- swapmove(x2, x3, 1, BS0, t); \
435
- swapmove(x4, x5, 1, BS0, t); \
436
- swapmove(x6, x7, 1, BS0, t); \
437
- \
438
- swapmove(x0, x2, 2, BS1, t); \
439
- swapmove(x1, x3, 2, BS1, t); \
440
- swapmove(x4, x6, 2, BS1, t); \
441
- swapmove(x5, x7, 2, BS1, t); \
442
- \
443
- swapmove(x0, x4, 4, BS2, t); \
444
- swapmove(x1, x5, 4, BS2, t); \
445
- swapmove(x2, x6, 4, BS2, t); \
446
- swapmove(x3, x7, 4, BS2, t)
447
-
448
- #define swapmove(a, b, n, m, t) \
449
- copy2(&t, &b); \
450
- rshift64_littleendian(&t, n); \
451
- xor2(&t, &a); \
452
- and2(&t, &m); \
453
- xor2(&a, &t); \
454
- lshift64_littleendian(&t, n); \
455
- xor2(&b, &t)
456
-
457
- #define rotbyte(x) shufb(x, ROTB) /* TODO: Make faster */
458
-
459
- /* Macros used for encryption (and decryption) */
460
-
461
- #define shiftrows(x0, x1, x2, x3, x4, x5, x6, x7, i, M, bskey) \
462
- xor2(&x0, (const aes_uint128_t *) (bskey + 128 * (i - 1) + 0)); \
463
- shufb(&x0, M); \
464
- xor2(&x1, (const aes_uint128_t *) (bskey + 128 * (i - 1) + 16)); \
465
- shufb(&x1, M); \
466
- xor2(&x2, (const aes_uint128_t *) (bskey + 128 * (i - 1) + 32)); \
467
- shufb(&x2, M); \
468
- xor2(&x3, (const aes_uint128_t *) (bskey + 128 * (i - 1) + 48)); \
469
- shufb(&x3, M); \
470
- xor2(&x4, (const aes_uint128_t *) (bskey + 128 * (i - 1) + 64)); \
471
- shufb(&x4, M); \
472
- xor2(&x5, (const aes_uint128_t *) (bskey + 128 * (i - 1) + 80)); \
473
- shufb(&x5, M); \
474
- xor2(&x6, (const aes_uint128_t *) (bskey + 128 * (i - 1) + 96)); \
475
- shufb(&x6, M); \
476
- xor2(&x7, (const aes_uint128_t *) (bskey + 128 * (i - 1) + 112)); \
477
- shufb(&x7, M)
478
-
479
- #define mixcolumns(x0, x1, x2, x3, x4, x5, x6, x7, t0, t1, t2, t3, t4, t5, t6, \
480
- t7) \
481
- shufd(&t0, &x0, 0x93); \
482
- shufd(&t1, &x1, 0x93); \
483
- shufd(&t2, &x2, 0x93); \
484
- shufd(&t3, &x3, 0x93); \
485
- shufd(&t4, &x4, 0x93); \
486
- shufd(&t5, &x5, 0x93); \
487
- shufd(&t6, &x6, 0x93); \
488
- shufd(&t7, &x7, 0x93); \
489
- \
490
- xor2(&x0, &t0); \
491
- xor2(&x1, &t1); \
492
- xor2(&x2, &t2); \
493
- xor2(&x3, &t3); \
494
- xor2(&x4, &t4); \
495
- xor2(&x5, &t5); \
496
- xor2(&x6, &t6); \
497
- xor2(&x7, &t7); \
498
- \
499
- xor2(&t0, &x7); \
500
- xor2(&t1, &x0); \
501
- xor2(&t2, &x1); \
502
- xor2(&t1, &x7); \
503
- xor2(&t3, &x2); \
504
- xor2(&t4, &x3); \
505
- xor2(&t5, &x4); \
506
- xor2(&t3, &x7); \
507
- xor2(&t6, &x5); \
508
- xor2(&t7, &x6); \
509
- xor2(&t4, &x7); \
510
- \
511
- shufd(&x0, &x0, 0x4e); \
512
- shufd(&x1, &x1, 0x4e); \
513
- shufd(&x2, &x2, 0x4e); \
514
- shufd(&x3, &x3, 0x4e); \
515
- shufd(&x4, &x4, 0x4e); \
516
- shufd(&x5, &x5, 0x4e); \
517
- shufd(&x6, &x6, 0x4e); \
518
- shufd(&x7, &x7, 0x4e); \
519
- \
520
- xor2(&t0, &x0); \
521
- xor2(&t1, &x1); \
522
- xor2(&t2, &x2); \
523
- xor2(&t3, &x3); \
524
- xor2(&t4, &x4); \
525
- xor2(&t5, &x5); \
526
- xor2(&t6, &x6); \
527
- xor2(&t7, &x7)
528
-
529
- #define aesround(i, b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, \
530
- t6, t7, bskey) \
531
- shiftrows(b0, b1, b2, b3, b4, b5, b6, b7, i, SR, bskey); \
532
- sbox(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7); \
533
- mixcolumns(b0, b1, b4, b6, b3, b7, b2, b5, t0, t1, t2, t3, t4, t5, t6, t7)
534
-
535
- #define lastround(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, \
536
- t7, bskey) \
537
- shiftrows(b0, b1, b2, b3, b4, b5, b6, b7, 10, SRM0, bskey); \
538
- sbox(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, t4, t5, t6, t7); \
539
- xor2(&b0, (const aes_uint128_t *) (bskey + 128 * 10)); \
540
- xor2(&b1, (const aes_uint128_t *) (bskey + 128 * 10 + 16)); \
541
- xor2(&b4, (const aes_uint128_t *) (bskey + 128 * 10 + 32)); \
542
- xor2(&b6, (const aes_uint128_t *) (bskey + 128 * 10 + 48)); \
543
- xor2(&b3, (const aes_uint128_t *) (bskey + 128 * 10 + 64)); \
544
- xor2(&b7, (const aes_uint128_t *) (bskey + 128 * 10 + 80)); \
545
- xor2(&b2, (const aes_uint128_t *) (bskey + 128 * 10 + 96)); \
546
- xor2(&b5, (const aes_uint128_t *) (bskey + 128 * 10 + 112))
547
-
548
- #define sbox(b0, b1, b2, b3, b4, b5, b6, b7, t0, t1, t2, t3, s0, s1, s2, s3) \
549
- InBasisChange(b0, b1, b2, b3, b4, b5, b6, b7); \
550
- Inv_GF256(b6, b5, b0, b3, b7, b1, b4, b2, t0, t1, t2, t3, s0, s1, s2, s3); \
551
- OutBasisChange(b7, b1, b4, b2, b6, b5, b0, b3)
552
-
553
- #define InBasisChange(b0, b1, b2, b3, b4, b5, b6, b7) \
554
- xor2(&b5, &b6); \
555
- xor2(&b2, &b1); \
556
- xor2(&b5, &b0); \
557
- xor2(&b6, &b2); \
558
- xor2(&b3, &b0); \
559
- \
560
- xor2(&b6, &b3); \
561
- xor2(&b3, &b7); \
562
- xor2(&b3, &b4); \
563
- xor2(&b7, &b5); \
564
- xor2(&b3, &b1); \
565
- \
566
- xor2(&b4, &b5); \
567
- xor2(&b2, &b7); \
568
- xor2(&b1, &b5)
569
-
570
- #define OutBasisChange(b0, b1, b2, b3, b4, b5, b6, b7) \
571
- xor2(&b0, &b6); \
572
- xor2(&b1, &b4); \
573
- xor2(&b2, &b0); \
574
- xor2(&b4, &b6); \
575
- xor2(&b6, &b1); \
576
- \
577
- xor2(&b1, &b5); \
578
- xor2(&b5, &b3); \
579
- xor2(&b2, &b5); \
580
- xor2(&b3, &b7); \
581
- xor2(&b7, &b5); \
582
- \
583
- xor2(&b4, &b7)
584
-
585
- #define Mul_GF4(x0, x1, y0, y1, t0) \
586
- copy2(&t0, &y0); \
587
- xor2(&t0, &y1); \
588
- and2(&t0, &x0); \
589
- xor2(&x0, &x1); \
590
- and2(&x0, &y1); \
591
- and2(&x1, &y0); \
592
- xor2(&x0, &x1); \
593
- xor2(&x1, &t0)
594
-
595
- #define Mul_GF4_N(x0, x1, y0, y1, t0) \
596
- copy2(&t0, &y0); \
597
- xor2(&t0, &y1); \
598
- and2(&t0, &x0); \
599
- xor2(&x0, &x1); \
600
- and2(&x0, &y1); \
601
- and2(&x1, &y0); \
602
- xor2(&x1, &x0); \
603
- xor2(&x0, &t0)
604
-
605
- #define Mul_GF4_2(x0, x1, x2, x3, y0, y1, t0, t1) \
606
- copy2(&t0, = y0); \
607
- xor2(&t0, &y1); \
608
- copy2(&t1, &t0); \
609
- and2(&t0, &x0); \
610
- and2(&t1, &x2); \
611
- xor2(&x0, &x1); \
612
- xor2(&x2, &x3); \
613
- and2(&x0, &y1); \
614
- and2(&x2, &y1); \
615
- and2(&x1, &y0); \
616
- and2(&x3, &y0); \
617
- xor2(&x0, &x1); \
618
- xor2(&x2, &x3); \
619
- xor2(&x1, &t0); \
620
- xor2(&x3, &t1)
621
-
622
- #define Mul_GF16(x0, x1, x2, x3, y0, y1, y2, y3, t0, t1, t2, t3) \
623
- copy2(&t0, &x0); \
624
- copy2(&t1, &x1); \
625
- Mul_GF4(x0, x1, y0, y1, t2); \
626
- xor2(&t0, &x2); \
627
- xor2(&t1, &x3); \
628
- xor2(&y0, &y2); \
629
- xor2(&y1, &y3); \
630
- Mul_GF4_N(t0, t1, y0, y1, t2); \
631
- Mul_GF4(x2, x3, y2, y3, t3); \
632
- \
633
- xor2(&x0, &t0); \
634
- xor2(&x2, &t0); \
635
- xor2(&x1, &t1); \
636
- xor2(&x3, &t1)
637
-
638
- #define Mul_GF16_2(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, t0, t1, t2, \
639
- t3) \
640
- copy2(&t0, &x0); \
641
- copy2(&t1, &x1); \
642
- Mul_GF4(x0, x1, y0, y1, t2); \
643
- xor2(&t0, &x2); \
644
- xor2(&t1, &x3); \
645
- xor2(&y0, &y2); \
646
- xor2(&y1, &y3); \
647
- Mul_GF4_N(t0, t1, y0, y1, t3); \
648
- Mul_GF4(x2, x3, y2, y3, t2); \
649
- \
650
- xor2(&x0, &t0); \
651
- xor2(&x2, &t0); \
652
- xor2(&x1, &t1); \
653
- xor2(&x3, &t1); \
654
- \
655
- copy2(&t0, &x4); \
656
- copy2(&t1, &x5); \
657
- xor2(&t0, &x6); \
658
- xor2(&t1, &x7); \
659
- Mul_GF4_N(t0, t1, y0, y1, t3); \
660
- Mul_GF4(x6, x7, y2, y3, t2); \
661
- xor2(&y0, &y2); \
662
- xor2(&y1, &y3); \
663
- Mul_GF4(x4, x5, y0, y1, t3); \
664
- \
665
- xor2(&x4, &t0); \
666
- xor2(&x6, &t0); \
667
- xor2(&x5, &t1); \
668
- xor2(&x7, &t1)
669
-
670
- #define Inv_GF16(x0, x1, x2, x3, t0, t1, t2, t3) \
671
- copy2(&t0, &x1); \
672
- copy2(&t1, &x0); \
673
- and2(&t0, &x3); \
674
- or2(&t1, &x2); \
675
- copy2(&t2, &x1); \
676
- copy2(&t3, &x0); \
677
- or2(&t2, &x2); \
678
- or2(&t3, &x3); \
679
- xor2(&t2, &t3); \
680
- \
681
- xor2(&t0, &t2); \
682
- xor2(&t1, &t2); \
683
- \
684
- Mul_GF4_2(x0, x1, x2, x3, t1, t0, t2, t3)
685
-
686
- #define Inv_GF256(x0, x1, x2, x3, x4, x5, x6, x7, t0, t1, t2, t3, s0, s1, s2, \
687
- s3) \
688
- copy2(&t3, &x4); \
689
- copy2(&t2, &x5); \
690
- copy2(&t1, &x1); \
691
- copy2(&s1, &x7); \
692
- copy2(&s0, &x0); \
693
- \
694
- xor2(&t3, &x6); \
695
- xor2(&t2, &x7); \
696
- xor2(&t1, &x3); \
697
- xor2(&s1, &x6); \
698
- xor2(&s0, &x2); \
699
- \
700
- copy2(&s2, &t3); \
701
- copy2(&t0, &t2); \
702
- copy2(&s3, &t3); \
703
- \
704
- or2(&t2, &t1); \
705
- or2(&t3, &s0); \
706
- xor2(&s3, &t0); \
707
- and2(&s2, &s0); \
708
- and2(&t0, &t1); \
709
- xor2(&s0, &t1); \
710
- and2(&s3, &s0); \
711
- copy2(&s0, &x3); \
712
- xor2(&s0, &x2); \
713
- and2(&s1, &s0); \
714
- xor2(&t3, &s1); \
715
- xor2(&t2, &s1); \
716
- copy2(&s1, &x4); \
717
- xor2(&s1, &x5); \
718
- copy2(&s0, &x1); \
719
- copy2(&t1, &s1); \
720
- xor2(&s0, &x0); \
721
- or2(&t1, &s0); \
722
- and2(&s1, &s0); \
723
- xor2(&t0, &s1); \
724
- xor2(&t3, &s3); \
725
- xor2(&t2, &s2); \
726
- xor2(&t1, &s3); \
727
- xor2(&t0, &s2); \
728
- xor2(&t1, &s2); \
729
- copy2(&s0, &x7); \
730
- copy2(&s1, &x6); \
731
- copy2(&s2, &x5); \
732
- copy2(&s3, &x4); \
733
- and2(&s0, &x3); \
734
- and2(&s1, &x2); \
735
- and2(&s2, &x1); \
736
- or2(&s3, &x0); \
737
- xor2(&t3, &s0); \
738
- xor2(&t2, &s1); \
739
- xor2(&t1, &s2); \
740
- xor2(&t0, &s3); \
741
- \
742
- copy2(&s0, &t3); \
743
- xor2(&s0, &t2); \
744
- and2(&t3, &t1); \
745
- copy2(&s2, &t0); \
746
- xor2(&s2, &t3); \
747
- copy2(&s3, &s0); \
748
- and2(&s3, &s2); \
749
- xor2(&s3, &t2); \
750
- copy2(&s1, &t1); \
751
- xor2(&s1, &t0); \
752
- xor2(&t3, &t2); \
753
- and2(&s1, &t3); \
754
- xor2(&s1, &t0); \
755
- xor2(&t1, &s1); \
756
- copy2(&t2, &s2); \
757
- xor2(&t2, &s1); \
758
- and2(&t2, &t0); \
759
- xor2(&t1, &t2); \
760
- xor2(&s2, &t2); \
761
- and2(&s2, &s3); \
762
- xor2(&s2, &s0); \
763
- \
764
- Mul_GF16_2(x0, x1, x2, x3, x4, x5, x6, x7, s3, s2, s1, t1, s0, t0, t2, t3)
765
-
766
- #endif