rbnacl-libsodium 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +6 -2
  3. data/lib/rbnacl/libsodium/version.rb +1 -1
  4. data/vendor/libsodium/ChangeLog +24 -0
  5. data/vendor/libsodium/LICENSE +2 -0
  6. data/vendor/libsodium/Makefile.in +6 -1
  7. data/vendor/libsodium/aclocal.m4 +1 -0
  8. data/vendor/libsodium/autom4te.cache/output.1 +1896 -1136
  9. data/vendor/libsodium/autom4te.cache/output.7 +19837 -0
  10. data/vendor/libsodium/autom4te.cache/requests +1271 -1031
  11. data/vendor/libsodium/autom4te.cache/traces.1 +532 -491
  12. data/vendor/libsodium/autom4te.cache/traces.7 +3614 -0
  13. data/vendor/libsodium/builds/msvc/version.h +2 -2
  14. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +22 -1
  15. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +23 -20
  16. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +13 -2
  17. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +12 -9
  18. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +12 -1
  19. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +3 -0
  20. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +2 -1
  21. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +14 -11
  22. data/vendor/libsodium/configure +1887 -1127
  23. data/vendor/libsodium/configure.ac +44 -11
  24. data/vendor/libsodium/dist-build/Makefile.am +4 -2
  25. data/vendor/libsodium/dist-build/Makefile.in +9 -2
  26. data/vendor/libsodium/dist-build/android-armv8-a.sh +1 -1
  27. data/vendor/libsodium/dist-build/android-build.sh +40 -3
  28. data/vendor/libsodium/dist-build/android-mips64.sh +1 -1
  29. data/vendor/libsodium/dist-build/android-x86_64.sh +4 -0
  30. data/vendor/libsodium/dist-build/emscripten-symbols.def +25 -25
  31. data/vendor/libsodium/dist-build/emscripten.sh +69 -35
  32. data/vendor/libsodium/dist-build/msys2-win32.sh +8 -2
  33. data/vendor/libsodium/dist-build/msys2-win64.sh +8 -2
  34. data/vendor/libsodium/dist-build/{nativeclient.sh → nativeclient-pnacl.sh} +3 -4
  35. data/vendor/libsodium/dist-build/nativeclient-x86.sh +19 -0
  36. data/vendor/libsodium/dist-build/nativeclient-x86_64.sh +19 -0
  37. data/vendor/libsodium/logo.png +0 -0
  38. data/vendor/libsodium/m4/ax_pthread.m4 +485 -0
  39. data/vendor/libsodium/msvc-scripts/Makefile.in +5 -0
  40. data/vendor/libsodium/msvc-scripts/process.bat +2 -2
  41. data/vendor/libsodium/packaging/nuget/package.bat +3 -3
  42. data/vendor/libsodium/src/Makefile.in +5 -0
  43. data/vendor/libsodium/src/libsodium/Makefile.am +2 -1
  44. data/vendor/libsodium/src/libsodium/Makefile.in +13 -8
  45. data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +70 -87
  46. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +6 -0
  47. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.c +1 -1
  48. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +9 -1
  49. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +11 -4
  50. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +14 -8
  51. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +0 -1
  52. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +10 -6
  53. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +2 -1
  54. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c +1 -1
  55. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +11 -11
  56. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h +2 -2
  57. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_nsquare.S +3 -0
  58. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_pack.S +3 -0
  59. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.S +830 -826
  60. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.S +732 -728
  61. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +3 -0
  62. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128.h +1 -1
  63. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S +8 -0
  64. data/vendor/libsodium/src/libsodium/include/Makefile.in +5 -0
  65. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +1 -1
  66. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +1 -1
  67. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth.h +1 -1
  68. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha256.h +1 -1
  69. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha512.h +1 -1
  70. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha512256.h +1 -1
  71. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +3 -3
  72. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +1 -1
  73. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash.h +1 -1
  74. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash_blake2b.h +1 -1
  75. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash.h +1 -1
  76. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha256.h +1 -1
  77. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha512.h +1 -1
  78. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth.h +1 -1
  79. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +1 -1
  80. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +1 -1
  81. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +1 -1
  82. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +1 -1
  83. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +1 -1
  84. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +1 -1
  85. data/vendor/libsodium/src/libsodium/include/sodium/crypto_shorthash.h +1 -1
  86. data/vendor/libsodium/src/libsodium/include/sodium/crypto_shorthash_siphash24.h +1 -1
  87. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign.h +3 -3
  88. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +1 -1
  89. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +1 -1
  90. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream.h +1 -1
  91. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes128ctr.h +1 -1
  92. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +1 -1
  93. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa20.h +1 -1
  94. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa2012.h +1 -1
  95. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa208.h +1 -1
  96. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xsalsa20.h +1 -1
  97. data/vendor/libsodium/src/libsodium/include/sodium/private/curve25519_ref10.h +2 -2
  98. data/vendor/libsodium/src/libsodium/include/sodium/private/mutex.h +7 -0
  99. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +1 -1
  100. data/vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +15 -4
  101. data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +25 -15
  102. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +72 -15
  103. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +43 -4
  104. data/vendor/libsodium/src/libsodium/sodium/core.c +131 -2
  105. data/vendor/libsodium/src/libsodium/sodium/runtime.c +5 -2
  106. data/vendor/libsodium/src/libsodium/sodium/utils.c +16 -8
  107. data/vendor/libsodium/test/Makefile.in +5 -0
  108. data/vendor/libsodium/test/default/Makefile.in +5 -0
  109. data/vendor/libsodium/test/default/generichash2.c +8 -2
  110. data/vendor/libsodium/test/default/nacl-test-wrapper.sh +19 -17
  111. data/vendor/libsodium/test/default/randombytes.c +4 -2
  112. data/vendor/libsodium/test/quirks/quirks.h +23 -2
  113. metadata +11 -15
  114. data/vendor/libsodium/README +0 -1
  115. data/vendor/libsodium/dist-build/android-x86-64.sh +0 -4
  116. data/vendor/libsodium/examples/Makefile +0 -21
  117. data/vendor/libsodium/examples/auth.c +0 -68
  118. data/vendor/libsodium/examples/box.c +0 -135
  119. data/vendor/libsodium/examples/box_detached.c +0 -134
  120. data/vendor/libsodium/examples/generichash.c +0 -80
  121. data/vendor/libsodium/examples/generichash_stream.c +0 -58
  122. data/vendor/libsodium/examples/shorthash.c +0 -58
  123. data/vendor/libsodium/examples/sign.c +0 -78
  124. data/vendor/libsodium/examples/utils.h +0 -110
