tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit 7adb60c1c700abb2e1b69943737a17bfbb63a30b
parent e95181096ff485a63f7714a1158467b8a3a8316e
Author: Nick Mathewson <nickm@torproject.org>
Date:   Thu, 22 May 2025 09:54:09 -0400

Fix a bug with less optimized polyval variants.

Using "0" to mean "doesn't support multi-block processing"
ran us into trouble: (n > 0 * 16) is always true for n > 0,
so we were always running a loop with no termination condition.

Additionally, the >s in this block should have been >=s,
since we want to process multi-blocks as long as there are any.
This won't have a performance impact for our current input sizes,
but it's nice to be correct.

Diffstat:
Msrc/ext/polyval/polyval.c | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/ext/polyval/polyval.c b/src/ext/polyval/polyval.c @@ -235,6 +235,11 @@ static inline void expand_key_none(const polyval_t *inp, (void) out; } +/* Kludge: a special value to use for block_stride when we don't support + * processing multiple blocks at once. Previously we used 0, but that + * caused warnings with some comparisons. */ +#define BLOCK_STRIDE_NONE 0xffff + #define PV_DECLARE(prefix, \ st, \ u128_from_bytes, \ @@ -270,10 +275,12 @@ static inline void expand_key_none(const polyval_t *inp, st void \ prefix ## polyval_add_zpad(polyval_t *pv, const uint8_t *data, size_t n) \ { \ - if (n > block_stride * 16) { \ + /* since block_stride is a constant, this should get optimized */ \ + if ((block_stride != BLOCK_STRIDE_NONE) \ + && n >= (block_stride) * 16) { \ expanded_key_tp expanded_key; \ expand_fn(pv, &expanded_key); \ - while (n > block_stride * 16) { \ + while (n >= (block_stride) * 16) { \ add_multiple_fn(pv, data, &expanded_key); \ n -= block_stride*16; \ data += block_stride * 16; \ @@ -326,7 +333,7 @@ PV_DECLARE(ctmul64_, static, u128_to_bytes_ctmul64, pv_xor_y_ctmul64, pv_mul_y_h_ctmul64, - 0, + BLOCK_STRIDE_NONE, struct expanded_key_none, expand_key_none, add_multiple_none) @@ -404,7 +411,7 @@ PV_DECLARE(, , u128_to_bytes_ctmul64, pv_xor_y_ctmul64, pv_mul_y_h_ctmul64, - 0, + BLOCK_STRIDE_NONE, struct expanded_key_none, expand_key_none, add_multiple_none) @@ -414,7 +421,7 @@ PV_DECLARE(, , u128_from_bytes_ctmul, u128_to_bytes_ctmul, pv_xor_y_ctmul, pv_mul_y_h_ctmul, - 0, + BLOCK_STRIDE_NONE, struct expanded_key_none, expand_key_none, add_multiple_none)