rbnacl-libsodium 0.7.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) 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 +13 -0
  5. data/vendor/libsodium/THANKS +1 -0
  6. data/vendor/libsodium/autom4te.cache/output.1 +14 -90
  7. data/vendor/libsodium/autom4te.cache/output.3 +14 -90
  8. data/vendor/libsodium/autom4te.cache/requests +127 -127
  9. data/vendor/libsodium/autom4te.cache/traces.1 +224 -224
  10. data/vendor/libsodium/autom4te.cache/traces.3 +137 -144
  11. data/vendor/libsodium/builds/msvc/version.h +2 -2
  12. data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +3 -0
  13. data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +3 -0
  14. data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +3 -0
  15. data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +3 -0
  16. data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +3 -0
  17. data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +3 -0
  18. data/vendor/libsodium/configure +14 -90
  19. data/vendor/libsodium/configure.ac +5 -12
  20. data/vendor/libsodium/msvc-scripts/process.bat +2 -2
  21. data/vendor/libsodium/packaging/nuget/package.config +1 -1
  22. data/vendor/libsodium/packaging/nuget/package.nuspec +25 -25
  23. data/vendor/libsodium/packaging/nuget/package.targets +20 -20
  24. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +2 -0
  25. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +7 -0
  26. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/keypair_curve25519xsalsa20poly1305.c +1 -1
  27. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2-impl.h +9 -4
  28. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +6 -1
  29. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c +4 -4
  30. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +2 -0
  31. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +2 -0
  32. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c +2 -1
  33. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +2 -0
  34. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +13 -13
  35. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +28 -27
  36. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +16 -12
  37. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +2 -2
  38. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +2 -2
  39. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +3 -3
  40. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +1 -1
  41. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +7 -3
  42. data/vendor/libsodium/src/libsodium/crypto_sign/edwards25519sha512batch/ref/sign_edwards25519sha512batch.c +1 -1
  43. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +3 -2
  44. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +10 -8
  45. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +13 -8
  46. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +10 -8
  47. data/vendor/libsodium/src/libsodium/sodium/core.c +1 -1
  48. data/vendor/libsodium/src/libsodium/sodium/runtime.c +3 -3
  49. data/vendor/libsodium/src/libsodium/sodium/utils.c +12 -12
  50. data/vendor/libsodium/test/default/Makefile.am +9 -1
  51. data/vendor/libsodium/test/default/Makefile.in +35 -13
  52. data/vendor/libsodium/test/default/aead_chacha20poly1305.c +37 -31
  53. data/vendor/libsodium/test/default/auth.c +48 -9
  54. data/vendor/libsodium/test/default/auth.exp +18 -0
  55. data/vendor/libsodium/test/default/auth2.c +19 -24
  56. data/vendor/libsodium/test/default/auth3.c +17 -25
  57. data/vendor/libsodium/test/default/auth5.c +24 -24
  58. data/vendor/libsodium/test/default/auth6.c +9 -8
  59. data/vendor/libsodium/test/default/auth7.c +24 -24
  60. data/vendor/libsodium/test/default/box.c +74 -51
  61. data/vendor/libsodium/test/default/box.exp +19 -0
  62. data/vendor/libsodium/test/default/box2.c +48 -51
  63. data/vendor/libsodium/test/default/box2.exp +17 -0
  64. data/vendor/libsodium/test/default/box7.c +20 -18
  65. data/vendor/libsodium/test/default/box8.c +27 -25
  66. data/vendor/libsodium/test/default/box_easy.c +32 -42
  67. data/vendor/libsodium/test/default/box_easy2.c +3 -5
  68. data/vendor/libsodium/test/default/box_seed.c +20 -20
  69. data/vendor/libsodium/test/default/chacha20.c +41 -21
  70. data/vendor/libsodium/test/default/chacha20.exp +8 -5
  71. data/vendor/libsodium/test/default/cmptest.h +4 -0
  72. data/vendor/libsodium/test/default/core1.c +26 -19
  73. data/vendor/libsodium/test/default/core2.c +24 -23
  74. data/vendor/libsodium/test/default/core3.c +30 -26
  75. data/vendor/libsodium/test/default/core4.c +22 -23
  76. data/vendor/libsodium/test/default/core5.c +18 -22
  77. data/vendor/libsodium/test/default/core6.c +33 -34
  78. data/vendor/libsodium/test/default/ed25519_convert.c +16 -20
  79. data/vendor/libsodium/test/default/generichash.c +59 -15
  80. data/vendor/libsodium/test/default/generichash.exp +2 -0
  81. data/vendor/libsodium/test/default/generichash2.c +30 -13
  82. data/vendor/libsodium/test/default/generichash3.c +156 -22
  83. data/vendor/libsodium/test/default/generichash3.exp +11 -0
  84. data/vendor/libsodium/test/default/hash.c +31 -6
  85. data/vendor/libsodium/test/default/hash.exp +3 -0
  86. data/vendor/libsodium/test/default/hash3.c +10 -7
  87. data/vendor/libsodium/test/default/onetimeauth.c +46 -34
  88. data/vendor/libsodium/test/default/onetimeauth.exp +2 -0
  89. data/vendor/libsodium/test/default/onetimeauth2.c +20 -32
  90. data/vendor/libsodium/test/default/onetimeauth7.c +24 -24
  91. data/vendor/libsodium/test/default/pwhash.c +276 -68
  92. data/vendor/libsodium/test/default/pwhash.exp +20 -0
  93. data/vendor/libsodium/test/default/pwhash_scrypt_ll.c +31 -37
  94. data/vendor/libsodium/test/default/randombytes.c +85 -8
  95. data/vendor/libsodium/test/default/randombytes.exp +1 -0
  96. data/vendor/libsodium/test/default/scalarmult.c +28 -15
  97. data/vendor/libsodium/test/default/scalarmult2.c +20 -15
  98. data/vendor/libsodium/test/default/scalarmult5.c +24 -21
  99. data/vendor/libsodium/test/default/scalarmult6.c +24 -21
  100. data/vendor/libsodium/test/default/scalarmult7.c +31 -0
  101. data/vendor/libsodium/test/default/scalarmult7.exp +1 -0
  102. data/vendor/libsodium/test/default/secretbox.c +50 -45
  103. data/vendor/libsodium/test/default/secretbox2.c +32 -45
  104. data/vendor/libsodium/test/default/secretbox7.c +19 -17
  105. data/vendor/libsodium/test/default/secretbox8.c +26 -24
  106. data/vendor/libsodium/test/default/secretbox_easy.c +46 -52
  107. data/vendor/libsodium/test/default/secretbox_easy2.c +3 -5
  108. data/vendor/libsodium/test/default/shorthash.c +17 -10
  109. data/vendor/libsodium/test/default/sign.c +74 -39
  110. data/vendor/libsodium/test/default/sodium_core.c +6 -3
  111. data/vendor/libsodium/test/default/sodium_utils.c +57 -28
  112. data/vendor/libsodium/test/default/sodium_utils.exp +6 -0
  113. data/vendor/libsodium/test/default/sodium_utils2.c +13 -11
  114. data/vendor/libsodium/test/default/sodium_utils3.c +5 -10
  115. data/vendor/libsodium/test/default/sodium_version.c +4 -5
  116. data/vendor/libsodium/test/default/stream.c +23 -17
  117. data/vendor/libsodium/test/default/stream2.c +17 -15
  118. data/vendor/libsodium/test/default/stream3.c +17 -19
  119. data/vendor/libsodium/test/default/stream4.c +36 -45
  120. data/vendor/libsodium/test/default/verify1.c +20 -18
  121. metadata +5 -3
  122. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c +0 -356
