rbnacl-libsodium 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +23 -0
  3. data/CHANGES.md +5 -0
  4. data/Gemfile +5 -2
  5. data/Rakefile +5 -0
  6. data/ext/rbnacl/extconf.rb +2 -1
  7. data/lib/rbnacl/libsodium.rb +8 -2
  8. data/lib/rbnacl/libsodium/version.rb +1 -1
  9. data/vendor/libsodium/AUTHORS +14 -0
  10. data/vendor/libsodium/ChangeLog +26 -0
  11. data/vendor/libsodium/LICENSE +1 -1
  12. data/vendor/libsodium/Makefile.am +1 -0
  13. data/vendor/libsodium/Makefile.in +9 -0
  14. data/vendor/libsodium/README.markdown +7 -0
  15. data/vendor/libsodium/aclocal.m4 +1 -0
  16. data/vendor/libsodium/appveyor.yml +25 -0
  17. data/vendor/libsodium/autom4te.cache/output.1 +640 -126
  18. data/vendor/libsodium/autom4te.cache/output.6 +19049 -0
  19. data/vendor/libsodium/autom4te.cache/requests +1151 -914
  20. data/vendor/libsodium/autom4te.cache/traces.1 +472 -426
  21. data/vendor/libsodium/autom4te.cache/traces.6 +3193 -0
  22. data/vendor/libsodium/builds/msvc/version.h +2 -2
  23. data/vendor/libsodium/builds/msvc/vs2010/libsodium.sln +50 -79
  24. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +20 -8
  25. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +208 -166
  26. data/vendor/libsodium/builds/msvc/vs2012/libsodium.sln +50 -79
  27. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +20 -8
  28. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +206 -164
  29. data/vendor/libsodium/builds/msvc/vs2013/libsodium.sln +52 -81
  30. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +20 -8
  31. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +206 -164
  32. data/vendor/libsodium/builds/msvc/vs2015/libsodium.sln +52 -81
  33. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +20 -8
  34. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +206 -164
  35. data/vendor/libsodium/configure +639 -125
  36. data/vendor/libsodium/configure.ac +94 -16
  37. data/vendor/libsodium/dist-build/Makefile.in +9 -0
  38. data/vendor/libsodium/dist-build/emscripten-symbols.def +370 -0
  39. data/vendor/libsodium/dist-build/emscripten.sh +9 -3
  40. data/vendor/libsodium/dist-build/generate-emscripten-symbols.sh +43 -0
  41. data/vendor/libsodium/libsodium-uninstalled.pc.in +1 -1
  42. data/vendor/libsodium/libsodium.pc.in +1 -1
  43. data/vendor/libsodium/libsodium.vcxproj +70 -66
  44. data/vendor/libsodium/libsodium.vcxproj.filters +204 -192
  45. data/vendor/libsodium/m4/ax_valgrind_check.m4 +190 -0
  46. data/vendor/libsodium/msvc-scripts/Makefile.in +9 -0
  47. data/vendor/libsodium/msvc-scripts/process.bat +2 -2
  48. data/vendor/libsodium/src/Makefile.in +9 -0
  49. data/vendor/libsodium/src/libsodium/Makefile.am +31 -6
  50. data/vendor/libsodium/src/libsodium/Makefile.in +238 -42
  51. data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +234 -38
  52. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +208 -118
  53. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_seal.c +2 -2
  54. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/before_curve25519xsalsa20poly1305.c +1 -4
  55. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +1799 -1790
  56. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.h +39 -39
  57. data/vendor/libsodium/src/libsodium/crypto_core/hchacha20/core_hchacha20.c +86 -0
  58. data/vendor/libsodium/src/libsodium/crypto_core/hchacha20/core_hchacha20.h +28 -0
  59. data/vendor/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20.c +38 -46
  60. data/vendor/libsodium/src/libsodium/crypto_core/salsa20/ref/core_salsa20.c +47 -55
  61. data/vendor/libsodium/src/libsodium/crypto_core/salsa2012/ref/core_salsa2012.c +47 -55
  62. data/vendor/libsodium/src/libsodium/crypto_core/salsa208/ref/core_salsa208.c +47 -55
  63. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/generichash_blake2_api.c +7 -0
  64. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2-impl.h +0 -89
  65. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2.h +50 -141
  66. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.c +45 -0
  67. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.h +123 -0
  68. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ref.c +3 -2
  69. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-sse41.c +2 -2
  70. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/{blake2b-round.h → blake2b-compress-sse41.h} +2 -28
  71. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.c +2 -4
  72. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.h +97 -0
  73. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-avx2.h +339 -0
  74. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse2.h +0 -2
  75. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse41.h +0 -2
  76. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +29 -18
  77. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +4 -43
  78. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +3 -32
  79. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h +1 -20
  80. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +22 -41
  81. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +12 -39
  82. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +2 -4
  83. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.h +1 -20
  84. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c +570 -0
  85. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.h +198 -0
  86. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +444 -0
  87. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.h +32 -0
  88. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c +229 -0
  89. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c +222 -0
  90. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-impl.h +40 -0
  91. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +238 -0
  92. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.h +251 -0
  93. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blake2b-long.c +80 -0
  94. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blake2b-long.h +8 -0
  95. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-ref.h +38 -0
  96. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-ssse3.h +117 -0
  97. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +164 -0
  98. data/vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c +106 -0
  99. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +1 -1
  100. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +4 -4
  101. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +186 -186
  102. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +2 -2
  103. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +3 -2
  104. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +33 -33
  105. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +253 -254
  106. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c +16 -17
  107. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.h +1 -0
  108. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +11 -11
  109. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h +1 -0
  110. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/consts_namespace.h +1 -1
  111. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe.h +3 -2
  112. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51.h +5 -3
  113. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c +41 -41
  114. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_mul.S +10 -2
  115. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_namespace.h +1 -1
  116. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_nsquare.S +4 -0
  117. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_pack.S +4 -0
  118. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c +31 -32
  119. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.S +4 -0
  120. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.h +1 -1
  121. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.S +4 -0
  122. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.h +1 -1
  123. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base_namespace.h +1 -1
  124. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_namespace.h +1 -1
  125. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +2 -6
  126. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphash24.c +8 -28
  127. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +75 -0
  128. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/afternm_aes128ctr.c +6 -6
  129. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/common.h +1 -18
  130. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128_aes128ctr.c +20 -20
  131. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/types.h +4 -4
  132. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/xor_afternm_aes128ctr.c +6 -6
  133. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +56 -77
  134. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.h +1 -0
  135. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.h +1 -0
  136. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c +2 -8
  137. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +2 -8
  138. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c +2 -8
  139. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c +2 -8
  140. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c +2 -8
  141. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c +2 -8
  142. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c +1 -5
  143. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c +1 -5
  144. data/vendor/libsodium/src/libsodium/include/Makefile.am +3 -0
  145. data/vendor/libsodium/src/libsodium/include/Makefile.in +19 -8
  146. data/vendor/libsodium/src/libsodium/include/sodium.h +3 -0
  147. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +50 -0
  148. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +94 -22
  149. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +6 -6
  150. data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_hchacha20.h +35 -0
  151. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash_blake2b.h +3 -0
  152. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +89 -0
  153. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +86 -0
  154. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +6 -6
  155. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +0 -11
  156. data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +3 -0
  157. data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +3 -0
  158. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +5 -1
  159. data/vendor/libsodium/src/libsodium/sodium/common.h +150 -0
  160. data/vendor/libsodium/src/libsodium/sodium/core.c +3 -1
  161. data/vendor/libsodium/src/libsodium/sodium/runtime.c +37 -19
  162. data/vendor/libsodium/src/libsodium/sodium/utils.c +18 -9
  163. data/vendor/libsodium/test/Makefile.in +9 -0
  164. data/vendor/libsodium/test/default/Makefile.am +10 -0
  165. data/vendor/libsodium/test/default/Makefile.in +53 -20
  166. data/vendor/libsodium/test/default/aead_aes256gcm.c +43 -17
  167. data/vendor/libsodium/test/default/aead_chacha20poly1305.c +179 -86
  168. data/vendor/libsodium/test/default/auth7.c +5 -5
  169. data/vendor/libsodium/test/default/box.c +4 -4
  170. data/vendor/libsodium/test/default/box2.c +1 -1
  171. data/vendor/libsodium/test/default/core6.c +1 -1
  172. data/vendor/libsodium/test/default/generichash.c +12 -1
  173. data/vendor/libsodium/test/default/generichash2.c +2 -2
  174. data/vendor/libsodium/test/default/generichash3.c +21 -0
  175. data/vendor/libsodium/test/default/pwhash.c +186 -168
  176. data/vendor/libsodium/test/default/pwhash.exp +11 -30
  177. data/vendor/libsodium/test/default/pwhash_scrypt.c +349 -0
  178. data/vendor/libsodium/test/default/pwhash_scrypt.exp +31 -0
  179. data/vendor/libsodium/test/default/secretbox.c +1 -1
  180. data/vendor/libsodium/test/default/secretbox2.c +1 -1
  181. data/vendor/libsodium/test/default/sign.c +15 -0
  182. data/vendor/libsodium/test/default/sodium_utils2.c +8 -3
  183. data/vendor/libsodium/test/default/sodium_utils3.c +4 -2
  184. data/vendor/libsodium/test/default/verify1.c +0 -4
  185. data/vendor/libsodium/test/quirks/quirks.h +3 -0
  186. metadata +37 -22
  187. data/vendor/libsodium/builds/msvc/vs2010/test/test.props +0 -43
  188. data/vendor/libsodium/builds/msvc/vs2010/test/test.runner.bat +0 -78
  189. data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +0 -244
  190. data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +0 -192
  191. data/vendor/libsodium/builds/msvc/vs2012/test/test.props +0 -43
  192. data/vendor/libsodium/builds/msvc/vs2012/test/test.runner.bat +0 -78
  193. data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +0 -244
  194. data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +0 -192
  195. data/vendor/libsodium/builds/msvc/vs2013/test/test.props +0 -43
  196. data/vendor/libsodium/builds/msvc/vs2013/test/test.runner.bat +0 -78
  197. data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +0 -244
  198. data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +0 -192
  199. data/vendor/libsodium/builds/msvc/vs2015/test/test.props +0 -43
  200. data/vendor/libsodium/builds/msvc/vs2015/test/test.runner.bat +0 -78
  201. data/vendor/libsodium/builds/msvc/vs2015/test/test.vcxproj +0 -244
  202. data/vendor/libsodium/builds/msvc/vs2015/test/test.vcxproj.filters +0 -192
  203. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sysendian.h +0 -146
  204. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/common_aes128ctr.c +0 -64
