From 30fa7c7d19487155581089842f16f1ab07caf0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Fri, 4 Dec 2015 10:20:20 -0300 Subject: [PATCH 1/9] Avoiding conditional directives that split up parts of statements. --- .../nosse/pwhash_scryptsalsa208sha256_nosse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c index 97d9ba6878..af75edde7e 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c @@ -257,11 +257,11 @@ escrypt_kdf_nosse(escrypt_local_t * local, errno = EINVAL; return -1; } - if ((r > SIZE_MAX / 128 / p) || + int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r); #if SIZE_MAX / 256 <= UINT32_MAX - (r > SIZE_MAX / 256) || + test = test || (r > SIZE_MAX / 256); #endif - (N > SIZE_MAX / 128 / r)) { + if (test) { errno = ENOMEM; return -1; } From dc5881dd7b2767dd42d1f3c61631e89659c4fe61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Fri, 4 Dec 2015 10:24:00 -0300 Subject: [PATCH 2/9] Avoiding conditional directives that split up parts of statements. --- .../sse/pwhash_scryptsalsa208sha256_sse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index 856a655e3f..ebc363b04a 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c @@ -345,11 +345,11 @@ escrypt_kdf_sse(escrypt_local_t * local, errno = EINVAL; return -1; } - if ((r > SIZE_MAX / 128 / p) || + int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r); #if SIZE_MAX / 256 <= UINT32_MAX - (r > SIZE_MAX / 256) || -#endif - (N > SIZE_MAX / 128 / r)) { + test = test || (r > SIZE_MAX / 256); +#endif + if (test) { errno = ENOMEM; return -1; } From 68ca982b6862b24e9422a786b89517f89c34cf53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Fri, 4 Dec 2015 10:34:23 -0300 Subject: [PATCH 3/9] Avoiding conditional directives that split up parts of statements. --- .../crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c index 5819651454..78acb1819e 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c @@ -41,13 +41,13 @@ alloc_region(escrypt_region_t * region, size_t size) { uint8_t * base, * aligned; #ifdef MAP_ANON - if ((base = (uint8_t *) mmap(NULL, size, PROT_READ | PROT_WRITE, + int flags; #ifdef MAP_NOCORE - MAP_ANON | MAP_PRIVATE | MAP_NOCORE, + flags = MAP_ANON | MAP_PRIVATE | MAP_NOCORE; #else - MAP_ANON | MAP_PRIVATE, + flags = MAP_ANON | MAP_PRIVATE; #endif - -1, 0)) == MAP_FAILED) + if ((base = (uint8_t *) mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0)) == MAP_FAILED) base = NULL; aligned = base; #elif defined(HAVE_POSIX_MEMALIGN) From 4dcfa8b1a15a9b5120c3f29926e21ffcb62f8b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Tue, 8 Mar 2016 15:11:41 -0300 Subject: [PATCH 4/9] Indenting #ifdefs (as requested by @GrayHatter) --- .../nosse/pwhash_scryptsalsa208sha256_nosse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c index af75edde7e..da2a103e3b 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c @@ -239,12 +239,12 @@ escrypt_kdf_nosse(escrypt_local_t * local, uint32_t i; /* Sanity-check parameters. */ -#if SIZE_MAX > UINT32_MAX + #if SIZE_MAX > UINT32_MAX if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { errno = EFBIG; return -1; } -#endif + #endif if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { errno = EFBIG; return -1; @@ -258,9 +258,9 @@ escrypt_kdf_nosse(escrypt_local_t * local, return -1; } int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r); -#if SIZE_MAX / 256 <= UINT32_MAX + #if SIZE_MAX / 256 <= UINT32_MAX test = test || (r > SIZE_MAX / 256); -#endif + #endif if (test) { errno = ENOMEM; return -1; From 4e2c2dfcb1b42339884a6ac8d095153eae6798ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Tue, 8 Mar 2016 15:16:11 -0300 Subject: [PATCH 5/9] Indenting #ifdefs (as requested by @GrayHatter) --- .../sse/pwhash_scryptsalsa208sha256_sse.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index ebc363b04a..d1d11b780b 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c @@ -319,16 +319,16 @@ escrypt_kdf_sse(escrypt_local_t * local, size_t B_size, V_size, XY_size, need; uint8_t * B; uint32_t * V, * XY; - size_t r = _r, p = _p; + size_t r = _r, p = _p; uint32_t i; /* Sanity-check parameters. */ -#if SIZE_MAX > UINT32_MAX + #if SIZE_MAX > UINT32_MAX if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { errno = EFBIG; return -1; } -#endif + #endif if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { errno = EFBIG; return -1; @@ -346,9 +346,9 @@ escrypt_kdf_sse(escrypt_local_t * local, return -1; } int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r); -#if SIZE_MAX / 256 <= UINT32_MAX + #if SIZE_MAX / 256 <= UINT32_MAX test = test || (r > SIZE_MAX / 256); -#endif + #endif if (test) { errno = ENOMEM; return -1; From e4c075fb928f890d48aef448345642b254a07a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Tue, 8 Mar 2016 15:17:20 -0300 Subject: [PATCH 6/9] Indenting #ifdefs (as requested by @GrayHatter) --- .../scrypt_platform.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c index 78acb1819e..f220de44f6 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c @@ -40,21 +40,21 @@ void * alloc_region(escrypt_region_t * region, size_t size) { uint8_t * base, * aligned; -#ifdef MAP_ANON + #ifdef MAP_ANON int flags; -#ifdef MAP_NOCORE + #ifdef MAP_NOCORE flags = MAP_ANON | MAP_PRIVATE | MAP_NOCORE; -#else + #else flags = MAP_ANON | MAP_PRIVATE; -#endif + #endif if ((base = (uint8_t *) mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0)) == MAP_FAILED) base = NULL; aligned = base; -#elif defined(HAVE_POSIX_MEMALIGN) + #elif defined(HAVE_POSIX_MEMALIGN) if ((errno = posix_memalign((void **) &base, 64, size)) != 0) base = NULL; aligned = base; -#else + #else base = aligned = NULL; if (size + 63 < size) errno = ENOMEM; @@ -62,7 +62,7 @@ alloc_region(escrypt_region_t * region, size_t size) aligned = base + 63; aligned -= (uintptr_t)aligned & 63; } -#endif + #endif region->base = base; region->aligned = aligned; region->size = base ? size : 0; @@ -80,12 +80,12 @@ int free_region(escrypt_region_t * region) { if (region->base) { -#ifdef MAP_ANON + #ifdef MAP_ANON if (munmap(region->base, region->size)) return -1; -#else + #else free(region->base); -#endif + #endif } init_region(region); return 0; From 10ad117e46d277e7a6ba9fbfd7e5c892035f7272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Thu, 12 Jan 2017 15:51:04 -0300 Subject: [PATCH 7/9] Update pwhash_scryptsalsa208sha256_nosse.c --- .../nosse/pwhash_scryptsalsa208sha256_nosse.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c index da2a103e3b..e66f528f64 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c @@ -239,12 +239,12 @@ escrypt_kdf_nosse(escrypt_local_t * local, uint32_t i; /* Sanity-check parameters. */ - #if SIZE_MAX > UINT32_MAX +#if SIZE_MAX > UINT32_MAX if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { errno = EFBIG; return -1; } - #endif +#endif if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { errno = EFBIG; return -1; @@ -257,11 +257,11 @@ escrypt_kdf_nosse(escrypt_local_t * local, errno = EINVAL; return -1; } - int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r); - #if SIZE_MAX / 256 <= UINT32_MAX - test = test || (r > SIZE_MAX / 256); - #endif - if (test) { + _Bool test_size_max = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r); +#if SIZE_MAX / 256 <= UINT32_MAX + test_size_max = test_size_max || (r > SIZE_MAX / 256); +#endif + if (test_size_max) { errno = ENOMEM; return -1; } From 2bc8074f680fec460eb31879118c8b6fc07b7457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Thu, 12 Jan 2017 15:54:09 -0300 Subject: [PATCH 8/9] Update scrypt_platform.c --- .../scrypt_platform.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c index f220de44f6..78acb1819e 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c @@ -40,21 +40,21 @@ void * alloc_region(escrypt_region_t * region, size_t size) { uint8_t * base, * aligned; - #ifdef MAP_ANON +#ifdef MAP_ANON int flags; - #ifdef MAP_NOCORE +#ifdef MAP_NOCORE flags = MAP_ANON | MAP_PRIVATE | MAP_NOCORE; - #else +#else flags = MAP_ANON | MAP_PRIVATE; - #endif +#endif if ((base = (uint8_t *) mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0)) == MAP_FAILED) base = NULL; aligned = base; - #elif defined(HAVE_POSIX_MEMALIGN) +#elif defined(HAVE_POSIX_MEMALIGN) if ((errno = posix_memalign((void **) &base, 64, size)) != 0) base = NULL; aligned = base; - #else +#else base = aligned = NULL; if (size + 63 < size) errno = ENOMEM; @@ -62,7 +62,7 @@ alloc_region(escrypt_region_t * region, size_t size) aligned = base + 63; aligned -= (uintptr_t)aligned & 63; } - #endif +#endif region->base = base; region->aligned = aligned; region->size = base ? size : 0; @@ -80,12 +80,12 @@ int free_region(escrypt_region_t * region) { if (region->base) { - #ifdef MAP_ANON +#ifdef MAP_ANON if (munmap(region->base, region->size)) return -1; - #else +#else free(region->base); - #endif +#endif } init_region(region); return 0; From b0942688f8cd5cb2a1c9b5ecda7f2fcbcd4eb7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Ribeiro?= Date: Thu, 12 Jan 2017 15:57:00 -0300 Subject: [PATCH 9/9] Update pwhash_scryptsalsa208sha256_sse.c --- .../sse/pwhash_scryptsalsa208sha256_sse.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c index d1d11b780b..75fdf5b85d 100644 --- a/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +++ b/toxencryptsave/crypto_pwhash_scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c @@ -323,12 +323,12 @@ escrypt_kdf_sse(escrypt_local_t * local, uint32_t i; /* Sanity-check parameters. */ - #if SIZE_MAX > UINT32_MAX +#if SIZE_MAX > UINT32_MAX if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { errno = EFBIG; return -1; } - #endif +#endif if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { errno = EFBIG; return -1; @@ -345,11 +345,11 @@ escrypt_kdf_sse(escrypt_local_t * local, errno = EINVAL; return -1; } - int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r); - #if SIZE_MAX / 256 <= UINT32_MAX - test = test || (r > SIZE_MAX / 256); - #endif - if (test) { + _Bool test_size_max = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r); +#if SIZE_MAX / 256 <= UINT32_MAX + test_size_max = test_size_max || (r > SIZE_MAX / 256); +#endif + if (test_size_max) { errno = ENOMEM; return -1; }