@@ -2,6 +2,7 @@
2
2
  #include "crypto_onetimeauth_poly1305.h"
3
3
  #include "donna/poly1305_donna.h"
4
4
 
5
+ /* LCOV_EXCL_START */
5
6
  static const crypto_onetimeauth_poly1305_implementation *implementation =
6
7
  &crypto_onetimeauth_poly1305_donna_implementation;
7
8
 
@@ -18,6 +19,7 @@ crypto_onetimeauth_poly1305_implementation_name(void)
18
19
  {
19
20
  return implementation->implementation_name();
20
21
  }
22
+ /* LCOV_EXCL_STOP */
21
23
 
22
24
  int
23
25
  crypto_onetimeauth_poly1305(unsigned char *out, const unsigned char *in,
@@ -36,7 +36,7 @@ encode64_uint32(uint8_t * dst, size_t dstlen, uint32_t src, uint32_t srcbits)
36
36
 
37
37
  for (bit = 0; bit < srcbits; bit += 6) {
38
38
  if (dstlen < 1) {
39
- return NULL;
39
+ return NULL; /* LCOV_EXCL_LINE */
40
40
  }
41
41
  *dst++ = itoa64[src & 0x3f];
42
42
  dstlen--;
@@ -60,7 +60,7 @@ encode64(uint8_t * dst, size_t dstlen, const uint8_t * src, size_t srclen)
60
60
  } while (bits < 24 && i < srclen);
61
61
  dnext = encode64_uint32(dst, dstlen, value, bits);
62
62
  if (!dnext) {
63
- return NULL;
63
+ return NULL; /* LCOV_EXCL_LINE */
64
64
  }
65
65
  dstlen -= dnext - dst;
66
66
  dst = dnext;
@@ -171,8 +171,8 @@ escrypt_r(escrypt_local_t * local, const uint8_t * passwd, size_t passwdlen,
171
171
 
172
172
  dst = encode64(dst, buflen - (dst - buf), hash, sizeof(hash));
173
173
  sodium_memzero(hash, sizeof hash);
174
- if (!dst || dst >= buf + buflen) { /* Can't happen */
175
- return NULL;
174
+ if (!dst || dst >= buf + buflen) {
175
+ return NULL; /* Can't happen LCOV_EXCL_LINE */
176
176
  }
177
177
  *dst = 0; /* NUL termination */
178
178
 
@@ -192,7 +192,7 @@ escrypt_gensalt_r(uint32_t N_log2, uint32_t r, uint32_t p,
192
192
 
193
193
  need = prefixlen + saltlen + 1;
194
194
  if (need > buflen || need < saltlen || saltlen < srclen) {
195
- return NULL;
195
+ return NULL; /* LCOV_EXCL_LINE */
196
196
  }
197
197
  if (N_log2 > 63 || ((uint64_t)r * (uint64_t)p >= (1U << 30))) {
198
198
  return NULL;
@@ -205,16 +205,16 @@ escrypt_gensalt_r(uint32_t N_log2, uint32_t r, uint32_t p,
205
205
  *dst++ = itoa64[N_log2];
206
206
 
207
207
  dst = encode64_uint32(dst, buflen - (dst - buf), r, 30);
208
- if (!dst) { /* Can't happen */
209
- return NULL;
208
+ if (!dst) {
209
+ return NULL; /* Can't happen LCOV_EXCL_LINE */
210
210
  }
211
211
  dst = encode64_uint32(dst, buflen - (dst - buf), p, 30);
212
- if (!dst) { /* Can't happen */
213
- return NULL;
212
+ if (!dst) {
213
+ return NULL; /* Can't happen LCOV_EXCL_LINE */
214
214
  }
215
215
  dst = encode64(dst, buflen - (dst - buf), src, srclen);
216
- if (!dst || dst >= buf + buflen) { /* Can't happen */
217
- return NULL;
216
+ if (!dst || dst >= buf + buflen) {
217
+ return NULL; /* Can't happen LCOV_EXCL_LINE */
218
218
  }
219
219
  *dst = 0; /* NUL termination */
220
220
 
@@ -232,7 +232,7 @@ crypto_pwhash_scryptsalsa208sha256_ll(const uint8_t * passwd, size_t passwdlen,
232
232
  int retval;
233
233
 
234
234
  if (escrypt_init_local(&local)) {
235
- return -1;
235
+ return -1; /* LCOV_EXCL_LINE */
236
236
  }
237
237
  #if defined(HAVE_EMMINTRIN_H) || defined(_MSC_VER)
238
238
  escrypt_kdf =
@@ -244,7 +244,7 @@ crypto_pwhash_scryptsalsa208sha256_ll(const uint8_t * passwd, size_t passwdlen,
244
244
  passwd, passwdlen, salt, saltlen,
245
245
  N, r, p, buf, buflen);
246
246
  if (escrypt_free_local(&local)) {
247
- return -1;
247
+ return -1; /* LCOV_EXCL_LINE */
248
248
  }
249
249
  return retval;
250
250
  }
@@ -44,41 +44,42 @@ void
44
44
  PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
45
45
  size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen)
46
46
  {
47
- crypto_auth_hmacsha256_state PShctx, hctx;
48
- size_t i;
49
- uint8_t ivec[4];
50
- uint8_t U[32];
51
- uint8_t T[32];
52
- uint64_t j;
53
- int k;
54
- size_t clen;
47
+ crypto_auth_hmacsha256_state PShctx, hctx;
48
+ size_t i;
49
+ uint8_t ivec[4];
50
+ uint8_t U[32];
51
+ uint8_t T[32];
52
+ uint64_t j;
53
+ int k;
54
+ size_t clen;
55
55
 
56
56
  crypto_auth_hmacsha256_init(&PShctx, passwd, passwdlen);
57
57
  crypto_auth_hmacsha256_update(&PShctx, salt, saltlen);
58
58
 
59
- for (i = 0; i * 32 < dkLen; i++) {
60
- be32enc(ivec, (uint32_t)(i + 1));
61
- memcpy(&hctx, &PShctx, sizeof(crypto_auth_hmacsha256_state));
62
- crypto_auth_hmacsha256_update(&hctx, ivec, 4);
63
- crypto_auth_hmacsha256_final(&hctx, U);
59
+ for (i = 0; i * 32 < dkLen; i++) {
60
+ be32enc(ivec, (uint32_t)(i + 1));
61
+ memcpy(&hctx, &PShctx, sizeof(crypto_auth_hmacsha256_state));
62
+ crypto_auth_hmacsha256_update(&hctx, ivec, 4);
63
+ crypto_auth_hmacsha256_final(&hctx, U);
64
64
 
65
- memcpy(T, U, 32);
65
+ memcpy(T, U, 32);
66
+ /* LCOV_EXCL_START */
67
+ for (j = 2; j <= c; j++) {
68
+ crypto_auth_hmacsha256_init(&hctx, passwd, passwdlen);
69
+ crypto_auth_hmacsha256_update(&hctx, U, 32);
70
+ crypto_auth_hmacsha256_final(&hctx, U);
66
71
 
67
- for (j = 2; j <= c; j++) {
68
- crypto_auth_hmacsha256_init(&hctx, passwd, passwdlen);
69
- crypto_auth_hmacsha256_update(&hctx, U, 32);
70
- crypto_auth_hmacsha256_final(&hctx, U);
71
-
72
- for (k = 0; k < 32; k++) {
73
- T[k] ^= U[k];
72
+ for (k = 0; k < 32; k++) {
73
+ T[k] ^= U[k];
74
74
  }
75
- }
76
-
77
- clen = dkLen - i * 32;
78
- if (clen > 32) {
79
- clen = 32;
80
75
  }
81
- memcpy(&buf[i * 32], T, clen);
76
+ /* LCOV_EXCL_STOP */
77
+
78
+ clen = dkLen - i * 32;
79
+ if (clen > 32) {
80
+ clen = 32;
82
81
  }
82
+ memcpy(&buf[i * 32], T, clen);
83
+ }
83
84
  sodium_memzero((void *) &PShctx, sizeof PShctx);
84
85
  }
@@ -41,9 +41,11 @@ pickparams(unsigned long long opslimit, const size_t memlimit,
41
41
  }
42
42
  }
43
43
  maxrp = (opslimit / 4) / ((uint64_t) (1) << *N_log2);
44
+ /* LCOV_EXCL_START */
44
45
  if (maxrp > 0x3fffffff) {
45
46
  maxrp = 0x3fffffff;
46
47
  }
48
+ /* LCOV_EXCL_STOP */
47
49
  *p = (uint32_t) (maxrp) / *r;
48
50
  }
49
51
  return 0;
@@ -106,12 +108,12 @@ crypto_pwhash_scryptsalsa208sha256(unsigned char * const out,
106
108
 
107
109
  memset(out, 0, outlen);
108
110
  if (passwdlen > SIZE_MAX || outlen > SIZE_MAX) {
109
- errno = EFBIG;
110
- return -1;
111
+ errno = EFBIG; /* LCOV_EXCL_LINE */
112
+ return -1; /* LCOV_EXCL_LINE */
111
113
  }
112
114
  if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) {
113
- errno = EINVAL;
114
- return -1;
115
+ errno = EINVAL; /* LCOV_EXCL_LINE */
116
+ return -1; /* LCOV_EXCL_LINE */
115
117
  }
116
118
  return crypto_pwhash_scryptsalsa208sha256_ll((const uint8_t *) passwd,
117
119
  (size_t) passwdlen,
@@ -137,28 +139,30 @@ crypto_pwhash_scryptsalsa208sha256_str(char out[crypto_pwhash_scryptsalsa208sha2
137
139
 
138
140
  memset(out, 0, crypto_pwhash_scryptsalsa208sha256_STRBYTES);
139
141
  if (passwdlen > SIZE_MAX) {
140
- errno = EFBIG;
141
- return -1;
142
+ errno = EFBIG; /* LCOV_EXCL_LINE */
143
+ return -1; /* LCOV_EXCL_LINE */
142
144
  }
143
145
  if (pickparams(opslimit, memlimit, &N_log2, &p, &r) != 0) {
144
- errno = EINVAL;
145
- return -1;
146
+ errno = EINVAL; /* LCOV_EXCL_LINE */
147
+ return -1; /* LCOV_EXCL_LINE */
146
148
  }
147
149
  randombytes_buf(salt, sizeof salt);
148
150
  if (escrypt_gensalt_r(N_log2, r, p, salt, sizeof salt,
149
151
  (uint8_t *) setting, sizeof setting) == NULL) {
150
- errno = EINVAL;
151
- return -1;
152
+ errno = EINVAL; /* LCOV_EXCL_LINE */
153
+ return -1; /* LCOV_EXCL_LINE */
152
154
  }
153
155
  if (escrypt_init_local(&escrypt_local) != 0) {
154
- return -1;
156
+ return -1; /* LCOV_EXCL_LINE */
155
157
  }
156
158
  if (escrypt_r(&escrypt_local, (const uint8_t *) passwd, (size_t) passwdlen,
157
159
  (const uint8_t *) setting, (uint8_t *) out,
158
160
  crypto_pwhash_scryptsalsa208sha256_STRBYTES) == NULL) {
161
+ /* LCOV_EXCL_START */
159
162
  escrypt_free_local(&escrypt_local);
160
163
  errno = EINVAL;
161
164
  return -1;
165
+ /* LCOV_EXCL_STOP */
162
166
  }
163
167
  escrypt_free_local(&escrypt_local);
164
168
 
@@ -187,7 +191,7 @@ crypto_pwhash_scryptsalsa208sha256_str_verify(const char str[crypto_pwhash_scryp
187
191
  return -1;
188
192
  }
189
193
  if (escrypt_init_local(&escrypt_local) != 0) {
190
- return -1;
194
+ return -1; /* LCOV_EXCL_LINE */
191
195
  }
192
196
  if (escrypt_r(&escrypt_local, (const uint8_t *) passwd, (size_t) passwdlen,
193
197
  (const uint8_t *) str, (uint8_t *) wanted,
@@ -43,7 +43,7 @@ alloc_region(escrypt_region_t * region, size_t size)
43
43
  MAP_ANON | MAP_PRIVATE,
44
44
  #endif
45
45
  -1, 0)) == MAP_FAILED)
46
- base = NULL;
46
+ base = NULL; /* LCOV_EXCL_LINE */
47
47
  aligned = base;
48
48
  #elif defined(HAVE_POSIX_MEMALIGN)
49
49
  if ((errno = posix_memalign((void **) &base, 64, size)) != 0)
@@ -77,7 +77,7 @@ free_region(escrypt_region_t * region)
77
77
  if (region->base) {
78
78
  #ifdef MAP_ANON
79
79
  if (munmap(region->base, region->size))
80
- return -1;
80
+ return -1; /* LCOV_EXCL_LINE */
81
81
  #else
82
82
  free(region->base);
83
83
  #endif
@@ -365,9 +365,9 @@ escrypt_kdf_sse(escrypt_local_t * local,
365
365
  }
366
366
  if (local->size < need) {
367
367
  if (free_region(local))
368
- return -1;
368
+ return -1; /* LCOV_EXCL_LINE */
369
369
  if (!alloc_region(local, need))
370
- return -1;
370
+ return -1; /* LCOV_EXCL_LINE */
371
371
  }
372
372
  B = (uint8_t *)local->aligned;
373
373
  V = (uint32_t *)((uint8_t *)B + B_size);
@@ -27,9 +27,6 @@ crypto_secretbox_detached(unsigned char *c, unsigned char *mac,
27
27
  unsigned long long i;
28
28
  unsigned long long mlen0;
29
29
 
30
- if (mlen > SIZE_MAX - crypto_secretbox_MACBYTES) {
31
- return -1;
32
- }
33
30
  crypto_core_hsalsa20(subkey, n, k, sigma);
34
31
 
35
32
  memset(block0, 0U, crypto_secretbox_ZEROBYTES);
@@ -68,6 +65,9 @@ crypto_secretbox_easy(unsigned char *c, const unsigned char *m,
68
65
  unsigned long long mlen, const unsigned char *n,
69
66
  const unsigned char *k)
70
67
  {
68
+ if (mlen > SIZE_MAX - crypto_secretbox_MACBYTES) {
69
+ return -1;
70
+ }
71
71
  return crypto_secretbox_detached(c + crypto_secretbox_MACBYTES,
72
72
  c, m, mlen, n, k);
73
73
  }
@@ -32,7 +32,7 @@ int crypto_sign_keypair(unsigned char *pk, unsigned char *sk)
32
32
  unsigned char seed[32];
33
33
  int ret;
34
34
 
35
- randombytes(seed, sizeof seed);
35
+ randombytes_buf(seed, sizeof seed);
36
36
  ret = crypto_sign_seed_keypair(pk, sk, seed);
37
37
  sodium_memzero(seed, sizeof seed);
38
38
 
@@ -61,15 +61,19 @@ crypto_sign(unsigned char *sm, unsigned long long *smlen,
61
61
  {
62
62
  unsigned long long siglen;
63
63
 
64
- if (crypto_sign_detached(sm, &siglen, m, mlen, sk) != 0 ||
65
- siglen > crypto_sign_ed25519_BYTES) {
64
+ memmove(sm + crypto_sign_ed25519_BYTES, m, mlen);
65
+ /* LCOV_EXCL_START */
66
+ if (crypto_sign_detached(sm, &siglen, sm + crypto_sign_ed25519_BYTES,
67
+ mlen, sk) != 0 ||
68
+ siglen != crypto_sign_ed25519_BYTES) {
66
69
  if (smlen != NULL) {
67
70
  *smlen = 0;
68
71
  }
69
72
  memset(sm, 0, mlen + crypto_sign_ed25519_BYTES);
70
73
  return -1;
71
74
  }
72
- memmove(sm + siglen, m, mlen);
75
+ /* LCOV_EXCL_STOP */
76
+
73
77
  if (smlen != NULL) {
74
78
  *smlen = mlen + siglen;
75
79
  }
@@ -13,7 +13,7 @@ int crypto_sign_keypair(
13
13
  sc25519 scsk;
14
14
  ge25519 gepk;
15
15
 
16
- randombytes(sk, 32);
16
+ randombytes_buf(sk, 32);
17
17
  crypto_hash_sha512(sk, sk, 32);
18
18
  sk[0] &= 248;
19
19
  sk[31] &= 127;
@@ -101,7 +101,7 @@ chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, unsigned long long bytes
101
101
  unsigned long long i;
102
102
 
103
103
  if (!bytes) {
104
- return;
104
+ return; /* LCOV_EXCL_LINE */
105
105
  }
106
106
  j0 = x->input[0];
107
107
  j1 = x->input[1];
@@ -190,10 +190,11 @@ chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, unsigned long long bytes
190
190
  x15 = XOR(x15, U8TO32_LITTLE(m + 60));
191
191
 
192
192
  j12 = PLUSONE(j12);
193
+ /* LCOV_EXCL_START */
193
194
  if (!j12) {
194
195
  j13 = PLUSONE(j13);
195
- /* stopping at 2^70 bytes per nonce is user's responsibility */
196
196
  }
197
+ /* LCOV_EXCL_STOP */
197
198
 
198
199
  U32TO8_LITTLE(c + 0, x0);
199
200
  U32TO8_LITTLE(c + 4, x1);
@@ -26,28 +26,30 @@ typedef struct randombytes_implementation {
26
26
  } randombytes_implementation;
27
27
 
28
28
  SODIUM_EXPORT
29
- int randombytes_set_implementation(randombytes_implementation *impl);
29
+ void randombytes_buf(void * const buf, const size_t size);
30
30
 
31
31
  SODIUM_EXPORT
32
- void randombytes(unsigned char * const buf, const unsigned long long buf_len);
32
+ uint32_t randombytes_random(void);
33
33
 
34
34
  SODIUM_EXPORT
35
- const char *randombytes_implementation_name(void);
35
+ uint32_t randombytes_uniform(const uint32_t upper_bound);
36
36
 
37
37
  SODIUM_EXPORT
38
- uint32_t randombytes_random(void);
38
+ void randombytes_stir(void);
39
39
 
40
40
  SODIUM_EXPORT
41
- void randombytes_stir(void);
41
+ int randombytes_close(void);
42
42
 
43
43
  SODIUM_EXPORT
44
- uint32_t randombytes_uniform(const uint32_t upper_bound);
44
+ int randombytes_set_implementation(randombytes_implementation *impl);
45
45
 
46
46
  SODIUM_EXPORT
47
- void randombytes_buf(void * const buf, const size_t size);
47
+ const char *randombytes_implementation_name(void);
48
+
49
+ /* -- Compatibility layer with NaCl -- */
48
50
 
49
51
  SODIUM_EXPORT
50
- int randombytes_close(void);
52
+ void randombytes(unsigned char * const buf, const unsigned long long buf_len);
51
53
 
52
54
  #ifdef __cplusplus
53
55
  }
@@ -67,7 +67,10 @@ sodium_hrtime(void)
67
67
  #ifdef _WIN32
68
68
  struct _timeb tb;
69
69
 
70
- _ftime_s(&tb);
70
+ # pragma warning(push)
71
+ # pragma warning(disable: 4996)
72
+ _ftime(&tb);
73
+ # pragma warning(pop)
71
74
  tv.tv_sec = (long) tb.time;
72
75
  tv.tv_usec = ((int) tb.millitm) * 1000;
73
76
  ret = 0;
@@ -91,12 +94,12 @@ safe_read(const int fd, void * const buf_, size_t count)
91
94
  assert(count > (size_t) 0U);
92
95
  do {
93
96
  while ((readnb = read(fd, buf, count)) < (ssize_t) 0 &&
94
- errno == EINTR);
97
+ errno == EINTR); /* LCOV_EXCL_LINE */
95
98
  if (readnb < (ssize_t) 0) {
96
- return readnb;
99
+ return readnb; /* LCOV_EXCL_LINE */
97
100
  }
98
101
  if (readnb == (ssize_t) 0) {
99
- break;
102
+ break; /* LCOV_EXCL_LINE */
100
103
  }
101
104
  count -= (size_t) readnb;
102
105
  buf += readnb;
@@ -110,6 +113,7 @@ safe_read(const int fd, void * const buf_, size_t count)
110
113
  static int
111
114
  randombytes_salsa20_random_random_dev_open(void)
112
115
  {
116
+ /* LCOV_EXCL_START */
113
117
  struct stat st;
114
118
  static const char *devices[] = {
115
119
  # ifndef USE_BLOCKING_RANDOM
@@ -131,6 +135,7 @@ randombytes_salsa20_random_random_dev_open(void)
131
135
  } while (*device != NULL);
132
136
 
133
137
  return -1;
138
+ /* LCOV_EXCL_STOP */
134
139
  }
135
140
 
136
141
  static void
@@ -143,7 +148,7 @@ randombytes_salsa20_random_init(void)
143
148
 
144
149
  if ((stream.random_data_source_fd =
145
150
  randombytes_salsa20_random_random_dev_open()) == -1) {
146
- abort();
151
+ abort(); /* LCOV_EXCL_LINE */
147
152
  }
148
153
  errno = errno_save;
149
154
  }
@@ -181,11 +186,11 @@ randombytes_salsa20_random_stir(void)
181
186
  #ifndef _WIN32
182
187
  if (safe_read(stream.random_data_source_fd, m0,
183
188
  sizeof m0) != (ssize_t) sizeof m0) {
184
- abort();
189
+ abort(); /* LCOV_EXCL_LINE */
185
190
  }
186
191
  #else /* _WIN32 */
187
192
  if (! RtlGenRandom((PVOID) m0, (ULONG) sizeof m0)) {
188
- abort();
193
+ abort(); /* LCOV_EXCL_LINE */
189
194
  }
190
195
  #endif
191
196
  COMPILER_ASSERT(sizeof stream.key == crypto_auth_hmacsha512256_BYTES);
@@ -319,7 +324,7 @@ randombytes_salsa20_random_uniform(const uint32_t upper_bound)
319
324
  if (r >= min) {
320
325
  break;
321
326
  }
322
- }
327
+ } /* LCOV_EXCL_LINE */
323
328
  return r % upper_bound;
324
329
  }
325
330