@@ -129,7 +129,7 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen,
129
129
  return NULL;
130
130
  }
131
131
  src++;
132
- N = (uint64_t)1 << N_log2;
132
+ N = (uint64_t) 1 << N_log2;
133
133
 
134
134
  src = decode64_uint32(&r, 30, src);
135
135
  if (!src) {
@@ -50,13 +50,13 @@
50
50
  #define BYTES2CHARS(bytes) ((((bytes) * 8) + 5) / 6)
51
51
 
52
52
  typedef struct {
53
- void * base, * aligned;
54
- size_t size;
53
+ void * base, * aligned;
54
+ size_t size;
55
55
  } escrypt_region_t;
56
56
 
57
57
  typedef union {
58
- uint64_t d[8];
59
- uint32_t w[16];
58
+ uint64_t d[8];
59
+ uint32_t w[16];
60
60
  } escrypt_block_t;
61
61
 
62
62
  typedef escrypt_region_t escrypt_local_t;
@@ -35,64 +35,64 @@
35
35
  #include <string.h>
36
36
 
37
37
  #include "../pbkdf2-sha256.h"
38
- #include "../sysendian.h"
39
38
  #include "../crypto_scrypt.h"
39
+ #include "../../../sodium/common.h"
40
40
 
41
41
  static inline void
42
42
  blkcpy_64(escrypt_block_t *dest, const escrypt_block_t *src)
43
43
  {
44
- int i;
44
+ int i;
45
45
 
46
46
  #if (ARCH_BITS==32)
47
- for (i = 0; i < 16; ++i)
48
- dest->w[i] = src->w[i];
47
+ for (i = 0; i < 16; ++i)
48
+ dest->w[i] = src->w[i];
49
49
  #else
50
- for (i = 0; i < 8; ++i)
51
- dest->d[i] = src->d[i];
50
+ for (i = 0; i < 8; ++i)
51
+ dest->d[i] = src->d[i];
52
52
  #endif
53
53
  }
54
54
 
55
55
  static inline void
56
56
  blkxor_64(escrypt_block_t *dest, const escrypt_block_t *src)
57
57
  {
58
- int i;
58
+ int i;
59
59
 
60
60
  #if (ARCH_BITS==32)
61
- for (i = 0; i < 16; ++i)
62
- dest->w[i] ^= src->w[i];
61
+ for (i = 0; i < 16; ++i)
62
+ dest->w[i] ^= src->w[i];
63
63
  #else
64
- for (i = 0; i < 8; ++i)
65
- dest->d[i] ^= src->d[i];
64
+ for (i = 0; i < 8; ++i)
65
+ dest->d[i] ^= src->d[i];
66
66
  #endif
67
67
  }
68
68
 
69
69
  static inline void
70
70
  blkcpy(escrypt_block_t *dest, const escrypt_block_t *src, size_t len)
71
71
  {
72
- size_t i, L;
72
+ size_t i, L;
73
73
  #if (ARCH_BITS==32)
74
- L = (len>>2);
75
- for (i = 0; i < L; ++i)
76
- dest->w[i] = src->w[i];
74
+ L = (len>>2);
75
+ for (i = 0; i < L; ++i)
76
+ dest->w[i] = src->w[i];
77
77
  #else
78
- L = (len>>3);
79
- for (i = 0; i < L; ++i)
80
- dest->d[i] = src->d[i];
78
+ L = (len>>3);
79
+ for (i = 0; i < L; ++i)
80
+ dest->d[i] = src->d[i];
81
81
  #endif
82
82
  }
83
83
 
84
84
  static inline void
85
85
  blkxor(escrypt_block_t *dest, const escrypt_block_t *src, size_t len)
86
86
  {
87
- size_t i, L;
87
+ size_t i, L;
88
88
  #if (ARCH_BITS==32)
89
- L = (len>>2);
90
- for (i = 0; i < L; ++i)
91
- dest->w[i] ^= src->w[i];
89
+ L = (len>>2);
90
+ for (i = 0; i < L; ++i)
91
+ dest->w[i] ^= src->w[i];
92
92
  #else
93
- L = (len>>3);
94
- for (i = 0; i < L; ++i)
95
- dest->d[i] ^= src->d[i];
93
+ L = (len>>3);
94
+ for (i = 0; i < L; ++i)
95
+ dest->d[i] ^= src->d[i];
96
96
  #endif
97
97
  }
98
98
 
@@ -103,42 +103,42 @@ blkxor(escrypt_block_t *dest, const escrypt_block_t *src, size_t len)
103
103
  static void
104
104
  salsa20_8(uint32_t B[16])
105
105
  {
106
- escrypt_block_t X;
107
- uint32_t *x = X.w;
108
- size_t i;
106
+ escrypt_block_t X;
107
+ uint32_t *x = X.w;
108
+ size_t i;
109
109
 
110
- blkcpy_64(&X, (escrypt_block_t*)B);
111
- for (i = 0; i < 8; i += 2) {
110
+ blkcpy_64(&X, (escrypt_block_t*)B);
111
+ for (i = 0; i < 8; i += 2) {
112
112
  #define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
113
- /* Operate on columns. */
114
- x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
115
- x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
113
+ /* Operate on columns. */
114
+ x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
115
+ x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
116
116
 
117
- x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
118
- x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
117
+ x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
118
+ x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
119
119
 
120
- x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
121
- x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
120
+ x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
121
+ x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
122
122
 
123
- x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
124
- x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
123
+ x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
124
+ x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
125
125
 
126
- /* Operate on rows. */
127
- x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
128
- x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
126
+ /* Operate on rows. */
127
+ x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
128
+ x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
129
129
 
130
- x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
131
- x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
130
+ x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
131
+ x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
132
132
 
133
- x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
134
- x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
133
+ x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
134
+ x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
135
135
 
136
- x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
137
- x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
136
+ x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
137
+ x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
138
138
  #undef R
139
- }
140
- for (i = 0; i < 16; i++)
141
- B[i] += x[i];
139
+ }
140
+ for (i = 0; i < 16; i++)
141
+ B[i] += x[i];
142
142
  }
143
143
 
144
144
  /**
@@ -150,29 +150,29 @@ salsa20_8(uint32_t B[16])
150
150
  static void
151
151
  blockmix_salsa8(const uint32_t * Bin, uint32_t * Bout, uint32_t * X, size_t r)
152
152
  {
153
- size_t i;
153
+ size_t i;
154
154
 
155
- /* 1: X <-- B_{2r - 1} */
156
- blkcpy_64((escrypt_block_t*)X, (escrypt_block_t*)&Bin[(2 * r - 1) * 16]);
155
+ /* 1: X <-- B_{2r - 1} */
156
+ blkcpy_64((escrypt_block_t*)X, (escrypt_block_t*)&Bin[(2 * r - 1) * 16]);
157
157
 
158
- /* 2: for i = 0 to 2r - 1 do */
159
- for (i = 0; i < 2 * r; i += 2) {
160
- /* 3: X <-- H(X \xor B_i) */
161
- blkxor_64((escrypt_block_t*)X, (escrypt_block_t*)&Bin[i * 16]);
162
- salsa20_8(X);
158
+ /* 2: for i = 0 to 2r - 1 do */
159
+ for (i = 0; i < 2 * r; i += 2) {
160
+ /* 3: X <-- H(X \xor B_i) */
161
+ blkxor_64((escrypt_block_t*)X, (escrypt_block_t*)&Bin[i * 16]);
162
+ salsa20_8(X);
163
163
 
164
- /* 4: Y_i <-- X */
165
- /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
166
- blkcpy_64((escrypt_block_t*)&Bout[i * 8], (escrypt_block_t*)X);
164
+ /* 4: Y_i <-- X */
165
+ /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
166
+ blkcpy_64((escrypt_block_t*)&Bout[i * 8], (escrypt_block_t*)X);
167
167
 
168
- /* 3: X <-- H(X \xor B_i) */
169
- blkxor_64((escrypt_block_t*)X, (escrypt_block_t*)&Bin[i * 16 + 16]);
170
- salsa20_8(X);
168
+ /* 3: X <-- H(X \xor B_i) */
169
+ blkxor_64((escrypt_block_t*)X, (escrypt_block_t*)&Bin[i * 16 + 16]);
170
+ salsa20_8(X);
171
171
 
172
- /* 4: Y_i <-- X */
173
- /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
174
- blkcpy_64((escrypt_block_t*)&Bout[i * 8 + r * 16], (escrypt_block_t*)X);
175
- }
172
+ /* 4: Y_i <-- X */
173
+ /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
174
+ blkcpy_64((escrypt_block_t*)&Bout[i * 8 + r * 16], (escrypt_block_t*)X);
175
+ }
176
176
  }
