rbnacl-libsodium 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +4 -0
  3. data/lib/rbnacl/libsodium/version.rb +1 -1
  4. data/vendor/libsodium/ChangeLog +5 -0
  5. data/vendor/libsodium/README.markdown +4 -1
  6. data/vendor/libsodium/autogen.sh +0 -5
  7. data/vendor/libsodium/autom4te.cache/output.1 +14 -14
  8. data/vendor/libsodium/autom4te.cache/output.5 +14 -14
  9. data/vendor/libsodium/autom4te.cache/requests +868 -868
  10. data/vendor/libsodium/autom4te.cache/traces.1 +1 -1
  11. data/vendor/libsodium/builds/msvc/version.h +2 -2
  12. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +10 -72
  13. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +36 -216
  14. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +10 -72
  15. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +34 -214
  16. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +10 -72
  17. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +34 -214
  18. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +10 -72
  19. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +25 -205
  20. data/vendor/libsodium/configure +14 -14
  21. data/vendor/libsodium/configure.ac +5 -5
  22. data/vendor/libsodium/dist-build/msys2-win32.sh +3 -2
  23. data/vendor/libsodium/dist-build/msys2-win64.sh +3 -2
  24. data/vendor/libsodium/examples/sign.c +2 -2
  25. data/vendor/libsodium/examples/utils.h +3 -1
  26. data/vendor/libsodium/libsodium.vcxproj +7 -53
  27. data/vendor/libsodium/libsodium.vcxproj.filters +18 -152
  28. data/vendor/libsodium/msvc-scripts/process.bat +2 -2
  29. data/vendor/libsodium/src/libsodium/Makefile.am +6 -68
  30. data/vendor/libsodium/src/libsodium/Makefile.in +49 -724
  31. data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +2 -2
  32. data/vendor/libsodium/src/libsodium/{crypto_sign/ed25519 → crypto_core/curve25519}/ref10/base.h +0 -0
  33. data/vendor/libsodium/src/libsodium/{crypto_sign/ed25519 → crypto_core/curve25519}/ref10/base2.h +0 -0
  34. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +2233 -0
  35. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.h +160 -0
  36. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +2 -2
  37. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +1 -1
  38. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +1 -1
  39. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +1 -1
  40. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +2 -2
  41. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +2 -2
  42. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c +1 -1
  43. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +255 -0
  44. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/{curve25519_ref10.h → x25519_ref10.h} +0 -0
  45. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c +1 -1
  46. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +1 -2
  47. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c +2 -4
  48. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +1 -2
  49. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +1 -2
  50. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +1 -1
  51. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c +16 -9
  52. data/vendor/libsodium/src/libsodium/include/sodium/export.h +2 -2
  53. data/vendor/libsodium/src/libsodium/include/sodium/utils.h +6 -4
  54. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +12 -8
  55. data/vendor/libsodium/src/libsodium/sodium/core.c +9 -0
  56. data/vendor/libsodium/src/libsodium/sodium/runtime.c +32 -10
  57. data/vendor/libsodium/src/libsodium/sodium/utils.c +8 -8
  58. data/vendor/libsodium/test/default/auth.c +1 -1
  59. data/vendor/libsodium/test/default/box.c +16 -4
  60. data/vendor/libsodium/test/default/box2.c +7 -0
  61. data/vendor/libsodium/test/default/box7.c +18 -10
  62. data/vendor/libsodium/test/default/box8.c +1 -1
  63. data/vendor/libsodium/test/default/box_easy2.c +13 -0
  64. data/vendor/libsodium/test/default/onetimeauth.c +1 -0
  65. data/vendor/libsodium/test/default/pwhash_scrypt_ll.c +2 -2
  66. data/vendor/libsodium/test/default/verify1.c +1 -1
  67. metadata +9 -71
  68. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/curve25519_ref10.c +0 -73
  69. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe.h +0 -44
  70. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_0_curve25519_ref10.c +0 -23
  71. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_1_curve25519_ref10.c +0 -23
  72. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_add_curve25519_ref10.c +0 -61
  73. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_copy_curve25519_ref10.c +0 -33
  74. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_cswap_curve25519_ref10.c +0 -77
  75. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_frombytes_curve25519_ref10.c +0 -74
  76. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_invert_curve25519_ref10.c +0 -18
  77. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_mul121666_curve25519_ref10.c +0 -74
  78. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_mul_curve25519_ref10.c +0 -257
  79. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_sq_curve25519_ref10.c +0 -153
  80. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_sub_curve25519_ref10.c +0 -61
  81. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/fe_tobytes_curve25519_ref10.c +0 -123
  82. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/montgomery.h +0 -140
  83. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/pow225521.h +0 -160
  84. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/d.h +0 -1
  85. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/d2.h +0 -1
  86. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe.h +0 -56
  87. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_0.c +0 -19
  88. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_1.c +0 -19
  89. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_add.c +0 -57
  90. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_cmov.c +0 -63
  91. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_copy.c +0 -29
  92. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_frombytes.c +0 -73
  93. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_invert.c +0 -14
  94. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_isnegative.c +0 -16
  95. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_isnonzero.c +0 -19
  96. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_mul.c +0 -253
  97. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_neg.c +0 -45
  98. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_pow22523.c +0 -13
  99. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_sq.c +0 -149
  100. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_sq2.c +0 -160
  101. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_sub.c +0 -57
  102. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/fe_tobytes.c +0 -119
  103. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge.h +0 -97
  104. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_add.c +0 -11
  105. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_add.h +0 -97
  106. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_double_scalarmult.c +0 -138
  107. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_frombytes.c +0 -50
  108. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_madd.c +0 -11
  109. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_madd.h +0 -88
  110. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_msub.c +0 -11
  111. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_msub.h +0 -88
  112. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p1p1_to_p2.c +0 -12
  113. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p1p1_to_p3.c +0 -13
  114. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p2_0.c +0 -8
  115. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p2_dbl.c +0 -11
  116. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p2_dbl.h +0 -73
  117. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p3_0.c +0 -9
  118. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p3_dbl.c +0 -12
  119. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p3_to_cached.c +0 -17
  120. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p3_to_p2.c +0 -12
  121. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_p3_tobytes.c +0 -14
  122. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_precomp_0.c +0 -8
  123. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_scalarmult_base.c +0 -111
  124. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_sub.c +0 -11
  125. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_sub.h +0 -97
  126. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ge_tobytes.c +0 -14
  127. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/pow22523.h +0 -160
  128. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/pow225521.h +0 -160
  129. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sc.h +0 -15
  130. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sc_muladd.c +0 -368
  131. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sc_reduce.c +0 -275
  132. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sqrtm1.h +0 -1
