rbnacl-libsodium 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/lib/rbnacl/libsodium/version.rb +1 -1
- data/vendor/libsodium/AUTHORS +0 -3
- data/vendor/libsodium/ChangeLog +24 -0
- data/vendor/libsodium/THANKS +2 -0
- data/vendor/libsodium/autom4te.cache/output.1 +35 -147
- data/vendor/libsodium/autom4te.cache/output.3 +35 -147
- data/vendor/libsodium/autom4te.cache/requests +127 -127
- data/vendor/libsodium/autom4te.cache/traces.1 +244 -254
- data/vendor/libsodium/autom4te.cache/traces.3 +111 -113
- data/vendor/libsodium/builds/msvc/properties/Common.props +3 -1
- data/vendor/libsodium/builds/msvc/properties/Release.props +1 -3
- data/vendor/libsodium/builds/msvc/version.h +3 -3
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +1 -11
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +1 -37
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +10 -1
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +10 -1
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +1 -11
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +1 -37
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +10 -1
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +10 -1
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +1 -11
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +1 -37
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +10 -1
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +10 -1
- data/vendor/libsodium/configure +33 -145
- data/vendor/libsodium/configure.ac +22 -23
- data/vendor/libsodium/dist-build/android-build.sh +1 -0
- data/vendor/libsodium/dist-build/emscripten.sh +2 -2
- data/vendor/libsodium/dist-build/ios.sh +1 -0
- data/vendor/libsodium/libsodium.pc.in +1 -1
- data/vendor/libsodium/libsodium.vcxproj +1 -5
- data/vendor/libsodium/libsodium.vcxproj.filters +1 -13
- data/vendor/libsodium/msvc-scripts/process.bat +3 -3
- data/vendor/libsodium/msvc-scripts/sodium.props +4 -1
- data/vendor/libsodium/src/libsodium/Makefile.am +1 -10
- data/vendor/libsodium/src/libsodium/Makefile.in +5 -79
- data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/cp/verify_hmacsha256.c +3 -1
- data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/cp/verify_hmacsha512.c +3 -1
- data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/cp/verify_hmacsha512256.c +3 -1
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +6 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/pow225521.h +2 -2
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +46 -3
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +2 -10
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +7 -1
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519_api.c +18 -0
- data/vendor/libsodium/src/libsodium/include/Makefile.am +0 -1
- data/vendor/libsodium/src/libsodium/include/Makefile.in +0 -1
- data/vendor/libsodium/src/libsodium/include/sodium.h +0 -1
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +1 -2
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +5 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +15 -0
- data/vendor/libsodium/src/libsodium/include/sodium/utils.h +54 -3
- data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +22 -7
- data/vendor/libsodium/src/libsodium/sodium/core.c +2 -0
- data/vendor/libsodium/src/libsodium/sodium/utils.c +305 -31
- data/vendor/libsodium/test/default/Makefile.am +18 -16
- data/vendor/libsodium/test/default/Makefile.in +141 -76
- data/vendor/libsodium/test/default/ed25519_convert.c +48 -0
- data/vendor/libsodium/test/default/ed25519_convert.exp +3 -0
- data/vendor/libsodium/test/default/sign.c +15 -4
- data/vendor/libsodium/test/default/sodium_utils2.c +70 -0
- data/vendor/libsodium/test/default/sodium_utils2.exp +3 -0
- data/vendor/libsodium/test/default/sodium_utils3.c +55 -0
- data/vendor/libsodium/test/default/sodium_utils3.exp +2 -0
- metadata +8 -24
- data/vendor/libsodium/src/libsodium/crypto_auth/try.c +0 -119
- data/vendor/libsodium/src/libsodium/crypto_box/try.c +0 -195
- data/vendor/libsodium/src/libsodium/crypto_hash/try.c +0 -76
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/try.c +0 -125
- data/vendor/libsodium/src/libsodium/crypto_secretbox/try.c +0 -129
- data/vendor/libsodium/src/libsodium/crypto_sign/try.c +0 -87
- data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/aes-table-be.h +0 -273
- data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/aes-table-le.h +0 -274
- data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/aes-table.h +0 -62
- data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/aes256-ctr.c +0 -239
- data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/aes256.h +0 -171
- data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/api.h +0 -13
- data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/hongjun/ecrypt-sync.h +0 -27
- data/vendor/libsodium/src/libsodium/crypto_stream/aes256estream/stream_aes256estream_api.c +0 -16
- data/vendor/libsodium/src/libsodium/crypto_stream/try.c +0 -122
- data/vendor/libsodium/src/libsodium/crypto_verify/try.c +0 -76
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes256estream.h +0 -67
- data/vendor/libsodium/src/libsodium/sodium/compat.c +0 -361
- data/vendor/libsodium/test/default/stream5.c +0 -29
- data/vendor/libsodium/test/default/stream5.exp +0 -1
- data/vendor/libsodium/test/default/stream6.c +0 -54
- data/vendor/libsodium/test/default/stream6.exp +0 -17
@@ -1,8 +1,10 @@
|
|
1
1
|
#ifndef __STDC_WANT_LIB_EXT1__
|
2
2
|
# define __STDC_WANT_LIB_EXT1__ 1
|
3
3
|
#endif
|
4
|
+
#include <assert.h>
|
4
5
|
#include <errno.h>
|
5
6
|
#include <limits.h>
|
7
|
+
#include <signal.h>
|
6
8
|
#include <stddef.h>
|
7
9
|
#include <stdint.h>
|
8
10
|
#include <stdlib.h>
|
@@ -17,7 +19,31 @@
|
|
17
19
|
#ifdef _WIN32
|
18
20
|
# include <windows.h>
|
19
21
|
# include <wincrypt.h>
|
22
|
+
#else
|
23
|
+
# include <unistd.h>
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#define CANARY_SIZE 16U
|
27
|
+
#define GARBAGE_VALUE 0xd0
|
28
|
+
|
29
|
+
#ifndef MAP_NOCORE
|
30
|
+
# define MAP_NOCORE 0
|
31
|
+
#endif
|
32
|
+
#if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
|
33
|
+
# define MAP_ANON MAP_ANONYMOUS
|
20
34
|
#endif
|
35
|
+
#if defined(_WIN32) || defined(MAP_ANON) || defined(HAVE_POSIX_MEMALIGN)
|
36
|
+
# define HAVE_ALIGNED_MALLOC
|
37
|
+
#endif
|
38
|
+
#if defined(HAVE_MPROTECT) && !(defined(PROT_NONE) && defined(PROT_READ) && defined(PROT_WRITE))
|
39
|
+
# undef HAVE_MPROTECT
|
40
|
+
#endif
|
41
|
+
#if defined(HAVE_ALIGNED_MALLOC) && (defined(_WIN32) || defined(HAVE_MPROTECT))
|
42
|
+
# define HAVE_PAGE_PROTECTION
|
43
|
+
#endif
|
44
|
+
|
45
|
+
static size_t page_size;
|
46
|
+
static unsigned char canary[CANARY_SIZE];
|
21
47
|
|
22
48
|
#ifdef HAVE_WEAK_SYMBOLS
|
23
49
|
__attribute__((weak)) void
|
@@ -31,7 +57,7 @@ __sodium_dummy_symbol_to_prevent_lto(void * const pnt, const size_t len)
|
|
31
57
|
void
|
32
58
|
sodium_memzero(void * const pnt, const size_t len)
|
33
59
|
{
|
34
|
-
#ifdef
|
60
|
+
#ifdef _WIN32
|
35
61
|
SecureZeroMemory(pnt, len);
|
36
62
|
#elif defined(HAVE_MEMSET_S)
|
37
63
|
if (memset_s(pnt, (rsize_t) len, 0, (rsize_t) len) != 0) {
|
@@ -66,34 +92,6 @@ sodium_memcmp(const void * const b1_, const void * const b2_, size_t len)
|
|
66
92
|
return (int) ((1 & ((d - 1) >> 8)) - 1);
|
67
93
|
}
|
68
94
|
|
69
|
-
unsigned char *
|
70
|
-
_sodium_alignedcalloc(unsigned char ** const unaligned_p, const size_t len)
|
71
|
-
{
|
72
|
-
unsigned char *aligned;
|
73
|
-
unsigned char *unaligned;
|
74
|
-
size_t i;
|
75
|
-
|
76
|
-
if (SIZE_MAX - (size_t) 256U < len ||
|
77
|
-
(unaligned = (unsigned char *) malloc(len + (size_t) 256U)) == NULL) {
|
78
|
-
*unaligned_p = NULL;
|
79
|
-
return NULL;
|
80
|
-
}
|
81
|
-
*unaligned_p = unaligned;
|
82
|
-
#ifdef HAVE_ARC4RANDOM_BUF
|
83
|
-
(void) i;
|
84
|
-
arc4random_buf(unaligned, len + (size_t) 256U);
|
85
|
-
#else
|
86
|
-
for (i = (size_t) 0U; i < len + (size_t) 256U; ++i) {
|
87
|
-
unaligned[i] = (unsigned char) rand();
|
88
|
-
}
|
89
|
-
#endif
|
90
|
-
aligned = unaligned + 64;
|
91
|
-
aligned += (ptrdiff_t) 63 & (-(ptrdiff_t) aligned);
|
92
|
-
memset(aligned, 0, len);
|
93
|
-
|
94
|
-
return aligned;
|
95
|
-
}
|
96
|
-
|
97
95
|
char *
|
98
96
|
sodium_bin2hex(char * const hex, const size_t hex_maxlen,
|
99
97
|
const unsigned char * const bin, const size_t bin_len)
|
@@ -178,7 +176,7 @@ sodium_mlock(void * const addr, const size_t len)
|
|
178
176
|
#endif
|
179
177
|
#ifdef HAVE_MLOCK
|
180
178
|
return mlock(addr, len);
|
181
|
-
#elif defined(
|
179
|
+
#elif defined(_WIN32)
|
182
180
|
return -(VirtualLock(addr, len) == 0);
|
183
181
|
#else
|
184
182
|
errno = ENOSYS;
|
@@ -195,10 +193,286 @@ sodium_munlock(void * const addr, const size_t len)
|
|
195
193
|
#endif
|
196
194
|
#ifdef HAVE_MLOCK
|
197
195
|
return munlock(addr, len);
|
198
|
-
#elif defined(
|
196
|
+
#elif defined(_WIN32)
|
199
197
|
return -(VirtualUnlock(addr, len) == 0);
|
200
198
|
#else
|
201
199
|
errno = ENOSYS;
|
202
200
|
return -1;
|
203
201
|
#endif
|
204
202
|
}
|
203
|
+
|
204
|
+
int
|
205
|
+
_sodium_alloc_init(void)
|
206
|
+
{
|
207
|
+
#if defined(_SC_PAGESIZE)
|
208
|
+
long page_size_ = sysconf(_SC_PAGESIZE);
|
209
|
+
if (page_size_ > 0L) {
|
210
|
+
page_size = (size_t) page_size_;
|
211
|
+
}
|
212
|
+
#elif defined(_WIN32)
|
213
|
+
SYSTEM_INFO si;
|
214
|
+
GetSystemInfo(&si);
|
215
|
+
page_size = (size_t) si.dwPageSize;
|
216
|
+
#endif
|
217
|
+
if (page_size < CANARY_SIZE) {
|
218
|
+
abort();
|
219
|
+
}
|
220
|
+
randombytes_buf(canary, sizeof canary);
|
221
|
+
|
222
|
+
return 0;
|
223
|
+
}
|
224
|
+
|
225
|
+
static inline size_t
|
226
|
+
_page_round(const size_t size)
|
227
|
+
{
|
228
|
+
const size_t page_mask = page_size - 1U;
|
229
|
+
|
230
|
+
return (size + page_mask) & ~page_mask;
|
231
|
+
}
|
232
|
+
|
233
|
+
static int
|
234
|
+
_mprotect_noaccess(void *ptr, size_t size)
|
235
|
+
{
|
236
|
+
#if defined(HAVE_MPROTECT) && defined(HAVE_PAGE_PROTECTION)
|
237
|
+
return mprotect(ptr, size, PROT_NONE);
|
238
|
+
#elif defined(_WIN32)
|
239
|
+
{
|
240
|
+
DWORD old;
|
241
|
+
return -(VirtualProtect(ptr, size, PAGE_NOACCESS, &old) == 0);
|
242
|
+
}
|
243
|
+
#else
|
244
|
+
errno = ENOSYS;
|
245
|
+
return -1;
|
246
|
+
#endif
|
247
|
+
}
|
248
|
+
|
249
|
+
static int
|
250
|
+
_mprotect_readonly(void *ptr, size_t size)
|
251
|
+
{
|
252
|
+
#if defined(HAVE_MPROTECT) && defined(HAVE_PAGE_PROTECTION)
|
253
|
+
return mprotect(ptr, size, PROT_READ);
|
254
|
+
#elif defined(_WIN32)
|
255
|
+
{
|
256
|
+
DWORD old;
|
257
|
+
return -(VirtualProtect(ptr, size, PAGE_READONLY, &old) == 0);
|
258
|
+
}
|
259
|
+
#else
|
260
|
+
errno = ENOSYS;
|
261
|
+
return -1;
|
262
|
+
#endif
|
263
|
+
}
|
264
|
+
|
265
|
+
static int
|
266
|
+
_mprotect_readwrite(void *ptr, size_t size)
|
267
|
+
{
|
268
|
+
#if defined(HAVE_MPROTECT) && defined(HAVE_PAGE_PROTECTION)
|
269
|
+
return mprotect(ptr, size, PROT_READ | PROT_WRITE);
|
270
|
+
#elif defined(_WIN32)
|
271
|
+
{
|
272
|
+
DWORD old;
|
273
|
+
return -(VirtualProtect(ptr, size, PAGE_READWRITE, &old) == 0);
|
274
|
+
}
|
275
|
+
#else
|
276
|
+
errno = ENOSYS;
|
277
|
+
return -1;
|
278
|
+
#endif
|
279
|
+
}
|
280
|
+
|
281
|
+
static void
|
282
|
+
_out_of_bounds(void)
|
283
|
+
{
|
284
|
+
#ifdef SIGSEGV
|
285
|
+
raise(SIGSEGV);
|
286
|
+
#elif defined(SIGKILL)
|
287
|
+
raise(SIGKILL);
|
288
|
+
#endif
|
289
|
+
abort();
|
290
|
+
}
|
291
|
+
|
292
|
+
static __attribute__((malloc)) unsigned char *
|
293
|
+
_alloc_aligned(const size_t size)
|
294
|
+
{
|
295
|
+
void *ptr;
|
296
|
+
|
297
|
+
#ifdef MAP_ANON
|
298
|
+
if ((ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
|
299
|
+
MAP_ANON | MAP_PRIVATE | MAP_NOCORE, -1, 0)) == MAP_FAILED) {
|
300
|
+
ptr = NULL;
|
301
|
+
}
|
302
|
+
#elif defined(HAVE_POSIX_MEMALIGN)
|
303
|
+
if (posix_memalign(&ptr, page_size, size) != 0) {
|
304
|
+
ptr = NULL;
|
305
|
+
}
|
306
|
+
#elif defined(_WIN32)
|
307
|
+
ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
308
|
+
#elif !defined(HAVE_ALIGNED_MALLOC)
|
309
|
+
ptr = malloc(size);
|
310
|
+
#else
|
311
|
+
# error Bug
|
312
|
+
#endif
|
313
|
+
return (unsigned char *) ptr;
|
314
|
+
}
|
315
|
+
|
316
|
+
static void
|
317
|
+
_free_aligned(unsigned char * const ptr, const size_t size)
|
318
|
+
{
|
319
|
+
#ifdef MAP_ANON
|
320
|
+
(void) munmap(ptr, size);
|
321
|
+
#elif defined(HAVE_POSIX_MEMALIGN)
|
322
|
+
free(ptr);
|
323
|
+
#elif defined(_WIN32)
|
324
|
+
VirtualFree(ptr, 0U, MEM_RELEASE);
|
325
|
+
#else
|
326
|
+
free(ptr);
|
327
|
+
#endif
|
328
|
+
}
|
329
|
+
|
330
|
+
static unsigned char *
|
331
|
+
_unprotected_ptr_from_user_ptr(const void *ptr)
|
332
|
+
{
|
333
|
+
uintptr_t unprotected_ptr_u;
|
334
|
+
unsigned char *canary_ptr;
|
335
|
+
size_t page_mask;
|
336
|
+
|
337
|
+
canary_ptr = ((unsigned char *) ptr) - sizeof canary;
|
338
|
+
page_mask = page_size - 1U;
|
339
|
+
unprotected_ptr_u = ((uintptr_t) canary_ptr & (uintptr_t) ~page_mask);
|
340
|
+
if (unprotected_ptr_u <= page_size * 2U) {
|
341
|
+
abort();
|
342
|
+
}
|
343
|
+
return (unsigned char *) unprotected_ptr_u;
|
344
|
+
}
|
345
|
+
|
346
|
+
static __attribute__((malloc)) void *
|
347
|
+
_sodium_malloc(const size_t size)
|
348
|
+
{
|
349
|
+
void *user_ptr;
|
350
|
+
unsigned char *base_ptr;
|
351
|
+
unsigned char *canary_ptr;
|
352
|
+
unsigned char *unprotected_ptr;
|
353
|
+
size_t page_mask;
|
354
|
+
size_t size_with_canary;
|
355
|
+
size_t total_size;
|
356
|
+
size_t unprotected_size;
|
357
|
+
|
358
|
+
if (size >= SIZE_MAX - page_size * 4U) {
|
359
|
+
errno = ENOMEM;
|
360
|
+
return NULL;
|
361
|
+
}
|
362
|
+
if (page_size <= sizeof canary || page_size < sizeof unprotected_size) {
|
363
|
+
abort();
|
364
|
+
}
|
365
|
+
size_with_canary = (sizeof canary) + size;
|
366
|
+
unprotected_size = _page_round(size_with_canary);
|
367
|
+
total_size = page_size + page_size + unprotected_size + page_size;
|
368
|
+
if ((base_ptr = _alloc_aligned(total_size)) == NULL) {
|
369
|
+
return NULL;
|
370
|
+
}
|
371
|
+
unprotected_ptr = base_ptr + page_size * 2U;
|
372
|
+
_mprotect_noaccess(base_ptr + page_size, page_size);
|
373
|
+
#ifndef HAVE_PAGE_PROTECTION
|
374
|
+
memcpy(unprotected_ptr + unprotected_size, canary, sizeof canary);
|
375
|
+
#endif
|
376
|
+
_mprotect_noaccess(unprotected_ptr + unprotected_size, page_size);
|
377
|
+
sodium_mlock(unprotected_ptr, unprotected_size);
|
378
|
+
page_mask = page_size - 1U;
|
379
|
+
canary_ptr = unprotected_ptr + _page_round(size_with_canary) -
|
380
|
+
size_with_canary;
|
381
|
+
user_ptr = canary_ptr + sizeof canary;
|
382
|
+
memcpy(canary_ptr, canary, sizeof canary);
|
383
|
+
memcpy(base_ptr, &unprotected_size, sizeof unprotected_size);
|
384
|
+
_mprotect_readonly(base_ptr, page_size);
|
385
|
+
assert(_unprotected_ptr_from_user_ptr(user_ptr) == unprotected_ptr);
|
386
|
+
|
387
|
+
return user_ptr;
|
388
|
+
}
|
389
|
+
|
390
|
+
__attribute__((malloc)) void *
|
391
|
+
sodium_malloc(const size_t size)
|
392
|
+
{
|
393
|
+
void *ptr;
|
394
|
+
|
395
|
+
if ((ptr = _sodium_malloc(size)) == NULL) {
|
396
|
+
return NULL;
|
397
|
+
}
|
398
|
+
memset(ptr, (int) GARBAGE_VALUE, size);
|
399
|
+
|
400
|
+
return ptr;
|
401
|
+
}
|
402
|
+
|
403
|
+
__attribute__((malloc)) void *
|
404
|
+
sodium_allocarray(size_t count, size_t size)
|
405
|
+
{
|
406
|
+
size_t total_size;
|
407
|
+
|
408
|
+
if (size >= SIZE_MAX / count) {
|
409
|
+
errno = ENOMEM;
|
410
|
+
return NULL;
|
411
|
+
}
|
412
|
+
total_size = count * size;
|
413
|
+
|
414
|
+
return sodium_malloc(total_size);
|
415
|
+
}
|
416
|
+
|
417
|
+
void
|
418
|
+
sodium_free(void *ptr)
|
419
|
+
{
|
420
|
+
unsigned char *base_ptr;
|
421
|
+
unsigned char *canary_ptr;
|
422
|
+
unsigned char *unprotected_ptr;
|
423
|
+
size_t total_size;
|
424
|
+
size_t unprotected_size;
|
425
|
+
|
426
|
+
if (ptr == NULL) {
|
427
|
+
return;
|
428
|
+
}
|
429
|
+
canary_ptr = ((unsigned char *) ptr) - sizeof canary;
|
430
|
+
if (sodium_memcmp(canary_ptr, canary, sizeof canary) != 0) {
|
431
|
+
_out_of_bounds();
|
432
|
+
}
|
433
|
+
unprotected_ptr = _unprotected_ptr_from_user_ptr(ptr);
|
434
|
+
base_ptr = unprotected_ptr - page_size * 2U;
|
435
|
+
memcpy(&unprotected_size, base_ptr, sizeof unprotected_size);
|
436
|
+
total_size = page_size + page_size + unprotected_size + page_size;
|
437
|
+
_mprotect_readwrite(base_ptr, total_size);
|
438
|
+
#ifndef HAVE_PAGE_PROTECTION
|
439
|
+
if (sodium_memcmp(unprotected_ptr + unprotected_size,
|
440
|
+
canary, sizeof canary) != 0) {
|
441
|
+
_out_of_bounds();
|
442
|
+
}
|
443
|
+
#endif
|
444
|
+
sodium_munlock(unprotected_ptr, unprotected_size);
|
445
|
+
_free_aligned(base_ptr, total_size);
|
446
|
+
}
|
447
|
+
|
448
|
+
static int
|
449
|
+
_sodium_mprotect(void *ptr, int (*cb)(void *ptr, size_t size))
|
450
|
+
{
|
451
|
+
unsigned char *base_ptr;
|
452
|
+
unsigned char *unprotected_ptr;
|
453
|
+
size_t unprotected_size;
|
454
|
+
|
455
|
+
unprotected_ptr = _unprotected_ptr_from_user_ptr(ptr);
|
456
|
+
base_ptr = unprotected_ptr - page_size * 2U;
|
457
|
+
memcpy(&unprotected_size, base_ptr, sizeof unprotected_size);
|
458
|
+
|
459
|
+
return cb(unprotected_ptr, unprotected_size);
|
460
|
+
}
|
461
|
+
|
462
|
+
int
|
463
|
+
sodium_mprotect_noaccess(void *ptr)
|
464
|
+
{
|
465
|
+
return _sodium_mprotect(ptr, _mprotect_noaccess);
|
466
|
+
}
|
467
|
+
|
468
|
+
int
|
469
|
+
sodium_mprotect_readonly(void *ptr)
|
470
|
+
{
|
471
|
+
return _sodium_mprotect(ptr, _mprotect_readonly);
|
472
|
+
}
|
473
|
+
|
474
|
+
int
|
475
|
+
sodium_mprotect_readwrite(void *ptr)
|
476
|
+
{
|
477
|
+
return _sodium_mprotect(ptr, _mprotect_readwrite);
|
478
|
+
}
|
@@ -23,6 +23,7 @@ EXTRA_DIST = \
|
|
23
23
|
core4.exp \
|
24
24
|
core5.exp \
|
25
25
|
core6.exp \
|
26
|
+
ed25519_convert.exp \
|
26
27
|
generichash.exp \
|
27
28
|
generichash2.exp \
|
28
29
|
generichash3.exp \
|
@@ -48,13 +49,13 @@ EXTRA_DIST = \
|
|
48
49
|
sign.exp \
|
49
50
|
sodium_core.exp \
|
50
51
|
sodium_utils.exp \
|
52
|
+
sodium_utils2.exp \
|
53
|
+
sodium_utils3.exp \
|
51
54
|
sodium_version.exp \
|
52
55
|
stream.exp \
|
53
56
|
stream2.exp \
|
54
57
|
stream3.exp \
|
55
58
|
stream4.exp \
|
56
|
-
stream5.exp \
|
57
|
-
stream6.exp \
|
58
59
|
verify1.exp
|
59
60
|
|
60
61
|
DISTCLEANFILES = \
|
@@ -79,6 +80,7 @@ DISTCLEANFILES = \
|
|
79
80
|
core4.res \
|
80
81
|
core5.res \
|
81
82
|
core6.res \
|
83
|
+
ed25519_convert.res \
|
82
84
|
generichash.res \
|
83
85
|
generichash2.res \
|
84
86
|
generichash3.res \
|
@@ -104,13 +106,13 @@ DISTCLEANFILES = \
|
|
104
106
|
sign.res \
|
105
107
|
sodium_core.res \
|
106
108
|
sodium_utils.res \
|
109
|
+
sodium_utils2.res \
|
110
|
+
sodium_utils3.res \
|
107
111
|
sodium_version.res \
|
108
112
|
stream.res \
|
109
113
|
stream2.res \
|
110
114
|
stream3.res \
|
111
115
|
stream4.res \
|
112
|
-
stream5.res \
|
113
|
-
stream6.res \
|
114
116
|
verify1.res
|
115
117
|
|
116
118
|
AM_CPPFLAGS = \
|
@@ -143,6 +145,7 @@ TESTS_TARGETS = \
|
|
143
145
|
core4 \
|
144
146
|
core5 \
|
145
147
|
core6 \
|
148
|
+
ed25519_convert \
|
146
149
|
generichash \
|
147
150
|
generichash2 \
|
148
151
|
generichash3 \
|
@@ -168,6 +171,8 @@ TESTS_TARGETS = \
|
|
168
171
|
sign \
|
169
172
|
sodium_core \
|
170
173
|
sodium_utils \
|
174
|
+
sodium_utils2 \
|
175
|
+
sodium_utils3 \
|
171
176
|
sodium_version \
|
172
177
|
stream \
|
173
178
|
stream2 \
|
@@ -175,12 +180,6 @@ TESTS_TARGETS = \
|
|
175
180
|
stream4 \
|
176
181
|
verify1
|
177
182
|
|
178
|
-
if !MINIMAL
|
179
|
-
TESTS_TARGETS += \
|
180
|
-
stream5 \
|
181
|
-
stream6
|
182
|
-
endif
|
183
|
-
|
184
183
|
check_PROGRAMS = $(TESTS_TARGETS)
|
185
184
|
|
186
185
|
TESTS = $(TESTS_TARGETS)
|
@@ -251,6 +250,9 @@ core5_LDADD = $(TESTS_LDADD)
|
|
251
250
|
core6_SOURCE = cmptest.h core6.c
|
252
251
|
core6_LDADD = $(TESTS_LDADD)
|
253
252
|
|
253
|
+
ed25519_convert_SOURCE = cmptest.h ed25519_convert.c
|
254
|
+
ed25519_convert_LDADD = $(TESTS_LDADD)
|
255
|
+
|
254
256
|
generichash_SOURCE = cmptest.h generichash.c
|
255
257
|
generichash_LDADD = $(TESTS_LDADD)
|
256
258
|
|
@@ -326,6 +328,12 @@ sodium_core_LDADD = $(TESTS_LDADD)
|
|
326
328
|
sodium_utils_SOURCE = cmptest.h sodium_utils.c
|
327
329
|
sodium_utils_LDADD = $(TESTS_LDADD)
|
328
330
|
|
331
|
+
sodium_utils2_SOURCE = cmptest.h sodium_utils2.c
|
332
|
+
sodium_utils2_LDADD = $(TESTS_LDADD)
|
333
|
+
|
334
|
+
sodium_utils3_SOURCE = cmptest.h sodium_utils3.c
|
335
|
+
sodium_utils3_LDADD = $(TESTS_LDADD)
|
336
|
+
|
329
337
|
sodium_version_SOURCE = cmptest.h sodium_version.c
|
330
338
|
sodium_version_LDADD = $(TESTS_LDADD)
|
331
339
|
|
@@ -341,12 +349,6 @@ stream3_LDADD = $(TESTS_LDADD)
|
|
341
349
|
stream4_SOURCE = cmptest.h stream4.c
|
342
350
|
stream4_LDADD = $(TESTS_LDADD)
|
343
351
|
|
344
|
-
stream5_SOURCE = cmptest.h stream5.c
|
345
|
-
stream5_LDADD = $(TESTS_LDADD)
|
346
|
-
|
347
|
-
stream6_SOURCE = cmptest.h stream6.c
|
348
|
-
stream6_LDADD = $(TESTS_LDADD)
|
349
|
-
|
350
352
|
verify1_SOURCE = cmptest.h verify1.c
|
351
353
|
verify1_LDADD = $(TESTS_LDADD)
|
352
354
|
|