rbnacl-libsodium 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rbnacl/libsodium/version.rb +1 -1
  3. data/vendor/libsodium/AUTHORS +14 -9
  4. data/vendor/libsodium/ChangeLog +26 -0
  5. data/vendor/libsodium/LICENSE +1 -1
  6. data/vendor/libsodium/Makefile.am +1 -0
  7. data/vendor/libsodium/README.markdown +185 -46
  8. data/vendor/libsodium/THANKS +10 -0
  9. data/vendor/libsodium/builds/msvc/properties/Common.props +21 -0
  10. data/vendor/libsodium/builds/msvc/properties/DLL.props +16 -0
  11. data/vendor/libsodium/builds/msvc/properties/Debug.props +29 -0
  12. data/vendor/libsodium/builds/msvc/properties/DebugDEXE.props +21 -0
  13. data/vendor/libsodium/builds/msvc/properties/DebugDLL.props +20 -0
  14. data/vendor/libsodium/builds/msvc/properties/DebugLEXE.props +20 -0
  15. data/vendor/libsodium/builds/msvc/properties/DebugLIB.props +20 -0
  16. data/vendor/libsodium/builds/msvc/properties/DebugLTCG.props +19 -0
  17. data/vendor/libsodium/builds/msvc/properties/DebugSEXE.props +21 -0
  18. data/vendor/libsodium/builds/msvc/properties/EXE.props +17 -0
  19. data/vendor/libsodium/builds/msvc/properties/LIB.props +16 -0
  20. data/vendor/libsodium/builds/msvc/properties/LTCG.props +13 -0
  21. data/vendor/libsodium/builds/msvc/properties/Link.props +21 -0
  22. data/vendor/libsodium/builds/msvc/properties/Messages.props +15 -0
  23. data/vendor/libsodium/builds/msvc/properties/Output.props +30 -0
  24. data/vendor/libsodium/builds/msvc/properties/Release.props +41 -0
  25. data/vendor/libsodium/builds/msvc/properties/ReleaseDEXE.props +20 -0
  26. data/vendor/libsodium/builds/msvc/properties/ReleaseDLL.props +19 -0
  27. data/vendor/libsodium/builds/msvc/properties/ReleaseLEXE.props +20 -0
  28. data/vendor/libsodium/builds/msvc/properties/ReleaseLIB.props +19 -0
  29. data/vendor/libsodium/builds/msvc/properties/ReleaseLTCG.props +19 -0
  30. data/vendor/libsodium/builds/msvc/properties/ReleaseSEXE.props +20 -0
  31. data/vendor/libsodium/builds/msvc/properties/Win32.props +20 -0
  32. data/vendor/libsodium/builds/msvc/properties/x64.props +23 -0
  33. data/vendor/libsodium/builds/msvc/resource.h +0 -0
  34. data/vendor/libsodium/builds/msvc/resource.rc +0 -0
  35. data/vendor/libsodium/builds/msvc/version.h +29 -0
  36. data/vendor/libsodium/builds/msvc/vs2010/libsodium.import.props +52 -0
  37. data/vendor/libsodium/builds/msvc/vs2010/libsodium.import.xml +17 -0
  38. data/vendor/libsodium/builds/msvc/vs2010/libsodium.sln +79 -0
  39. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.props +43 -0
  40. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +345 -0
  41. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +1037 -0
  42. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.xml +15 -0
  43. data/vendor/libsodium/builds/msvc/vs2010/test/test.props +37 -0
  44. data/vendor/libsodium/builds/msvc/vs2010/test/test.runner.bat +78 -0
  45. data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +220 -0
  46. data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +168 -0
  47. data/vendor/libsodium/builds/msvc/vs2012/libsodium.import.props +52 -0
  48. data/vendor/libsodium/builds/msvc/vs2012/libsodium.import.xml +17 -0
  49. data/vendor/libsodium/builds/msvc/vs2012/libsodium.sln +79 -0
  50. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.props +43 -0
  51. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +345 -0
  52. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +1037 -0
  53. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.xml +15 -0
  54. data/vendor/libsodium/builds/msvc/vs2012/test/test.props +37 -0
  55. data/vendor/libsodium/builds/msvc/vs2012/test/test.runner.bat +78 -0
  56. data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +220 -0
  57. data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +168 -0
  58. data/vendor/libsodium/builds/msvc/vs2013/libsodium.import.props +52 -0
  59. data/vendor/libsodium/builds/msvc/vs2013/libsodium.import.xml +17 -0
  60. data/vendor/libsodium/builds/msvc/vs2013/libsodium.sln +81 -0
  61. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.props +43 -0
  62. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +345 -0
  63. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +1037 -0
  64. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.xml +15 -0
  65. data/vendor/libsodium/builds/msvc/vs2013/test/test.props +37 -0
  66. data/vendor/libsodium/builds/msvc/vs2013/test/test.runner.bat +78 -0
  67. data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +220 -0
  68. data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +168 -0
  69. data/vendor/libsodium/configure.ac +87 -68
  70. data/vendor/libsodium/dist-build/Makefile.am +10 -0
  71. data/vendor/libsodium/dist-build/android-arm.sh +3 -0
  72. data/vendor/libsodium/dist-build/android-armv7.sh +3 -0
  73. data/vendor/libsodium/dist-build/android-build.sh +37 -0
  74. data/vendor/libsodium/dist-build/android-mips.sh +3 -0
  75. data/vendor/libsodium/dist-build/android-x86.sh +3 -0
  76. data/vendor/libsodium/dist-build/emscripten.sh +13 -0
  77. data/vendor/libsodium/dist-build/{iphone.sh → ios.sh} +2 -2
  78. data/vendor/libsodium/dist-build/msys2-win32.sh +10 -0
  79. data/vendor/libsodium/dist-build/msys2-win64.sh +10 -0
  80. data/vendor/libsodium/libsodium.vcxproj +25 -13
  81. data/vendor/libsodium/libsodium.vcxproj.filters +60 -24
  82. data/vendor/libsodium/msvc-scripts/process.bat +3 -7
  83. data/vendor/libsodium/packaging/nuget/package.bat +13 -0
  84. data/vendor/libsodium/packaging/nuget/package.config +4 -0
  85. data/vendor/libsodium/packaging/nuget/package.gsl +255 -0
  86. data/vendor/libsodium/packaging/nuget/package.nuspec +93 -0
  87. data/vendor/libsodium/packaging/nuget/package.targets +128 -0
  88. data/vendor/libsodium/packaging/nuget/package.xml +22 -0
  89. data/vendor/libsodium/src/libsodium/Makefile.am +32 -20
  90. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/auth_hmacsha256_api.c +0 -5
  91. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/{ref → cp}/api.h +0 -1
  92. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/cp/hmac_hmacsha256.c +110 -0
  93. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/{ref → cp}/verify_hmacsha256.c +0 -0
  94. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/auth_hmacsha512_api.c +11 -0
  95. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/cp/api.h +9 -0
  96. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/cp/hmac_hmacsha512.c +110 -0
  97. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/cp/verify_hmacsha512.c +10 -0
  98. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/auth_hmacsha512256_api.c +0 -5
  99. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/{ref → cp}/api.h +0 -1
  100. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/cp/hmac_hmacsha512256.c +54 -0
  101. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/{ref → cp}/verify_hmacsha512256.c +2 -1
  102. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +94 -0
  103. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305_api.c +0 -5
  104. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/api.h +0 -1
  105. data/vendor/libsodium/src/libsodium/crypto_core/hsalsa20/core_hsalsa20_api.c +0 -5
  106. data/vendor/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/api.h +0 -1
  107. data/vendor/libsodium/src/libsodium/crypto_core/salsa20/core_salsa20_api.c +0 -5
  108. data/vendor/libsodium/src/libsodium/crypto_core/salsa20/ref/api.h +0 -1
  109. data/vendor/libsodium/src/libsodium/crypto_core/salsa2012/core_salsa2012_api.c +0 -5
  110. data/vendor/libsodium/src/libsodium/crypto_core/salsa2012/ref/api.h +0 -1
  111. data/vendor/libsodium/src/libsodium/crypto_core/salsa208/core_salsa208_api.c +0 -5
  112. data/vendor/libsodium/src/libsodium/crypto_core/salsa208/ref/api.h +0 -1
  113. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/generichash_blake2_api.c +15 -5
  114. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/api.h +0 -2
  115. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2.h +14 -6
  116. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +95 -0
  117. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c +50 -3
  118. data/vendor/libsodium/src/libsodium/crypto_generichash/crypto_generichash.c +4 -10
  119. data/vendor/libsodium/src/libsodium/crypto_hash/crypto_hash.c +11 -0
  120. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/{ref → cp}/api.h +3 -1
  121. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +294 -0
  122. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/hash_sha256_api.c +0 -5
  123. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/{ref → cp}/api.h +3 -1
  124. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +321 -0
  125. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/hash_sha512_api.c +0 -5
  126. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c +51 -127
  127. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h +12 -0
  128. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +221 -0
  129. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +209 -0
  130. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_api.c +0 -5
  131. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c +1 -140
  132. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/crypto_scrypt-common.c +250 -0
  133. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/crypto_scrypt.h +100 -0
  134. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/nosse/pwhash_scryptxsalsa208sha256_nosse.c +302 -0
  135. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/pbkdf2-sha256.c +94 -0
  136. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/pbkdf2-sha256.h +45 -0
  137. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/pwhash_scryptxsalsa208sha256.c +172 -0
  138. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/scrypt_platform.c +96 -0
  139. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sse/pwhash_scryptxsalsa208sha256_sse.c +391 -0
  140. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptxsalsa208sha256/sysendian.h +146 -0
  141. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/api.h +2 -2
  142. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/smult_curve25519_donna_c64.c +39 -9
  143. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref/api.h +2 -2
  144. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox.c +6 -0
  145. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +94 -0
  146. data/vendor/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/ref/api.h +0 -1
  147. data/vendor/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305_api.c +3 -3
  148. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/api.h +0 -1
  149. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/shorthash_siphash24_api.c +3 -3
  150. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/api.h +0 -1
  151. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_scalarmult_base.c +6 -0
  152. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +5 -3
  153. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +28 -18
  154. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +14 -9
  155. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519_api.c +0 -5
  156. data/vendor/libsodium/src/libsodium/crypto_sign/edwards25519sha512batch/ref/api.h +0 -1
  157. data/vendor/libsodium/src/libsodium/crypto_sign/edwards25519sha512batch/sign_edwards25519sha512batch_api.c +0 -5
  158. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/afternm_aes128ctr.c +21 -21
  159. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/api.h +0 -1
  160. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128.h +6 -0
  161. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/xor_afternm_aes128ctr.c +42 -42
  162. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/stream_aes128ctr_api.c +0 -5
  163. data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/aes-table-be.h +4 -4
  164. data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/aes-table-le.h +4 -4
  165. data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/aes256-ctr.c +15 -14
  166. data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/api.h +0 -1
  167. data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/ecrypt-sync.h +1 -1
  168. data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/stream_aes256estream_api.c +0 -5
  169. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S +153 -160
  170. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/api.h +2 -5
  171. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c +9 -3
  172. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +9 -3
  173. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20_api.c +0 -5
  174. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/api.h +0 -1
  175. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/stream_salsa2012_api.c +0 -5
  176. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/api.h +0 -1
  177. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/stream_salsa208_api.c +0 -5
  178. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/api.h +0 -1
  179. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20_api.c +0 -5
  180. data/vendor/libsodium/src/libsodium/crypto_verify/64/ref/api.h +2 -0
  181. data/vendor/libsodium/src/libsodium/crypto_verify/64/ref/verify_64.c +72 -0
  182. data/vendor/libsodium/src/libsodium/crypto_verify/64/verify_64_api.c +6 -0
  183. data/vendor/libsodium/src/libsodium/include/Makefile.am +6 -7
  184. data/vendor/libsodium/src/libsodium/include/sodium.h +4 -3
  185. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth.h +3 -0
  186. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha256.h +31 -9
  187. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha512.h +58 -0
  188. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha512256.h +26 -9
  189. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +13 -0
  190. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +38 -24
  191. data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_hsalsa20.h +6 -11
  192. data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_salsa20.h +6 -11
  193. data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_salsa2012.h +6 -11
  194. data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_salsa208.h +6 -11
  195. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash.h +7 -8
  196. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash_blake2b.h +36 -16
  197. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash.h +13 -4
  198. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha256.h +25 -7
  199. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha512.h +25 -7
  200. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth.h +3 -0
  201. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +5 -5
  202. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305_donna.h +3 -0
  203. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptxsalsa208sha256.h +48 -0
  204. data/vendor/libsodium/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h +31 -0
  205. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +17 -0
  206. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +21 -11
  207. data/vendor/libsodium/src/libsodium/include/sodium/crypto_shorthash.h +3 -0
  208. data/vendor/libsodium/src/libsodium/include/sodium/crypto_shorthash_siphash24.h +8 -7
  209. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign.h +3 -0
  210. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +16 -17
  211. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +18 -14
  212. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream.h +3 -0
  213. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes128ctr.h +18 -18
  214. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes256estream.h +19 -18
  215. data/vendor/libsodium/src/libsodium/include/sodium/{crypto_stream_salsa20.h.in → crypto_stream_salsa20.h} +8 -19
  216. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa2012.h +8 -8
  217. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa208.h +8 -8
  218. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xsalsa20.h +10 -11
  219. data/vendor/libsodium/src/libsodium/include/sodium/crypto_verify_16.h +1 -4
  220. data/vendor/libsodium/src/libsodium/include/sodium/crypto_verify_32.h +1 -4
  221. data/vendor/libsodium/src/libsodium/include/sodium/crypto_verify_64.h +22 -0
  222. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +3 -0
  223. data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +27 -0
  224. data/vendor/libsodium/src/libsodium/include/sodium/utils.h +15 -3
  225. data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +3 -1
  226. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +18 -7
  227. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +57 -9
  228. data/vendor/libsodium/src/libsodium/sodium/compat.c +62 -0
  229. data/vendor/libsodium/src/libsodium/sodium/core.c +2 -0
  230. data/vendor/libsodium/src/libsodium/sodium/runtime.c +134 -0
  231. data/vendor/libsodium/src/libsodium/sodium/utils.c +100 -8
  232. data/vendor/libsodium/test/default/Makefile.am +63 -3
  233. data/vendor/libsodium/test/default/auth6.c +21 -0
  234. data/vendor/libsodium/test/default/auth6.exp +8 -0
  235. data/vendor/libsodium/test/default/auth7.c +37 -0
  236. data/vendor/libsodium/test/default/auth7.exp +0 -0
  237. data/vendor/libsodium/test/default/box_easy.c +59 -0
  238. data/vendor/libsodium/test/default/box_easy.exp +19 -0
  239. data/vendor/libsodium/test/default/box_easy2.c +31 -0
  240. data/vendor/libsodium/test/default/box_easy2.exp +1 -0
  241. data/vendor/libsodium/test/default/cmptest.h +7 -1
  242. data/vendor/libsodium/test/default/generichash3.c +36 -0
  243. data/vendor/libsodium/test/default/generichash3.exp +64 -0
  244. data/vendor/libsodium/test/default/pwhash.c +59 -0
  245. data/vendor/libsodium/test/default/pwhash.exp +2 -0
  246. data/vendor/libsodium/test/default/scalarmult7.c +0 -2
  247. data/vendor/libsodium/test/default/scalarmult8.c +0 -2
  248. data/vendor/libsodium/test/default/secretbox_easy.c +51 -0
  249. data/vendor/libsodium/test/default/secretbox_easy.exp +19 -0
  250. data/vendor/libsodium/test/default/secretbox_easy2.c +27 -0
  251. data/vendor/libsodium/test/default/secretbox_easy2.exp +1 -0
  252. data/vendor/libsodium/test/default/sign.c +1106 -0
  253. data/vendor/libsodium/test/default/sign.exp +3 -0
  254. data/vendor/libsodium/test/default/sodium_utils.c +8 -0
  255. data/vendor/libsodium/test/default/sodium_utils.exp +2 -1
  256. data/vendor/libsodium/test/default/sodium_version.c +1 -1
  257. data/vendor/libsodium/test/default/verify1.c +34 -0
  258. data/vendor/libsodium/test/default/verify1.exp +6 -0
  259. metadata +138 -33
  260. data/vendor/libsodium/dist-build/android.sh +0 -48
  261. data/vendor/libsodium/dist-build/msys.sh +0 -9
  262. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/ref/hmac_hmacsha256.c +0 -83
  263. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/ref/hmac_hmacsha512256.c +0 -86
  264. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/ref/hash_sha256.c +0 -69
  265. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/ref/hash_sha512.c +0 -71
  266. data/vendor/libsodium/src/libsodium/crypto_hashblocks/sha256/checksum +0 -1
  267. data/vendor/libsodium/src/libsodium/crypto_hashblocks/sha256/hashblocks_sha256_api.c +0 -16
  268. data/vendor/libsodium/src/libsodium/crypto_hashblocks/sha256/ref/api.h +0 -9
  269. data/vendor/libsodium/src/libsodium/crypto_hashblocks/sha256/ref/blocks_sha256.c +0 -212
  270. data/vendor/libsodium/src/libsodium/crypto_hashblocks/sha512/checksum +0 -1
  271. data/vendor/libsodium/src/libsodium/crypto_hashblocks/sha512/hashblocks_sha512_api.c +0 -16
  272. data/vendor/libsodium/src/libsodium/crypto_hashblocks/sha512/ref/api.h +0 -9
  273. data/vendor/libsodium/src/libsodium/crypto_hashblocks/sha512/ref/blocks_sha512.c +0 -239
  274. data/vendor/libsodium/src/libsodium/crypto_hashblocks/try.c +0 -78
  275. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/53/api.h +0 -8
  276. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/53/auth_poly1305_53.c +0 -1661
  277. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/53/verify_poly1305_53.c +0 -10
  278. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/portable-jane.h +0 -772
  279. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hashblocks_sha256.h +0 -32
  280. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hashblocks_sha512.h +0 -32
  281. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305_53.h +0 -34
  282. data/vendor/libsodium/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h.in +0 -44