@@ -11,7 +11,7 @@
11
11
  static const crypto_scalarmult_curve25519_implementation *implementation =
12
12
  &crypto_scalarmult_curve25519_donna_c64_implementation;
13
13
  #else
14
- # include "ref10/curve25519_ref10.h"
14
+ # include "ref10/x25519_ref10.h"
15
15
  static const crypto_scalarmult_curve25519_implementation *implementation =
16
16
  &crypto_scalarmult_curve25519_ref10_implementation;
17
17
  #endif
@@ -4,10 +4,9 @@
4
4
  #include "crypto_sign_ed25519.h"
5
5
  #include "crypto_hash_sha512.h"
6
6
  #include "crypto_scalarmult_curve25519.h"
7
- #include "fe.h"
8
- #include "ge.h"
9
7
  #include "randombytes.h"
10
8
  #include "utils.h"
9
+ #include "../../../crypto_core/curve25519/ref10/curve25519_ref10.h"
11
10
 
12
11
  int crypto_sign_ed25519_seed_keypair(unsigned char *pk, unsigned char *sk,
13
12
  const unsigned char *seed)
@@ -6,11 +6,9 @@
6
6
  #include "crypto_hash_sha512.h"
7
7
  #include "crypto_sign_edwards25519sha512batch.h"