@@ -92,6 +92,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
92
92
  am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_compile_flag.m4 \
93
93
  $(top_srcdir)/m4/ax_check_define.m4 \
94
94
  $(top_srcdir)/m4/ax_check_link_flag.m4 \
95
+ $(top_srcdir)/m4/ax_pthread.m4 \
95
96
  $(top_srcdir)/m4/ax_valgrind_check.m4 \
96
97
  $(top_srcdir)/m4/ld-output-def.m4 $(top_srcdir)/m4/libtool.m4 \
97
98
  $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@@ -205,6 +206,9 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
205
206
  PACKAGE_URL = @PACKAGE_URL@
206
207
  PACKAGE_VERSION = @PACKAGE_VERSION@
207
208
  PATH_SEPARATOR = @PATH_SEPARATOR@
209
+ PTHREAD_CC = @PTHREAD_CC@
210
+ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
211
+ PTHREAD_LIBS = @PTHREAD_LIBS@
208
212
  RANLIB = @RANLIB@
209
213
  SAFECODE_HOME = @SAFECODE_HOME@
210
214
  SED = @SED@
@@ -234,6 +238,7 @@ am__leading_dot = @am__leading_dot@
234
238
  am__quote = @am__quote@
235
239
  am__tar = @am__tar@
236
240
  am__untar = @am__untar@
241
+ ax_pthread_config = @ax_pthread_config@
237
242
  bindir = @bindir@
238
243
  build = @build@
239
244
  build_alias = @build_alias@
@@ -1,4 +1,4 @@
1
- cscript msvc-scripts/rep.vbs //Nologo s/@VERSION@/1.0.10/ < src\libsodium\include\sodium\version.h.in > tmp
1
+ cscript msvc-scripts/rep.vbs //Nologo s/@VERSION@/1.0.11/ < src\libsodium\include\sodium\version.h.in > tmp
2
2
  cscript msvc-scripts/rep.vbs //Nologo s/@SODIUM_LIBRARY_VERSION_MAJOR@/9/ < tmp > tmp2