177
177
 
178
178
  /**
@@ -182,9 +182,9 @@ blockmix_salsa8(const uint32_t * Bin, uint32_t * Bout, uint32_t * X, size_t r)
182
182
  static inline uint64_t
183
183
  integerify(const void * B, size_t r)
184
184
  {
185
- const uint32_t * X = (const uint32_t *)((uintptr_t)(B) + (2 * r - 1) * 64);
185
+ const uint32_t * X = (const uint32_t *)((uintptr_t)(B) + (2 * r - 1) * 64);
186
186
 
187
- return (((uint64_t)(X[1]) << 32) + X[0]);
187
+ return (((uint64_t)(X[1]) << 32) + X[0]);
188
188
  }
189
189
 
190
190
  /**
@@ -198,51 +198,51 @@ integerify(const void * B, size_t r)
198
198
  static void
199
199
  smix(uint8_t * B, size_t r, uint64_t N, uint32_t * V, uint32_t * XY)
200
200
  {
201
- uint32_t * X = XY;
202
- uint32_t * Y = &XY[32 * r];
203
- uint32_t * Z = &XY[64 * r];
204
- uint64_t i;
205
- uint64_t j;
206
- size_t k;
207
-
208
- /* 1: X <-- B */
209
- for (k = 0; k < 32 * r; k++)
210
- X[k] = le32dec(&B[4 * k]);
211
-
212
- /* 2: for i = 0 to N - 1 do */
213
- for (i = 0; i < N; i += 2) {
214
- /* 3: V_i <-- X */
215
- blkcpy((escrypt_block_t*)&V[i * (32 * r)], (escrypt_block_t*)X, 128 * r);
216
-
217
- /* 4: X <-- H(X) */
218
- blockmix_salsa8(X, Y, Z, r);
219
-
220
- /* 3: V_i <-- X */
221
- blkcpy((escrypt_block_t*)&V[(i + 1) * (32 * r)], (escrypt_block_t*)Y, 128 * r);
222
-
223
- /* 4: X <-- H(X) */
224
- blockmix_salsa8(Y, X, Z, r);
225
- }
226
-
227
- /* 6: for i = 0 to N - 1 do */
228
- for (i = 0; i < N; i += 2) {
229
- /* 7: j <-- Integerify(X) mod N */
230
- j = integerify(X, r) & (N - 1);
231
-
232
- /* 8: X <-- H(X \xor V_j) */
233
- blkxor((escrypt_block_t*)X, (escrypt_block_t*)&V[j * (32 * r)], 128 * r);
234
- blockmix_salsa8(X, Y, Z, r);
235
-
236
- /* 7: j <-- Integerify(X) mod N */
237
- j = integerify(Y, r) & (N - 1);
238
-
239
- /* 8: X <-- H(X \xor V_j) */
240
- blkxor((escrypt_block_t*)Y, (escrypt_block_t*)&V[j * (32 * r)], 128 * r);
241
- blockmix_salsa8(Y, X, Z, r);
242
- }
243
- /* 10: B' <-- X */
244
- for (k = 0; k < 32 * r; k++)
245
- le32enc(&B[4 * k], X[k]);
201
+ uint32_t * X = XY;
202
+ uint32_t * Y = &XY[32 * r];
203
+ uint32_t * Z = &XY[64 * r];
204
+ uint64_t i;
205
+ uint64_t j;
206
+ size_t k;
207
+
208
+ /* 1: X <-- B */
209
+ for (k = 0; k < 32 * r; k++)
210
+ X[k] = LOAD32_LE(&B[4 * k]);
211
+
212
+ /* 2: for i = 0 to N - 1 do */
213
+ for (i = 0; i < N; i += 2) {
214
+ /* 3: V_i <-- X */
215
+ blkcpy((escrypt_block_t*)&V[i * (32 * r)], (escrypt_block_t*)X, 128 * r);
216
+
217
+ /* 4: X <-- H(X) */
218
+ blockmix_salsa8(X, Y, Z, r);
219
+
220
+ /* 3: V_i <-- X */
221
+ blkcpy((escrypt_block_t*)&V[(i + 1) * (32 * r)], (escrypt_block_t*)Y, 128 * r);
222
+
223
+ /* 4: X <-- H(X) */
224
+ blockmix_salsa8(Y, X, Z, r);
225
+ }
226
+
227
+ /* 6: for i = 0 to N - 1 do */
228
+ for (i = 0; i < N; i += 2) {
229
+ /* 7: j <-- Integerify(X) mod N */
230
+ j = integerify(X, r) & (N - 1);
231
+
232
+ /* 8: X <-- H(X \xor V_j) */
233
+ blkxor((escrypt_block_t*)X, (escrypt_block_t*)&V[j * (32 * r)], 128 * r);
234
+ blockmix_salsa8(X, Y, Z, r);
235
+
236
+ /* 7: j <-- Integerify(X) mod N */
237
+ j = integerify(Y, r) & (N - 1);
238
+
239
+ /* 8: X <-- H(X \xor V_j) */
240
+ blkxor((escrypt_block_t*)Y, (escrypt_block_t*)&V[j * (32 * r)], 128 * r);
241
+ blockmix_salsa8(Y, X, Z, r);
242
+ }
243
+ /* 10: B' <-- X */
244
+ for (k = 0; k < 32 * r; k++)
245
+ STORE32_LE(&B[4 * k], X[k]);
246
246
  }