8
8
  #include "crypto_verify_32.h"
9
- #include "fe.h"
10
- #include "ge.h"
11
9
  #include "randombytes.h"
12
- #include "sc.h"
13
10
  #include "utils.h"
11
+ #include "../../../crypto_core/curve25519/ref10/curve25519_ref10.h"
14
12
 
15
13
  int crypto_sign_edwards25519sha512batch_keypair(unsigned char *pk,
16
14
  unsigned char *sk)
@@ -107,7 +105,7 @@ int crypto_sign_edwards25519sha512batch_open(unsigned char *m,
107
105
  return -1;
108
106
  }
109
107
  *mlen_p = mlen;
110
- memmove(m, sm + 64, mlen);
108
+ memmove(m, sm + 32, mlen);
111
109
 
112
110
  return 0;
113
111
  }
@@ -6,9 +6,8 @@
6
6
  #include "crypto_hash_sha512.h"
7
7
  #include "crypto_sign_ed25519.h"
8
8
  #include "crypto_verify_32.h"
9
- #include "ge.h"
10
- #include "sc.h"
11
9
  #include "utils.h"
10
+ #include "../../../crypto_core/curve25519/ref10/curve25519_ref10.h"
12
11
 
13
12
  int
14
13
  crypto_sign_ed25519_verify_detached(const unsigned char *sig,
@@ -3,9 +3,8 @@
3
3
 
4
4
  #include "crypto_hash_sha512.h"
5
5
  #include "crypto_sign_ed25519.h"
6
- #include "ge.h"
7
- #include "sc.h"
8
6
  #include "utils.h"
7
+ #include "../../../crypto_core/curve25519/ref10/curve25519_ref10.h"
9
8
 
10
9
  int
11
10
  crypto_sign_ed25519_detached(unsigned char *sig, unsigned long long *siglen_p,
@@ -229,7 +229,7 @@ chacha_encrypt_bytes(chacha_ctx *ctx, const u8 *m, u8 *c, unsigned long long byt
229
229
  if (bytes <= 64) {
230
230
  if (bytes < 64) {
231
231
  for (i = 0; i < (unsigned int) bytes; ++i) {
232
- ctarget[i] = c[i];
232
+ ctarget[i] = c[i]; /* ctarget cannot be NULL */
233
233
  }
234
234
  }
235
235
  ctx->input[12] = j12;
@@ -16,7 +16,7 @@
16
16
 
17
17
  #define CHACHA_RNDS 20
18
18
 
19
- typedef unsigned int vec __attribute__((vector_size(16)));
19
+ typedef unsigned int vec __attribute__ ((vector_size(16)));
20
20
 
21
21
  #include <emmintrin.h>
22
22
  #include <tmmintrin.h>
@@ -97,13 +97,20 @@ typedef struct chacha_ctx chacha_ctx;
97
97
  static void
98
98
  chacha_ivsetup(chacha_ctx *ctx, const uint8_t *iv, uint64_t ic)
99
99
  {
100
- const vec s3 = {
101
- (uint32_t) ic,
102
- (uint32_t) (ic >> 32),
103
- ((const uint32_t *) (const void *) iv)[0],
104
- ((const uint32_t *) (const void *) iv)[1]
105
- };
106
- ctx->s3 = s3;
100
+ uint32_t iv_low;
101
+ uint32_t iv_high;
102
+
103
+ memcpy(&iv_low, iv, 4);
104
+ memcpy(&iv_high, iv + 4, 4);
105
+ {
106
+ const vec s3 = {
107
+ (uint32_t) ic,
108
+ (uint32_t) (ic >> 32),
109
+ iv_low,
110
+ iv_high
111
+ };
112
+ ctx->s3 = s3;
113
+ }
107
114
  }
108
115
 
109
116
  static void
@@ -138,7 +145,7 @@ chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *in, uint8_t *out,
138
145
  unsigned long long i;
139
146
 
140
147
  if (inlen > 64ULL * (1ULL << 32) - 64ULL) {
141
- abort();
148
+ abort(); /* LCOV_EXCL_LINE */
142
149
  }
143
150
  s0 = LOAD_ALIGNED(chacha_const);
144
151
  s1 = ctx->s1;
@@ -21,7 +21,7 @@
21
21
  # else
22
22
  # if defined(__SUNPRO_C)
23
23
  # ifndef __GNU_C__
24
- # define SODIUM_EXPORT __attribute__(visibility(__global))
24
+ # define SODIUM_EXPORT __attribute__ (visibility(__global))
25
25
  # else
26
26
  # define SODIUM_EXPORT __attribute__ __global
27
27
  # endif
@@ -37,7 +37,7 @@
37
37
  # if defined(__INTEL_COMPILER) || defined(_MSC_VER)
38
38
  # define CRYPTO_ALIGN(x) __declspec(align(x))
39
39
  # else
40
- # define CRYPTO_ALIGN(x) __attribute__((aligned(x)))
40
+ # define CRYPTO_ALIGN(x) __attribute__ ((aligned(x)))
41
41
  # endif
42
42
  #endif
43
43
 
@@ -10,10 +10,12 @@
10
10
  extern "C" {
11
11
  #endif
12
12
 
13
- #if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
14
- # define SODIUM_C99(X)
15
- #else
16
- # define SODIUM_C99(X) X
13
+ #ifndef SODIUM_C99
14
+ # if defined(__cplusplus) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
15
+ # define SODIUM_C99(X)
16
+ # else
17
+ # define SODIUM_C99(X) X
18
+ # endif
17
19
  #endif
18
20
 
19
21
  SODIUM_EXPORT
@@ -14,6 +14,7 @@
14
14
  #include <fcntl.h>
15
15
  #include <limits.h>
16
16
  #include <stdint.h>
17
+ #include <stdlib.h>
17
18
  #include <string.h>
18
19
  #ifndef _MSC_VER
19
20
  # include <unistd.h>
@@ -50,21 +51,21 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
50
51
  #endif
51
52
 
52
53
  typedef struct Salsa20Random_ {
54
+ size_t rnd32_outleft;
55
+ int random_data_source_fd;
56
+ int initialized;
57
+ int getrandom_available;
53
58
  unsigned char key[crypto_stream_salsa20_KEYBYTES];
54
59
  unsigned char rnd32[16U * SALSA20_RANDOM_BLOCK_SIZE];
55
60
  uint64_t nonce;
56
- size_t rnd32_outleft;
57
61
  #ifdef HAVE_GETPID
58
62
  pid_t pid;
59
63
  #endif
60
- int random_data_source_fd;
61
- int initialized;
62
- int getrandom_available;
63
64
  } Salsa20Random;
64
65
 
65
66
  static Salsa20Random stream = {
66
- SODIUM_C99(.random_data_source_fd =) -1,
67
67
  SODIUM_C99(.rnd32_outleft =) (size_t) 0U,
68
+ SODIUM_C99(.random_data_source_fd =) -1,
68
69
  SODIUM_C99(.initialized =) 0,
69
70
  SODIUM_C99(.getrandom_available =) 0
70
71
  };
@@ -86,7 +87,10 @@ sodium_hrtime(void)
86
87
  #else
87
88
  {
88
89
  struct timeval tv;
89
- assert(gettimeofday(&tv, NULL) == 0);
90
+
91
+ if (gettimeofday(&tv, NULL) != 0) {
92
+ abort(); /* LCOV_EXCL_LINE */
93
+ }
90
94
  ts = ((uint64_t) tv.tv_sec) * 1000000U + (uint64_t) tv.tv_usec;
91
95
  }
92
96
  #endif
@@ -104,7 +108,7 @@ safe_read(const int fd, void * const buf_, size_t size)
104
108
  assert(size <= SSIZE_MAX);
105
109
  do {
106
110
  while ((readnb = read(fd, buf, size)) < (ssize_t) 0 &&
107
- (errno == EINTR || errno == EAGAIN)); /* LCOV_EXCL_LINE */
111
+ (errno == EINTR || errno == EAGAIN)); /* LCOV_EXCL_LINE */
108
112
  if (readnb < (ssize_t) 0) {
109
113
  return readnb; /* LCOV_EXCL_LINE */
110
114
  }
@@ -304,7 +308,7 @@ randombytes_salsa20_random_stir(void)
304
308
  #endif
305
309
  if (crypto_generichash(stream.key, sizeof stream.key, k0, sizeof_k0,
306
310
  hsigma, sizeof hsigma) != 0) {
307
- abort();
311
+ abort(); /* LCOV_EXCL_LINE */
308
312
  }
309
313
  COMPILER_ASSERT(sizeof stream.key <= sizeof m0);
310
314
  randombytes_salsa20_random_rekey(m0);
@@ -8,6 +8,15 @@
8
8
  #include "runtime.h"
9
9
  #include "utils.h"
10
10
 
11
+ #if 0
12
+ # warning This is unstable, untested, development code.
13
+ # warning It might not compile. It might not work as expected.
14
+ # warning It might be totally insecure.
15
+ # warning Do not use this in production.
16
+ # warning Use releases available at https://download.libsodium.org/libsodium/releases/ instead.
17
+ # warning Alternatively, use the "stable" branch in the git repository.
18
+ #endif
19
+
11
20
  static int initialized;
12
21
 
13
22
  int
@@ -1,4 +1,6 @@
1
1
 
2
+ #include <stddef.h>
3
+ #include <stdint.h>
2
4
  #ifdef HAVE_ANDROID_GETCPUFEATURES
3
5
  # include <cpu-features.h>
4
6
  #endif
@@ -19,13 +21,18 @@ typedef struct CPUFeatures_ {
19
21
 
20
22
  static CPUFeatures _cpu_features;
21
23
 
22
- #define CPUID_SSE2 0x04000000
23
- #define CPUIDECX_SSE3 0x00000001
24
- #define CPUIDECX_SSSE3 0x00000200
25
- #define CPUIDECX_SSE41 0x00080000
26
- #define CPUIDECX_AVX 0x10000000
27
- #define CPUIDECX_PCLMUL 0x00000002
28
- #define CPUIDECX_AESNI 0x02000000
24
+ #define CPUID_SSE2 0x04000000
25
+ #define CPUIDECX_SSE3 0x00000001
26
+ #define CPUIDECX_SSSE3 0x00000200
27
+ #define CPUIDECX_SSE41 0x00080000
28
+ #define CPUIDECX_AVX 0x10000000
29
+ #define CPUIDECX_PCLMUL 0x00000002
30
+ #define CPUIDECX_AESNI 0x02000000
31
+ #define CPUIDECX_XSAVE 0x04000000
32
+ #define CPUIDECX_OSXSAVE 0x08000000
33
+
34
+ #define XCR0_SSE 0x00000002
35
+ #define XCR0_AVX 0x00000004
29
36
 
30
37
  static int
31
38
  _sodium_runtime_arm_cpu_features(CPUFeatures * const cpu_features)
@@ -130,11 +137,26 @@ _sodium_runtime_intel_cpu_features(CPUFeatures * const cpu_features)
130
137
  cpu_features->has_sse41 = 0;
131
138
  #endif
132
139
 
140
+ cpu_features->has_avx = 0;
133
141
  #if defined(HAVE_AVXINTRIN_H) || \
134
142
  (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_AMD64) || defined(_M_IX86)))
135
- cpu_features->has_avx = ((cpu_info[2] & CPUIDECX_AVX) != 0x0);
136
- #else
137
- cpu_features->has_avx = 0;
143
+ if ((cpu_info[2] & (CPUIDECX_AVX | CPUIDECX_XSAVE | CPUIDECX_OSXSAVE))
144
+ == (CPUIDECX_AVX | CPUIDECX_XSAVE | CPUIDECX_OSXSAVE)) {
145
+ uint32_t xcr0 = 0U;
146
+ # ifdef MSC_VER
147
+ __asm {
148
+ xor ecx, ecx
149
+ _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0
150
+ mov xcr0, eax
151
+ }
152
+ # elif defined(HAVE_AVX_ASM)
153
+ __asm__ __volatile__ (".byte 0x0f, 0x01, 0xd0" /* XGETBV */
154
+ : "=a"(xcr0) : "c"((uint32_t) 0U) : "%edx");
155
+ # endif
156
+ if ((xcr0 & (XCR0_SSE | XCR0_AVX)) == (XCR0_SSE | XCR0_AVX)) {
157
+ cpu_features->has_avx = 1;
158
+ }
159
+ }
138
160
  #endif
139
161
 
140
162
  #if defined(HAVE_WMMINTRIN_H) || \
@@ -50,7 +50,7 @@ static size_t page_size;
50
50
  static unsigned char canary[CANARY_SIZE];
51
51
 
52
52
  #ifdef HAVE_WEAK_SYMBOLS
53
- __attribute__((weak)) void
53
+ __attribute__ ((weak)) void
54
54
  _sodium_dummy_symbol_to_prevent_memzero_lto(void * const pnt, const size_t len)
55
55
  {
56
56
  (void) pnt;
@@ -83,7 +83,7 @@ sodium_memzero(void * const pnt, const size_t len)
83
83
  }
84
84
 
85
85
  #ifdef HAVE_WEAK_SYMBOLS
86
- __attribute__((weak)) void
86
+ __attribute__ ((weak)) void
87
87
  _sodium_dummy_symbol_to_prevent_memcmp_lto(const unsigned char *b1,
88
88
  const unsigned char *b2,
89
89
  const size_t len)
@@ -117,7 +117,7 @@ sodium_memcmp(const void * const b1_, const void * const b2_, size_t len)
117
117
  }
118
118
 
119
119
  #ifdef HAVE_WEAK_SYMBOLS
120
- __attribute__((weak)) void
120
+ __attribute__ ((weak)) void
121
121
  _sodium_dummy_symbol_to_prevent_compare_lto(const unsigned char *b1,
122
122
  const unsigned char *b2,
123
123
  const size_t len)
@@ -459,7 +459,7 @@ _page_round(const size_t size)
459
459
  return (size + page_mask) & ~page_mask;
460
460
  }
461
461
 
462
- static __attribute__((malloc)) unsigned char *
462
+ static __attribute__ ((malloc)) unsigned char *
463
463
  _alloc_aligned(const size_t size)
464
464
  {
465
465
  void *ptr;
@@ -514,13 +514,13 @@ _unprotected_ptr_from_user_ptr(void * const ptr)
514
514
  #endif /* HAVE_ALIGNED_MALLOC */
515
515
 
516
516
  #ifndef HAVE_ALIGNED_MALLOC
517
- static __attribute__((malloc)) void *
517
+ static __attribute__ ((malloc)) void *
518
518
  _sodium_malloc(const size_t size)
519
519
  {
520
520
  return malloc(size);
521
521
  }
522
522
  #else
523
- static __attribute__((malloc)) void *
523
+ static __attribute__ ((malloc)) void *
524
524
  _sodium_malloc(const size_t size)
525
525
  {
526
526
  void *user_ptr;
@@ -563,7 +563,7 @@ _sodium_malloc(const size_t size)
563
563
  }
564
564
  #endif /* !HAVE_ALIGNED_MALLOC */
565
565
 
566
- __attribute__((malloc)) void *
566
+ __attribute__ ((malloc)) void *
567
567
  sodium_malloc(const size_t size)
568
568
  {
569
569
  void *ptr;
@@ -576,7 +576,7 @@ sodium_malloc(const size_t size)
576
576
  return ptr;
577
577
  }
578
578
 
579
- __attribute__((malloc)) void *
579
+ __attribute__ ((malloc)) void *
580
580
  sodium_allocarray(size_t count, size_t size)
581
581
  {
582
582
  size_t total_size;
@@ -15,7 +15,7 @@ static unsigned char a2[crypto_auth_hmacsha512_BYTES];
15
15
  int main(void)
16
16
  {
17
17
  crypto_auth_hmacsha512_state st;
18
- int i;
18
+ size_t i;
19
19
 
20
20
  assert(crypto_auth_hmacsha512_statebytes() ==
21
21
  sizeof(crypto_auth_hmacsha512_state));
@@ -2,23 +2,28 @@
2
2
  #define TEST_NAME "box"
3
3
  #include "cmptest.h"
4
4
 
5
- static unsigned char alicesk[32]
5
+ static const unsigned char alicesk[32]
6
6
  = { 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1,
7
7
  0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0,
8
8
  0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a };
9
9
 
10
- static unsigned char bobpk[32]
10
+ static const unsigned char bobpk[32]
11
11
  = { 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, 0xd3, 0x5b, 0x61,
12
12
  0xc2, 0xec, 0xe4, 0x35, 0x37, 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78,
13
13
  0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f };
14
14
 
15
- static unsigned char nonce[24]
15
+ static const unsigned char small_order_p[crypto_box_PUBLICKEYBYTES]
16
+ = { 0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,
17
+ 0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,
18
+ 0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00 };
19
+
20
+ static const unsigned char nonce[24]
16
21
  = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
17
22
  0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
18
23
  0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 };
19
24
 
20
25
  // API requires first 32 bytes to be 0
21
- static unsigned char m[163]
26
+ static const unsigned char m[163]
22
27
  = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23
28
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24
29
  0, 0, 0, 0, 0, 0, 0, 0, 0xbe, 0x07, 0x5f, 0xc5,
@@ -50,8 +55,12 @@ int main(void)
50
55
  printf("\n");
51
56
  }
52
57
  printf("\n");
58
+
59
+ ret = crypto_box(c, m, 163, nonce, small_order_p, alicesk);
60
+ assert(ret == -1);
53
61
 
54
62
  memset(c, 0, sizeof c);
63
+
55
64
  ret = crypto_box_beforenm(k, bobpk, alicesk);
56
65
  assert(ret == 0);
57
66
  crypto_box_afternm(c, m, 163, nonce, k);
@@ -61,6 +70,9 @@ int main(void)
61
70
  printf("\n");
62
71
  }
63
72
  printf("\n");
73
+
74
+ ret = crypto_box_beforenm(k, small_order_p, alicesk);
75
+ assert(ret == -1);
64
76
 
65
77
  assert(crypto_box_seedbytes() > 0U);
66
78
  assert(crypto_box_publickeybytes() > 0U);
@@ -12,6 +12,11 @@ static unsigned char alicepk[32]
12
12
  0xdc, 0xb4, 0x3e, 0xf7, 0x5a, 0x0d, 0xbf, 0x3a, 0x0d, 0x26, 0x38,
13
13
  0x1a, 0xf4, 0xeb, 0xa4, 0xa9, 0x8e, 0xaa, 0x9b, 0x4e, 0x6a };
14
14
 
15
+ static const unsigned char small_order_p[crypto_box_PUBLICKEYBYTES]
16
+ = { 0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,
17
+ 0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,
18
+ 0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00 };
19
+
15
20
  static unsigned char nonce[24]
16
21
  = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
17
22
  0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
@@ -50,6 +55,8 @@ int main(void)
50
55
  }
51
56
  printf("\n");
52
57
  }
58
+ ret = crypto_box_open(m, c, 163, nonce, small_order_p, bobsk);
59
+ assert(ret == -1);
53
60
 
54
61
  memset(m, 0, sizeof m);
55
62
  ret = crypto_box_beforenm(k, alicepk, bobsk);