3
- cscript msvc-scripts/rep.vbs //Nologo s/@SODIUM_LIBRARY_VERSION_MINOR@/2/ < tmp2 > src\libsodium\include\sodium\version.h
3
+ cscript msvc-scripts/rep.vbs //Nologo s/@SODIUM_LIBRARY_VERSION_MINOR@/3/ < tmp2 > src\libsodium\include\sodium\version.h
4
4
  del tmp tmp2
@@ -1,13 +1,13 @@
1
1
  @ECHO OFF
2
2
  ECHO Started nuget packaging build.
3
3
  ECHO.
4
- REM http://www.nuget.org/packages/gsl
4
+ REM https://www.nuget.org/packages/gsl
5
5
  gsl -q -script:package.gsl package.config
6
6
  ECHO.
7
- REM http://nuget.codeplex.com/releases
7
+ REM https://nuget.codeplex.com/releases
8
8
  nuget pack package.nuspec -verbosity detailed
9
9
  ECHO.
10
10
  ECHO NOTE: Ignore warnings not applicable to native code: "Issue: Assembly outside lib folder."
11
11
  ECHO.
12
12
  ECHO Completed nuget packaging build. The package is in the following folder:
13
- CD
13
+ CD
@@ -92,6 +92,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
92
92
  am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_compile_flag.m4 \
93
93
  $(top_srcdir)/m4/ax_check_define.m4 \
94
94
  $(top_srcdir)/m4/ax_check_link_flag.m4 \
95
+ $(top_srcdir)/m4/ax_pthread.m4 \
95
96
  $(top_srcdir)/m4/ax_valgrind_check.m4 \
96
97
  $(top_srcdir)/m4/ld-output-def.m4 $(top_srcdir)/m4/libtool.m4 \
97
98
  $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@@ -265,6 +266,9 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
265
266
  PACKAGE_URL = @PACKAGE_URL@
266
267
  PACKAGE_VERSION = @PACKAGE_VERSION@
267
268
  PATH_SEPARATOR = @PATH_SEPARATOR@
269
+ PTHREAD_CC = @PTHREAD_CC@
270
+ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
271
+ PTHREAD_LIBS = @PTHREAD_LIBS@
268
272
  RANLIB = @RANLIB@
269
273
  SAFECODE_HOME = @SAFECODE_HOME@
270
274
  SED = @SED@
@@ -294,6 +298,7 @@ am__leading_dot = @am__leading_dot@
294
298
  am__quote = @am__quote@
295
299
  am__tar = @am__tar@
296
300
  am__untar = @am__untar@
301
+ ax_pthread_config = @ax_pthread_config@
297
302
  bindir = @bindir@
298
303
  build = @build@
299
304
  build_alias = @build_alias@
@@ -102,6 +102,7 @@ libsodium_la_SOURCES = \
102
102
  crypto_verify/64/ref/verify_64.c \
103
103
  include/sodium/private/common.h \
104
104
  include/sodium/private/curve25519_ref10.h \
105
+ include/sodium/private/mutex.h \
105
106
  randombytes/randombytes.c \
106
107
  sodium/core.c \
107
108
  sodium/runtime.c \
@@ -117,7 +118,7 @@ libsodium_la_SOURCES += \
117
118
  randombytes/nativeclient/randombytes_nativeclient.c
118
119
  else
119
120
  libsodium_la_SOURCES += \
120
- randombytes/sysrandom/randombytes_sysrandom.c
121
+ randombytes/sysrandom/randombytes_sysrandom.c
121
122
  endif
122
123
 
123
124
  endif
@@ -97,7 +97,7 @@ host_triplet = @host@
97
97
  @EMSCRIPTEN_FALSE@@NATIVECLIENT_TRUE@ randombytes/nativeclient/randombytes_nativeclient.c
98
98
 
99
99
  @EMSCRIPTEN_FALSE@@NATIVECLIENT_FALSE@am__append_3 = \