@@ -0,0 +1,302 @@
1
+ /*-
2
+ * Copyright 2009 Colin Percival
3
+ * Copyright 2013 Alexander Peslyak
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
+ * SUCH DAMAGE.
26
+ *
27
+ * This file was originally written by Colin Percival as part of the Tarsnap
28
+ * online backup system.
29
+ */
30
+
31
+ #include <errno.h>
32
+ #include <limits.h>
33
+ #include <stdint.h>
34
+ #include <stdlib.h>
35
+ #include <string.h>
36
+
37
+ #include "../pbkdf2-sha256.h"
38
+ #include "../sysendian.h"
39
+ #include "../crypto_scrypt.h"
40
+
41
+ static inline void
42
+ blkcpy(void * dest, const void * src, size_t len)
43
+ {
44
+ size_t * D = (size_t *) dest;
45
+ const size_t * S = (const size_t *) src;
46
+ size_t L = len / sizeof(size_t);
47
+ size_t i;
48
+
49
+ for (i = 0; i < L; i++)
50
+ D[i] = S[i];
51
+ }
52
+
53
+ static inline void
54
+ blkxor(void * dest, const void * src, size_t len)
55
+ {
56
+ size_t * D = (size_t *) dest;
57
+ const size_t * S = (const size_t *) src;
58
+ size_t L = len / sizeof(size_t);
59
+ size_t i;
60
+
61
+ for (i = 0; i < L; i++)
62
+ D[i] ^= S[i];
63
+ }
64
+
65
+ /**
66
+ * salsa20_8(B):
67
+ * Apply the salsa20/8 core to the provided block.
68
+ */
69
+ static void
70
+ salsa20_8(uint32_t B[16])
71
+ {
72
+ uint32_t x[16];
73
+ size_t i;
74
+
75
+ blkcpy(x, B, 64);
76
+ for (i = 0; i < 8; i += 2) {
77
+ #define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
78
+ /* Operate on columns. */
79
+ x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
80
+ x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
81
+
82
+ x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
83
+ x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
84
+
85
+ x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
86
+ x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
87
+
88
+ x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
89
+ x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
90
+
91
+ /* Operate on rows. */
92
+ x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
93
+ x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
94
+
95
+ x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
96
+ x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
97
+
98
+ x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
99
+ x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
100
+
101
+ x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
102
+ x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
103
+ #undef R
104
+ }
105
+ for (i = 0; i < 16; i++)
106
+ B[i] += x[i];
107
+ }
108
+
109
+ /**
110
+ * blockmix_salsa8(Bin, Bout, X, r):
111
+ * Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r
112
+ * bytes in length; the output Bout must also be the same size. The
113
+ * temporary space X must be 64 bytes.
114
+ */
115
+ static void
116
+ blockmix_salsa8(const uint32_t * Bin, uint32_t * Bout, uint32_t * X, size_t r)
117
+ {
118
+ size_t i;
119
+
120
+ /* 1: X <-- B_{2r - 1} */
121
+ blkcpy(X, &Bin[(2 * r - 1) * 16], 64);
122
+
123
+ /* 2: for i = 0 to 2r - 1 do */
124
+ for (i = 0; i < 2 * r; i += 2) {
125
+ /* 3: X <-- H(X \xor B_i) */
126
+ blkxor(X, &Bin[i * 16], 64);
127
+ salsa20_8(X);
128
+
129
+ /* 4: Y_i <-- X */
130
+ /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
131
+ blkcpy(&Bout[i * 8], X, 64);
132
+
133
+ /* 3: X <-- H(X \xor B_i) */
134
+ blkxor(X, &Bin[i * 16 + 16], 64);
135
+ salsa20_8(X);
136
+
137
+ /* 4: Y_i <-- X */
138
+ /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
139
+ blkcpy(&Bout[i * 8 + r * 16], X, 64);
140
+ }
141
+ }
142
+
143
+ /**
144
+ * integerify(B, r):
145
+ * Return the result of parsing B_{2r-1} as a little-endian integer.
146
+ */
147
+ static inline uint64_t
148
+ integerify(const void * B, size_t r)
149
+ {
150
+ const uint32_t * X = (const uint32_t *)((uintptr_t)(B) + (2 * r - 1) * 64);
151
+
152
+ return (((uint64_t)(X[1]) << 32) + X[0]);
153
+ }
154
+
155
+ /**
156
+ * smix(B, r, N, V, XY):
157
+ * Compute B = SMix_r(B, N). The input B must be 128r bytes in length;
158
+ * the temporary storage V must be 128rN bytes in length; the temporary
159
+ * storage XY must be 256r + 64 bytes in length. The value N must be a
160
+ * power of 2 greater than 1. The arrays B, V, and XY must be aligned to a
161
+ * multiple of 64 bytes.
162
+ */
163
+ static void
164
+ smix(uint8_t * B, size_t r, uint64_t N, uint32_t * V, uint32_t * XY)
165
+ {
166
+ uint32_t * X = XY;
167
+ uint32_t * Y = &XY[32 * r];
168
+ uint32_t * Z = &XY[64 * r];
169
+ uint64_t i;
170
+ uint64_t j;
171
+ size_t k;
172
+
173
+ /* 1: X <-- B */
174
+ for (k = 0; k < 32 * r; k++)
175
+ X[k] = le32dec(&B[4 * k]);
176
+
177
+ /* 2: for i = 0 to N - 1 do */
178
+ for (i = 0; i < N; i += 2) {
179
+ /* 3: V_i <-- X */
180
+ blkcpy(&V[i * (32 * r)], X, 128 * r);
181
+
182
+ /* 4: X <-- H(X) */
183
+ blockmix_salsa8(X, Y, Z, r);
184
+
185
+ /* 3: V_i <-- X */
186
+ blkcpy(&V[(i + 1) * (32 * r)], Y, 128 * r);
187
+
188
+ /* 4: X <-- H(X) */
189
+ blockmix_salsa8(Y, X, Z, r);
190
+ }
191
+
192
+ /* 6: for i = 0 to N - 1 do */
193
+ for (i = 0; i < N; i += 2) {
194
+ /* 7: j <-- Integerify(X) mod N */
195
+ j = integerify(X, r) & (N - 1);
196
+
197
+ /* 8: X <-- H(X \xor V_j) */
198
+ blkxor(X, &V[j * (32 * r)], 128 * r);
199
+ blockmix_salsa8(X, Y, Z, r);
200
+
201
+ /* 7: j <-- Integerify(X) mod N */
202
+ j = integerify(Y, r) & (N - 1);
203
+
204
+ /* 8: X <-- H(X \xor V_j) */
205
+ blkxor(Y, &V[j * (32 * r)], 128 * r);
206
+ blockmix_salsa8(Y, X, Z, r);
207
+ }
208
+ /* 10: B' <-- X */
209
+ for (k = 0; k < 32 * r; k++)
210
+ le32enc(&B[4 * k], X[k]);
211
+ }
212
+
213
+ /**
214
+ * escrypt_kdf(local, passwd, passwdlen, salt, saltlen,
215
+ * N, r, p, buf, buflen):
216
+ * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
217
+ * p, buflen) and write the result into buf. The parameters r, p, and buflen
218
+ * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N
219
+ * must be a power of 2 greater than 1.
220
+ *
221
+ * Return 0 on success; or -1 on error.
222
+ */
223
+ int
224
+ escrypt_kdf_nosse(escrypt_local_t * local,
225
+ const uint8_t * passwd, size_t passwdlen,
226
+ const uint8_t * salt, size_t saltlen,
227
+ uint64_t N, uint32_t _r, uint32_t _p,
228
+ uint8_t * buf, size_t buflen)
229
+ {
230
+ size_t B_size, V_size, XY_size, need;
231
+ uint8_t * B;
232
+ uint32_t * V, * XY;
233
+ size_t r = _r, p = _p;
234
+ uint32_t i;
235
+
236
+ /* Sanity-check parameters. */
237
+ #if SIZE_MAX > UINT32_MAX
238
+ if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
239
+ errno = EFBIG;
240
+ return -1;
241
+ }
242
+ #endif
243
+ if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
244
+ errno = EFBIG;
245
+ return -1;
246
+ }
247
+ if (((N & (N - 1)) != 0) || (N < 2)) {
248
+ errno = EINVAL;
249
+ return -1;
250
+ }
251
+ if (r == 0 || p == 0) {
252
+ errno = EINVAL;
253
+ return -1;
254
+ }
255
+ if ((r > SIZE_MAX / 128 / p) ||
256
+ #if SIZE_MAX / 256 <= UINT32_MAX
257
+ (r > SIZE_MAX / 256) ||
258
+ #endif
259
+ (N > SIZE_MAX / 128 / r)) {
260
+ errno = ENOMEM;
261
+ return -1;
262
+ }
263
+
264
+ /* Allocate memory. */
265
+ B_size = (size_t)128 * r * p;
266
+ V_size = (size_t)128 * r * N;
267
+ need = B_size + V_size;
268
+ if (need < V_size) {
269
+ errno = ENOMEM;
270
+ return -1;
271
+ }
272
+ XY_size = (size_t)256 * r + 64;
273
+ need += XY_size;
274
+ if (need < XY_size) {
275
+ errno = ENOMEM;
276
+ return -1;
277
+ }
278
+ if (local->size < need) {
279
+ if (free_region(local))
280
+ return -1;
281
+ if (!alloc_region(local, need))
282
+ return -1;
283
+ }
284
+ B = (uint8_t *)local->aligned;
285
+ V = (uint32_t *)((uint8_t *)B + B_size);
286
+ XY = (uint32_t *)((uint8_t *)V + V_size);
287
+
288
+ /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
289
+ PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, B_size);
290
+
291
+ /* 2: for i = 0 to p - 1 do */
292
+ for (i = 0; i < p; i++) {
293
+ /* 3: B_i <-- MF(B_i, N) */
294
+ smix(&B[(size_t)128 * i * r], r, N, V, XY);
295
+ }
296
+
297
+ /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
298
+ PBKDF2_SHA256(passwd, passwdlen, B, B_size, 1, buf, buflen);
299
+
300
+ /* Success! */
301
+ return 0;
302
+ }
@@ -0,0 +1,94 @@
1
+ /*-
2
+ * Copyright 2005,2007,2009 Colin Percival
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright
11
+ * notice, this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ *
14
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ * SUCH DAMAGE.
25
+ */
26
+
27
+ #include <sys/types.h>
28
+
29
+ #include <stdint.h>
30
+ #include <stdlib.h>
31
+ #include <string.h>
32
+
33
+ #include "crypto_auth_hmacsha256.h"
34
+ #include "pbkdf2-sha256.h"
35
+ #include "utils.h"
36
+
37
+ static inline void
38
+ be32enc(void *pp, uint32_t x)
39
+ {
40
+ uint8_t * p = (uint8_t *)pp;
41
+
42
+ p[3] = x & 0xff;
43
+ p[2] = (x >> 8) & 0xff;
44
+ p[1] = (x >> 16) & 0xff;
45
+ p[0] = (x >> 24) & 0xff;
46
+ }
47
+
48
+ /**
49
+ * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):
50
+ * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and
51
+ * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1).
52
+ */
53
+ void
54
+ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
55
+ size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen)
56
+ {
57
+ crypto_auth_hmacsha256_state PShctx, hctx;
58
+ size_t i;
59
+ uint8_t ivec[4];
60
+ uint8_t U[32];
61
+ uint8_t T[32];
62
+ uint64_t j;
63
+ int k;
64
+ size_t clen;
65
+
66
+ crypto_auth_hmacsha256_init(&PShctx, passwd, passwdlen);
67
+ crypto_auth_hmacsha256_update(&PShctx, salt, saltlen);
68
+
69
+ for (i = 0; i * 32 < dkLen; i++) {
70
+ be32enc(ivec, (uint32_t)(i + 1));
71
+ memcpy(&hctx, &PShctx, sizeof(crypto_auth_hmacsha256_state));
72
+ crypto_auth_hmacsha256_update(&hctx, ivec, 4);
73
+ crypto_auth_hmacsha256_final(&hctx, U);
74
+
75
+ memcpy(T, U, 32);
76
+
77
+ for (j = 2; j <= c; j++) {
78
+ crypto_auth_hmacsha256_init(&hctx, passwd, passwdlen);
79
+ crypto_auth_hmacsha256_update(&hctx, U, 32);
80
+ crypto_auth_hmacsha256_final(&hctx, U);
81
+
82
+ for (k = 0; k < 32; k++) {
83
+ T[k] ^= U[k];
84
+ }
85
+ }
86
+
87
+ clen = dkLen - i * 32;
88
+ if (clen > 32) {
89
+ clen = 32;
90
+ }
91
+ memcpy(&buf[i * 32], T, clen);
92
+ }
93
+ sodium_memzero((void *) &PShctx, sizeof PShctx);
94
+ }
@@ -0,0 +1,45 @@
1
+ /*-
2
+ * Copyright 2005,2007,2009 Colin Percival
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright
11
+ * notice, this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ *
14
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ * SUCH DAMAGE.
25
+ *
26
+ */
27
+
28
+ #ifndef _SHA256_H_
29
+ #define _SHA256_H_
30
+
31
+ #include <sys/types.h>
32
+
33
+ #include <stdint.h>
34
+
35
+ #include "crypto_auth_hmacsha256.h"
36
+
37
+ /**
38
+ * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):
39
+ * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and
40
+ * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1).
41
+ */
42
+ void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t,
43
+ uint64_t, uint8_t *, size_t);
44
+
45
+ #endif /* !_SHA256_H_ */
@@ -0,0 +1,172 @@
1
+
2
+ #include <errno.h>
3
+ #include <limits.h>
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+ #include <string.h>
7
+
8
+ #include "crypto_pwhash_scryptxsalsa208sha256.h"
9
+ #include "crypto_scrypt.h"
10
+ #include "randombytes.h"
11
+ #include "utils.h"
12
+
13
+ #define SETTING_SIZE(saltbytes) \
14
+ (sizeof "$7$" - 1U) + \
15
+ (1U /* N_log2 */) + (5U /* r */) + (5U /* p */) + BYTES2CHARS(saltbytes)
16
+
17
+ static int
18
+ pickparams(unsigned long long opslimit, const size_t memlimit,
19
+ uint32_t * const N_log2, uint32_t * const p, uint32_t * const r)
20
+ {
21
+ unsigned long long maxN;
22
+ unsigned long long maxrp;
23
+
24
+ if (opslimit < 32768) {
25
+ opslimit = 32768;
26
+ }
27
+ *r = 8;
28
+ if (opslimit < memlimit / 32) {
29
+ *p = 1;
30
+ maxN = opslimit / (*r * 4);
31
+ for (*N_log2 = 1; *N_log2 < 63; *N_log2 += 1) {
32
+ if ((uint64_t)(1) << *N_log2 > maxN / 2) {
33
+ break;
34
+ }
35
+ }
36
+ } else {
37
+ maxN = memlimit / (*r * 128);
38
+ for (*N_log2 = 1; *N_log2 < 63; *N_log2 += 1) {
39
+ if ((uint64_t) (1) << *N_log2 > maxN / 2) {
40
+ break;
41
+ }
42
+ }
43
+ maxrp = (opslimit / 4) / ((uint64_t) (1) << *N_log2);
44
+ if (maxrp > 0x3fffffff) {
45
+ maxrp = 0x3fffffff;
46
+ }
47
+ *p = (uint32_t) (maxrp) / *r;
48
+ }
49
+ return 0;
50
+ }
51
+
52
+ size_t
53
+ crypto_pwhash_scryptxsalsa208sha256_saltbytes(void)
54
+ {
55
+ return crypto_pwhash_scryptxsalsa208sha256_SALTBYTES;
56
+ }
57
+
58
+ size_t
59
+ crypto_pwhash_scryptxsalsa208sha256_strbytes(void)
60
+ {
61
+ return crypto_pwhash_scryptxsalsa208sha256_STRBYTES;
62
+ }
63
+
64
+ int
65
+ crypto_pwhash_scryptxsalsa208sha256(unsigned char * const out,
66
+ unsigned long long outlen,
67
+ const char * const passwd,
68
+ unsigned long long passwdlen,
69
+ const unsigned char * const salt,
70
+ unsigned long long opslimit,
71
+ size_t memlimit)
72
+ {
73
+ uint32_t N_log2;
74
+ uint32_t p;
75
+ uint32_t r;
76
+
77
+ memset(out, 0, outlen);
78
+ if (passwdlen > SIZE_MAX || outlen > SIZE_MAX) {
79
+ errno = EFBIG;
80
+ return -1;
81
+ }
82
+ if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) {
83
+ errno = EINVAL;
84
+ return -1;
85
+ }
86
+ return crypto_scrypt_compat((const uint8_t *) passwd, (size_t) passwdlen,
87
+ (const uint8_t *) salt,
88
+ crypto_pwhash_scryptxsalsa208sha256_SALTBYTES,
89
+ (uint64_t) (1) << N_log2, r, p,
90
+ out, (size_t) outlen);
91
+ }
92
+
93
+ int
94
+ crypto_pwhash_scryptxsalsa208sha256_str(char out[crypto_pwhash_scryptxsalsa208sha256_STRBYTES],
95
+ const char * const passwd,
96
+ unsigned long long passwdlen,
97
+ unsigned long long opslimit,
98
+ size_t memlimit)
99
+ {
100
+ uint8_t salt[crypto_pwhash_scryptxsalsa208sha256_STRSALTBYTES];
101
+ char setting[crypto_pwhash_scryptxsalsa208sha256_STRSETTINGBYTES + 1U];
102
+ escrypt_local_t escrypt_local;
103
+ uint32_t N_log2;
104
+ uint32_t p;
105
+ uint32_t r;
106
+
107
+ memset(out, 0, crypto_pwhash_scryptxsalsa208sha256_STRBYTES);
108
+ if (passwdlen > SIZE_MAX) {
109
+ errno = EFBIG;
110
+ return -1;
111
+ }
112
+ if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) {
113
+ errno = EINVAL;
114
+ return -1;
115
+ }
116
+ randombytes_buf(salt, sizeof salt);
117
+ if (escrypt_gensalt_r(N_log2, r, p, salt, sizeof salt,
118
+ (uint8_t *) setting, sizeof setting) == NULL) {
119
+ errno = EINVAL;
120
+ return -1;
121
+ }
122
+ if (escrypt_init_local(&escrypt_local) != 0) {
123
+ return -1;
124
+ }
125
+ if (escrypt_r(&escrypt_local, (const uint8_t *) passwd, (size_t) passwdlen,
126
+ (const uint8_t *) setting, (uint8_t *) out,
127
+ crypto_pwhash_scryptxsalsa208sha256_STRBYTES) == NULL) {
128
+ escrypt_free_local(&escrypt_local);
129
+ errno = EINVAL;
130
+ return -1;
131
+ }
132
+ escrypt_free_local(&escrypt_local);
133
+
134
+ (void) sizeof
135
+ (int[SETTING_SIZE(crypto_pwhash_scryptxsalsa208sha256_STRSALTBYTES)
136
+ == crypto_pwhash_scryptxsalsa208sha256_STRSETTINGBYTES ? 1 : -1]);
137
+ (void) sizeof
138
+ (int[crypto_pwhash_scryptxsalsa208sha256_STRSETTINGBYTES + 1U +
139
+ crypto_pwhash_scryptxsalsa208sha256_STRHASHBYTES_ENCODED + 1U
140
+ == crypto_pwhash_scryptxsalsa208sha256_STRBYTES ? 1 : -1]);
141
+
142
+ return 0;
143
+ }
144
+
145
+ int
146
+ crypto_pwhash_scryptxsalsa208sha256_str_verify(const char str[crypto_pwhash_scryptxsalsa208sha256_STRBYTES],
147
+ const char * const passwd,
148
+ unsigned long long passwdlen)
149
+ {
150
+ char wanted[crypto_pwhash_scryptxsalsa208sha256_STRBYTES];
151
+ escrypt_local_t escrypt_local;
152
+ int ret = -1;
153
+
154
+ if (memchr(str, 0, crypto_pwhash_scryptxsalsa208sha256_STRBYTES) !=
155
+ &str[crypto_pwhash_scryptxsalsa208sha256_STRBYTES - 1U]) {
156
+ return -1;
157
+ }
158
+ if (escrypt_init_local(&escrypt_local) != 0) {
159
+ return -1;
160
+ }
161
+ if (escrypt_r(&escrypt_local, (const uint8_t *) passwd, (size_t) passwdlen,
162
+ (const uint8_t *) str, (uint8_t *) wanted,
163
+ sizeof wanted) == NULL) {
164
+ escrypt_free_local(&escrypt_local);
165
+ return -1;
166
+ }
167
+ escrypt_free_local(&escrypt_local);
168
+ ret = sodium_memcmp(wanted, str, sizeof wanted);
169
+ sodium_memzero(wanted, sizeof wanted);
170
+
171
+ return ret;
172
+ }