Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marciomribeiro please undo this formatting change.

if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
errno = EFBIG;
return -1;
}
#endif
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And undo this.

if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
errno = EFBIG;
return -1;
Expand All @@ -257,11 +257,11 @@ escrypt_kdf_nosse(escrypt_local_t * local,
errno = EINVAL;
return -1;
}
if ((r > SIZE_MAX / 128 / p) ||
#if SIZE_MAX / 256 <= UINT32_MAX
(r > SIZE_MAX / 256) ||
#endif
(N > SIZE_MAX / 128 / r)) {
int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use _Bool. Also rename to something more useful. test doesn't say anything. What is it testing?

#if SIZE_MAX / 256 <= UINT32_MAX
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to column 0.

test = test || (r > SIZE_MAX / 256);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to column 0.

if (test) {
errno = ENOMEM;
return -1;
}
Expand Down
28 changes: 14 additions & 14 deletions toxencryptsave/crypto_pwhash_scryptsalsa208sha256/scrypt_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,29 @@ void *
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,
#ifdef MAP_NOCORE
MAP_ANON | MAP_PRIVATE | MAP_NOCORE,
#else
MAP_ANON | MAP_PRIVATE,
#endif
-1, 0)) == MAP_FAILED)
#ifdef MAP_ANON
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move all of these back to column 0.

int flags;
#ifdef MAP_NOCORE
flags = MAP_ANON | MAP_PRIVATE | MAP_NOCORE;
#else
flags = MAP_ANON | MAP_PRIVATE;
#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;
else if ((base = (uint8_t *) malloc(size + 63)) != NULL) {
aligned = base + 63;
aligned -= (uintptr_t)aligned & 63;
}
#endif
#endif
region->base = base;
region->aligned = aligned;
region->size = base ? size : 0;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing in this file: revert the style change.

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;
Expand All @@ -345,11 +345,11 @@ escrypt_kdf_sse(escrypt_local_t * local,
errno = EINVAL;
return -1;
}
if ((r > SIZE_MAX / 128 / p) ||
#if SIZE_MAX / 256 <= UINT32_MAX
(r > SIZE_MAX / 256) ||
#endif
(N > SIZE_MAX / 128 / r)) {
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) {
errno = ENOMEM;
return -1;
}
Expand Down