100
- @EMSCRIPTEN_FALSE@@NATIVECLIENT_FALSE@ randombytes/sysrandom/randombytes_sysrandom.c
100
+ @EMSCRIPTEN_FALSE@@NATIVECLIENT_FALSE@ randombytes/sysrandom/randombytes_sysrandom.c
101
101
 
102
102
  @HAVE_TI_MODE_TRUE@am__append_4 = \
103
103
  @HAVE_TI_MODE_TRUE@ crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c \
@@ -161,6 +161,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
161
161
  am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_compile_flag.m4 \
162
162
  $(top_srcdir)/m4/ax_check_define.m4 \
163
163
  $(top_srcdir)/m4/ax_check_link_flag.m4 \
164
+ $(top_srcdir)/m4/ax_pthread.m4 \
164
165
  $(top_srcdir)/m4/ax_valgrind_check.m4 \
165
166
  $(top_srcdir)/m4/ld-output-def.m4 $(top_srcdir)/m4/libtool.m4 \
166
167
  $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@@ -319,8 +320,8 @@ am__libsodium_la_SOURCES_DIST = \
319
320
  crypto_verify/64/ref/verify_64.c \
320
321
  include/sodium/private/common.h \
321
322
  include/sodium/private/curve25519_ref10.h \
322
- randombytes/randombytes.c sodium/core.c sodium/runtime.c \
323
- sodium/utils.c sodium/version.c \
323
+ include/sodium/private/mutex.h randombytes/randombytes.c \
324
+ sodium/core.c sodium/runtime.c sodium/utils.c sodium/version.c \
324
325
  randombytes/salsa20/randombytes_salsa20_random.c \
325
326
  randombytes/nativeclient/randombytes_nativeclient.c \
326
327
  randombytes/sysrandom/randombytes_sysrandom.c \
@@ -707,6 +708,9 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
707
708
  PACKAGE_URL = @PACKAGE_URL@
708
709
  PACKAGE_VERSION = @PACKAGE_VERSION@
709
710
  PATH_SEPARATOR = @PATH_SEPARATOR@
711
+ PTHREAD_CC = @PTHREAD_CC@
712
+ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
713
+ PTHREAD_LIBS = @PTHREAD_LIBS@
710
714
  RANLIB = @RANLIB@
711
715
  SAFECODE_HOME = @SAFECODE_HOME@
712
716
  SED = @SED@
@@ -736,6 +740,7 @@ am__leading_dot = @am__leading_dot@
736
740
  am__quote = @am__quote@
737
741
  am__tar = @am__tar@
738
742
  am__untar = @am__untar@
743
+ ax_pthread_config = @ax_pthread_config@
739
744
  bindir = @bindir@
740
745
  build = @build@
741
746
  build_alias = @build_alias@
@@ -877,11 +882,11 @@ libsodium_la_SOURCES = \
877
882
  crypto_verify/64/ref/verify_64.c \
878
883
  include/sodium/private/common.h \
879
884
  include/sodium/private/curve25519_ref10.h \
880
- randombytes/randombytes.c sodium/core.c sodium/runtime.c \
881
- sodium/utils.c sodium/version.c $(am__append_1) \
882
- $(am__append_2) $(am__append_3) $(am__append_4) \
883
- $(am__append_5) $(am__append_6) $(am__append_7) \
884
- $(am__append_8) $(am__append_9)
885
+ include/sodium/private/mutex.h randombytes/randombytes.c \
886
+ sodium/core.c sodium/runtime.c sodium/utils.c sodium/version.c \
887
+ $(am__append_1) $(am__append_2) $(am__append_3) \
888
+ $(am__append_4) $(am__append_5) $(am__append_6) \
889
+ $(am__append_7) $(am__append_8) $(am__append_9)
885
890
  noinst_HEADERS = \
886
891
  crypto_scalarmult/curve25519/sandy2x/consts.S \
887
892
  crypto_scalarmult/curve25519/sandy2x/fe51_mul.S \
@@ -1,6 +1,8 @@
1
1
 
2
2
  /*
3
- * AES256-GCM, based on original code by Romain Dolbeau
3
+ * AES256-GCM, based on the "Intel Carry-Less Multiplication Instruction and its Usage for Computing
4
+ * the GCM Mode" paper and reference code, using the aggregated reduction method.
5
+ * Originally adapted by Romain Dolbeau.
4
6
  */
