Skip to content

Commit

Permalink
Fill the destination buffer with all set bits on error for fail-safety
Browse files Browse the repository at this point in the history
of the caller's "< target" check in case the caller neglects to check
for errors.

CVS-ID: CHANGES 1.2
CVS-ID: yespower-opt.c 1.4
CVS-ID: yespower-ref.c 1.2
  • Loading branch information
solardiz committed Jun 30, 2019
1 parent 74dfcc0 commit d81b48a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changes made between 1.0.0 (2018/07/12) and 1.0.1 (2019/06/30).

Fill the destination buffer with all set bits on error for fail-safety
of the caller's "< target" check in case the caller neglects to check
for errors.

Simplified SMix2 for its final invocation with Nloop=2 in yespower 0.5.

Revised the "XOR of yespower" tests to trigger duplicate index in the
Expand Down
15 changes: 9 additions & 6 deletions yespower-opt.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* Copyright 2009 Colin Percival
* Copyright 2012-2018 Alexander Peslyak
* Copyright 2012-2019 Alexander Peslyak
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -1049,7 +1049,7 @@ int yespower(yespower_local_t *local,
(N & (N - 1)) != 0 ||
(!pers && perslen)) {
errno = EINVAL;
return -1;
goto fail;
}

/* Allocate memory */
Expand All @@ -1067,9 +1067,9 @@ int yespower(yespower_local_t *local,
need = B_size + V_size + XY_size + ctx.Sbytes;
if (local->aligned_size < need) {
if (free_region(local))
return -1;
goto fail;
if (!alloc_region(local, need))
return -1;
goto fail;
}
B = (uint8_t *)local->aligned;
V = (salsa20_blk_t *)((uint8_t *)B + B_size);
Expand Down Expand Up @@ -1113,6 +1113,10 @@ int yespower(yespower_local_t *local,

/* Success! */
return 0;

fail:
memset(dst, 0xff, sizeof(*dst));
return -1;
}

/**
Expand All @@ -1129,8 +1133,7 @@ int yespower_tls(const uint8_t *src, size_t srclen,
static __thread yespower_local_t local;

if (!initialized) {
if (yespower_init_local(&local))
return -1;
init_region(&local);
initialized = 1;
}

Expand Down
4 changes: 3 additions & 1 deletion yespower-ref.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-
* Copyright 2009 Colin Percival
* Copyright 2013-2018 Alexander Peslyak
* Copyright 2013-2019 Alexander Peslyak
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -468,6 +468,8 @@ int yespower(yespower_local_t *local,
pwxform_ctx_t ctx;
uint32_t sha256[8];

memset(dst, 0xff, sizeof(*dst));

/* Sanity-check parameters */
if ((version != YESPOWER_0_5 && version != YESPOWER_1_0) ||
N < 1024 || N > 512 * 1024 || r < 8 || r > 32 ||
Expand Down

0 comments on commit d81b48a

Please sign in to comment.