247
247
 
248
248
  /**
@@ -262,80 +262,80 @@ escrypt_kdf_nosse(escrypt_local_t * local,
262
262
  uint64_t N, uint32_t _r, uint32_t _p,
263
263
  uint8_t * buf, size_t buflen)
264
264
  {
265
- size_t B_size, V_size, XY_size, need;
266
- uint8_t * B;
267
- uint32_t * V, * XY;
265
+ size_t B_size, V_size, XY_size, need;
266
+ uint8_t * B;
267
+ uint32_t * V, * XY;
268
268
  size_t r = _r, p = _p;
269
- uint32_t i;
269
+ uint32_t i;
270
270
 
271
- /* Sanity-check parameters. */
271
+ /* Sanity-check parameters. */
272
272
  #if SIZE_MAX > UINT32_MAX
273
- if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
274
- errno = EFBIG;
275
- return -1;
276
- }
273
+ if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
274
+ errno = EFBIG;
275
+ return -1;
276
+ }
277
277
  #endif
278
- if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
279
- errno = EFBIG;
280
- return -1;
281
- }
282
- if (N > UINT32_MAX) {
283
- errno = EFBIG;
284
- return -1;
285
- }
286
- if (((N & (N - 1)) != 0) || (N < 2)) {
287
- errno = EINVAL;
288
- return -1;
289
- }
290
- if (r == 0 || p == 0) {
291
- errno = EINVAL;
292
- return -1;
293
- }
294
- if ((r > SIZE_MAX / 128 / p) ||
278
+ if ((uint64_t)(r) * (uint64_t)(p) >= ((uint64_t) 1 << 30)) {
279
+ errno = EFBIG;
280
+ return -1;
281
+ }
282
+ if (N > UINT32_MAX) {
283
+ errno = EFBIG;
284
+ return -1;
285
+ }
286
+ if (((N & (N - 1)) != 0) || (N < 2)) {
287
+ errno = EINVAL;
288
+ return -1;
289
+ }
290
+ if (r == 0 || p == 0) {
291
+ errno = EINVAL;
292
+ return -1;
293
+ }
294
+ if ((r > SIZE_MAX / 128 / p) ||
295
295
  #if SIZE_MAX / 256 <= UINT32_MAX
296
- (r > SIZE_MAX / 256) ||
296
+ (r > SIZE_MAX / 256) ||
297
297
  #endif
298
- (N > SIZE_MAX / 128 / r)) {
299
- errno = ENOMEM;
300
- return -1;
301
- }
302
-
303
- /* Allocate memory. */
304
- B_size = (size_t)128 * r * p;
305
- V_size = (size_t)128 * r * N;
306
- need = B_size + V_size;
307
- if (need < V_size) {
308
- errno = ENOMEM;
309
- return -1;
310
- }
311
- XY_size = (size_t)256 * r + 64;
312
- need += XY_size;
313
- if (need < XY_size) {
314
- errno = ENOMEM;
315
- return -1;
316
- }
317
- if (local->size < need) {
318
- if (free_region(local))
319
- return -1;
320
- if (!alloc_region(local, need))
321
- return -1;
322
- }
323
- B = (uint8_t *)local->aligned;
324
- V = (uint32_t *)((uint8_t *)B + B_size);
325
- XY = (uint32_t *)((uint8_t *)V + V_size);
326
-
327
- /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
328
- PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, B_size);
329
-
330
- /* 2: for i = 0 to p - 1 do */
331
- for (i = 0; i < p; i++) {
332
- /* 3: B_i <-- MF(B_i, N) */
333
- smix(&B[(size_t)128 * i * r], r, N, V, XY);
334
- }
335
-
336
- /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
337
- PBKDF2_SHA256(passwd, passwdlen, B, B_size, 1, buf, buflen);
338
-
339
- /* Success! */
340
- return 0;
298
+ (N > SIZE_MAX / 128 / r)) {
299
+ errno = ENOMEM;
300
+ return -1;
301
+ }
302
+
303
+ /* Allocate memory. */
304
+ B_size = (size_t)128 * r * p;
305
+ V_size = (size_t)128 * r * N;
306
+ need = B_size + V_size;
307
+ if (need < V_size) {
308
+ errno = ENOMEM;
309
+ return -1;
310
+ }
311
+ XY_size = (size_t)256 * r + 64;
312
+ need += XY_size;
313
+ if (need < XY_size) {
314
+ errno = ENOMEM;
315
+ return -1;
316
+ }
317
+ if (local->size < need) {
318
+ if (free_region(local))
319
+ return -1;
320
+ if (!alloc_region(local, need))
321
+ return -1;
322
+ }
323
+ B = (uint8_t *)local->aligned;
324
+ V = (uint32_t *)((uint8_t *)B + B_size);
325
+ XY = (uint32_t *)((uint8_t *)V + V_size);
326
+
327
+ /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
328
+ PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, B_size);
329
+
330
+ /* 2: for i = 0 to p - 1 do */
331
+ for (i = 0; i < p; i++) {
332
+ /* 3: B_i <-- MF(B_i, N) */
333
+ smix(&B[(size_t)128 * i * r], r, N, V, XY);
334
+ }
335
+
336
+ /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
337
+ PBKDF2_SHA256(passwd, passwdlen, B, B_size, 1, buf, buflen);
338
+
339
+ /* Success! */
340
+ return 0;
341
341
  }