5
7
 
6
8
  #include <errno.h>
@@ -13,14 +15,15 @@
13
15
  #include "runtime.h"
14
16
  #include "utils.h"
15
17
 
16
- #if defined(HAVE_WMMINTRIN_H) || \
17
- (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)))
18
+ #if (defined(HAVE_TMMINTRIN_H) && defined(HAVE_WMMINTRIN_H)) || \
19
+ (defined(_MSC_VER) && _MSC_VER >= 1600 && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)))
18
20
 
19
21
  #pragma GCC target("ssse3")
20
22
  #pragma GCC target("aes")
21
23
  #pragma GCC target("pclmul")
22
24
 
23
- #include <immintrin.h>
25
+ #include <tmmintrin.h>
26
+ #include <wmmintrin.h>
24
27
 
25
28
  #ifndef ENOSYS
26
29
  # define ENOSYS ENXIO
@@ -49,68 +52,43 @@ typedef struct context {
49
52
  } context;
50
53
 
51
54
  static inline void
52
- aesni_key256_expand(const unsigned char *key, __m128 *rkeys)
55
+ aesni_key256_expand(const unsigned char *key, __m128i * const rkeys)
53
56
  {
54
- __m128 key0 = _mm_loadu_ps((const float *) (key + 0));
55
- __m128 key1 = _mm_loadu_ps((const float *) (key + 16));
56
- __m128 temp0, temp1, temp2, temp4;
57
- int idx = 0;
58
-
59
- rkeys[idx++] = key0;
60
- temp0 = key0;
61
- temp2 = key1;
62
- temp4 = _mm_setzero_ps();
63
-
64
- /* why single precision floating-point rather than integer instructions ?
65
- because _mm_shuffle_ps takes two inputs, while _mm_shuffle_epi32 only
66
- takes one - it doesn't perform the same computation...
67
- _mm_shuffle_ps takes the lower 64 bits of the result from the first
68
- operand, and the higher 64 bits of the result from the second operand
69
- (in both cases, all four input floats are accessible).
70
- I don't like the non-orthogonal naming scheme :-(
71
-
72
- This is all strongly inspired by the openssl assembly code.
73
- */
74
- #define BLOCK1(IMM) \
75
- temp1 = _mm_castsi128_ps(_mm_aeskeygenassist_si128(_mm_castps_si128(temp2), IMM));\
76
- rkeys[idx++] = temp2; \
77
- temp4 = _mm_shuffle_ps(temp4, temp0, 0x10); \
78
- temp0 = _mm_xor_ps(temp0, temp4); \
79
- temp4 = _mm_shuffle_ps(temp4, temp0, 0x8c); \
80
- temp0 = _mm_xor_ps(temp0, temp4); \
81
- temp1 = _mm_shuffle_ps(temp1, temp1, 0xff); \
82
- temp0 = _mm_xor_ps(temp0, temp1)
83
-
84
- #define BLOCK2(IMM) \
85
- temp1 = _mm_castsi128_ps(_mm_aeskeygenassist_si128(_mm_castps_si128(temp0), IMM));\
86
- rkeys[idx++] = temp0; \
87
- temp4 = _mm_shuffle_ps(temp4, temp2, 0x10); \
88
- temp2 = _mm_xor_ps(temp2, temp4); \
89
- temp4 = _mm_shuffle_ps(temp4, temp2, 0x8c); \
90
- temp2 = _mm_xor_ps(temp2, temp4); \
91
- temp1 = _mm_shuffle_ps(temp1, temp1, 0xaa); \
92
- temp2 = _mm_xor_ps(temp2, temp1)
93
-
94
- BLOCK1(0x01);
95
- BLOCK2(0x01);
96
-
97
- BLOCK1(0x02);
98
- BLOCK2(0x02);
99
-
100
- BLOCK1(0x04);
101
- BLOCK2(0x04);
102
-
103
- BLOCK1(0x08);
104
- BLOCK2(0x08);
105
-
106
- BLOCK1(0x10);
107
- BLOCK2(0x10);
108
-
109
- BLOCK1(0x20);
110
- BLOCK2(0x20);
111
-
112
- BLOCK1(0x40);
113
- rkeys[idx++] = temp0;
57
+ __m128i X0, X1, X2, X3;
58
+ int i = 0;
59
+
60
+ X0 = _mm_loadu_si128((const __m128i *) &key[0]);
61
+ rkeys[i++] = X0;
62
+
63
+ X2 = _mm_loadu_si128((const __m128i *) &key[16]);
64
+ rkeys[i++] = X2;
65
+
66
+ #define EXPAND_KEY_1(S) do { \
67
+ X1 = _mm_shuffle_epi32(_mm_aeskeygenassist_si128(X2, (S)), 0xff); \
68
+ X3 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(X3), _mm_castsi128_ps(X0), 0x10)); \
69
+ X0 = _mm_xor_si128(X0, X3); \
70
+ X3 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(X3), _mm_castsi128_ps(X0), 0x8c)); \
71
+ X0 = _mm_xor_si128(_mm_xor_si128(X0, X3), X1); \
72
+ rkeys[i++] = X0; \
73
+ } while (0)
74
+
75
+ #define EXPAND_KEY_2(S) do { \
76
+ X1 = _mm_shuffle_epi32(_mm_aeskeygenassist_si128(X0, (S)), 0xaa); \
77
+ X3 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(X3), _mm_castsi128_ps(X2), 0x10)); \
78
+ X2 = _mm_xor_si128(X2, X3); \
79
+ X3 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(X3), _mm_castsi128_ps(X2), 0x8c)); \
80
+ X2 = _mm_xor_si128(_mm_xor_si128(X2, X3), X1); \
81
+ rkeys[i++] = X2; \
82
+ } while (0)
83
+
84
+ X3 = _mm_setzero_si128();
85
+ EXPAND_KEY_1(0x01); EXPAND_KEY_2(0x01);
86
+ EXPAND_KEY_1(0x02); EXPAND_KEY_2(0x02);
87
+ EXPAND_KEY_1(0x04); EXPAND_KEY_2(0x04);
88
+ EXPAND_KEY_1(0x08); EXPAND_KEY_2(0x08);
89
+ EXPAND_KEY_1(0x10); EXPAND_KEY_2(0x10);
90
+ EXPAND_KEY_1(0x20); EXPAND_KEY_2(0x20);
91
+ EXPAND_KEY_1(0x40);
114
92
  }
115
93
 
116
94
  /** single, by-the-book AES encryption with AES-NI */
@@ -129,7 +107,7 @@ aesni_encrypt1(unsigned char *out, __m128i nv, const __m128i *rkeys)
129
107
  }
130
108
 
131
109
  /** multiple-blocks-at-once AES encryption with AES-NI ;
132
- on Haswell, aesenc as a latency of 7 and a throughput of 1
110
+ on Haswell, aesenc has a latency of 7 and a throughput of 1
133
111
  so the sequence of aesenc should be bubble-free if you
134
112
  have at least 8 blocks. Let's build an arbitratry-sized
135
113
  function */
@@ -269,7 +247,7 @@ addmul(unsigned char *c, const unsigned char *a, unsigned int xlen, const unsign
269
247
  _mm_storeu_si128((__m128i *) c, tmp21);
270
248
  }
271
249
 
272
- /* pure multiplication, for pre-computing powers of H */
250
+ /* pure multiplication, for pre-computing powers of H */
273
251
  static inline __m128i
274
252
  mulv(__m128i A, __m128i B)
275
253
  {
@@ -328,19 +306,19 @@ mulv(__m128i A, __m128i B)
328
306
  tmp##a##B = _mm_xor_si128(tmp##a##B, X##a); \
329
307
  tmp##a = _mm_clmulepi64_si128(tmp##a, tmp##a##B, 0x00)
330
308
 
331
- #define REDUCE4(rev, H0_, H1_, H2_, H3_, X0_, X1_, X2_, X3_, accv) \
309
+ #define MULREDUCE4(rev, H0_, H1_, H2_, H3_, X0_, X1_, X2_, X3_, accv) \
332
310
  do { \
333
311
  MAKE4(RED_DECL); \
334
- __m128i lo, hi; \
335
- __m128i tmp8, tmp9; \
336
- __m128i H0 = H0_; \
337
- __m128i H1 = H1_; \
338
- __m128i H2 = H2_; \
339
- __m128i H3 = H3_; \
340
- __m128i X0 = X0_; \
341
- __m128i X1 = X1_; \
342
- __m128i X2 = X2_; \
343
- __m128i X3 = X3_; \
312
+ __m128i lo, hi; \
313
+ __m128i tmp8, tmp9; \
314
+ __m128i H0 = H0_; \
315
+ __m128i H1 = H1_; \
316
+ __m128i H2 = H2_; \
317
+ __m128i H3 = H3_; \
318
+ __m128i X0 = X0_; \
319
+ __m128i X1 = X1_; \
320
+ __m128i X2 = X2_; \
321
+ __m128i X3 = X3_; \
344
322
  \
345
323
  /* byte-revert the inputs & xor the first one into the accumulator */ \
346
324
  \
@@ -449,8 +427,8 @@ do { \
449
427
  MAKE8(XORx); \
450
428
  MAKE8(STOREx); \
451
429
  accv_ = _mm_load_si128((const __m128i *) accum); \
452
- REDUCE4(rev, hv, h2v, h3v, h4v, temp3, temp2, temp1, temp0, accv_); \
453
- REDUCE4(rev, hv, h2v, h3v, h4v, temp7, temp6, temp5, temp4, accv_); \
430
+ MULREDUCE4(rev, hv, h2v, h3v, h4v, temp3, temp2, temp1, temp0, accv_); \
431
+ MULREDUCE4(rev, hv, h2v, h3v, h4v, temp7, temp6, temp5, temp4, accv_); \
454
432
  _mm_store_si128((__m128i *) accum, accv_); \
455
433
  } while(0)
456
434
 
@@ -466,8 +444,8 @@ do { \
466
444
  \
467
445
  MAKE8(LOADx); \
468
446
  accv_ = _mm_load_si128((const __m128i *) accum); \
469
- REDUCE4(rev, hv, h2v, h3v, h4v, in3, in2, in1, in0, accv_); \
470
- REDUCE4(rev, hv, h2v, h3v, h4v, in7, in6, in5, in4, accv_); \
447
+ MULREDUCE4(rev, hv, h2v, h3v, h4v, in3, in2, in1, in0, accv_); \
448
+ MULREDUCE4(rev, hv, h2v, h3v, h4v, in7, in6, in5, in4, accv_); \
471
449
  _mm_store_si128((__m128i *) accum, accv_); \
472
450
  } while(0)
473
451
 
@@ -502,7 +480,7 @@ crypto_aead_aes256gcm_beforenm(crypto_aead_aes256gcm_state *ctx_,
502
480
  unsigned char *H = ctx->H;
503
481
 
504
482
  (void) sizeof(int[(sizeof *ctx_) >= (sizeof *ctx) ? 1 : -1]);
505
- aesni_key256_expand(k, (__m128 *) rkeys);
483
+ aesni_key256_expand(k, rkeys);
506
484
  aesni_encrypt1(H, zero, rkeys);
507
485
 
508
486
  return 0;
@@ -553,13 +531,13 @@ crypto_aead_aes256gcm_encrypt_detached_afternm(unsigned char *c,
553
531
  H4v = mulv(H3v, Hv);
554
532
 
555
533
  accv = _mm_setzero_si128();
556
- /* unrolled by 4 GCM (by 8 doesn't improve using REDUCE4) */
534
+ /* unrolled by 4 GCM (by 8 doesn't improve using MULREDUCE4) */
557
535
  for (i = 0; i < adlen_rnd64; i += 64) {
558
536
  __m128i X4_ = _mm_loadu_si128((const __m128i *) (ad + i + 0));
559
537
  __m128i X3_ = _mm_loadu_si128((const __m128i *) (ad + i + 16));
560
538
  __m128i X2_ = _mm_loadu_si128((const __m128i *) (ad + i + 32));
561
539
  __m128i X1_ = _mm_loadu_si128((const __m128i *) (ad + i + 48));
562
- REDUCE4(rev, Hv, H2v, H3v, H4v, X1_, X2_, X3_, X4_, accv);
540
+ MULREDUCE4(rev, Hv, H2v, H3v, H4v, X1_, X2_, X3_, X4_, accv);
563
541
  }
564
542
  _mm_store_si128((__m128i *) accum, accv);
565
543
 
@@ -700,7 +678,7 @@ crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m, unsigned char *
700
678
  __m128i X3_ = _mm_loadu_si128((const __m128i *) (ad + i + 16));
701
679
  __m128i X2_ = _mm_loadu_si128((const __m128i *) (ad + i + 32));
702
680
  __m128i X1_ = _mm_loadu_si128((const __m128i *) (ad + i + 48));
703
- REDUCE4(rev, Hv, H2v, H3v, H4v, X1_, X2_, X3_, X4_, accv);
681
+ MULREDUCE4(rev, Hv, H2v, H3v, H4v, X1_, X2_, X3_, X4_, accv);
704
682
  }
705
683
  _mm_store_si128((__m128i *) accum, accv);
706
684
 
@@ -787,9 +765,14 @@ crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m, unsigned char *
787
765
  d |= (mac[i] ^ (T[i] ^ accum[15 - i]));
788
766
  }
789
767
  if (d != 0) {
790
- memset(m, 0, mlen);
768
+ if (m != NULL) {
769
+ memset(m, 0, mlen);
770
+ }
791
771
  return -1;
792
772
  }
773
+ if (m == NULL) {
774
+ return 0;
775
+ }
793
776
  }
794
777
  n2[3] = 0U;
795
778
  COUNTER_INC2(n2);
@@ -198,6 +198,9 @@ crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m,
198
198
  (void) sizeof(int[sizeof computed_mac == 16U ? 1 : -1]);
199
199
  ret = crypto_verify_16(computed_mac, mac);
200
200
  sodium_memzero(computed_mac, sizeof computed_mac);
201
+ if (m == NULL) {
202
+ return ret;
203
+ }
201
204
  if (ret != 0) {
202
205
  memset(m, 0, mlen);
203
206
  return -1;
@@ -279,6 +282,9 @@ crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m,
279
282
  (void) sizeof(int[sizeof computed_mac == 16U ? 1 : -1]);
280
283
  ret = crypto_verify_16(computed_mac, mac);
281
284
  sodium_memzero(computed_mac, sizeof computed_mac);
285
+ if (m == NULL) {
286
+ return ret;
287
+ }
282
288
  if (ret != 0) {
283
289
  memset(m, 0, mlen);
284
290
  return -1;
@@ -7,7 +7,7 @@
7
7
  #include <string.h>
8
8
 
9
9
  #if (defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)) || \
10
- (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64)))
10
+ (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64)) && _MSC_VER >= 1700)
11
11
 
12
12
  #pragma GCC target("sse2")
13
13
  #pragma GCC target("ssse3")
@@ -54,6 +54,11 @@ static inline int blake2b_clear_lastnode( blake2b_state *S )
54
54
  }
55
55
  #endif
56
56
 
57
+ static inline int blake2b_is_lastblock( const blake2b_state *S )
58
+ {
59
+ return S->f[0] != 0;
60
+ }
61
+
57
62
  static inline int blake2b_set_lastblock( blake2b_state *S )
58
63
  {
59
64
  if( S->last_node ) blake2b_set_lastnode( S );
@@ -327,6 +332,9 @@ int blake2b_final( blake2b_state *S, uint8_t *out, uint8_t outlen )
327
332
  if( !outlen || outlen > BLAKE2B_OUTBYTES ) {
328
333
  abort(); /* LCOV_EXCL_LINE */
329
334
  }
335
+ if( blake2b_is_lastblock( S ) ) {
336
+ return -1;
337
+ }
330
338
  if( S->buflen > BLAKE2B_BLOCKBYTES )
331
339
  {
332
340
  blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
@@ -421,7 +429,7 @@ blake2b_pick_best_implementation(void)
421
429
  {
422
430
  /* LCOV_EXCL_START */
423
431
  #if (defined(HAVE_AVX2INTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)) || \
424
- (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64)))
432
+ (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64)) && _MSC_VER >= 1700)
425
433
  if (sodium_runtime_has_avx2()) {
426
434
  blake2b_compress = blake2b_compress_avx2;
427
435
  return 0;