From 1d26f80ccf648495f56e64d5e7efd6e4b6aed3af Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 26 Feb 2024 11:46:03 -0800 Subject: [PATCH] more nhmd4.c formatting Insert a space between cast operator and target. For 'x | y' expression spanning multiple lines, split with bitwise OR operator at the beginning of second line instead at the end of first. I changed a macro that was expanding to 'expr_1; expr_2' into '(expr_1, expr_2)'. Both expressions modify arg 'a' which would be a no-no within a single expression, but the comma operator provides a sequence point that guarantees that the first expression will be fully evaluated with side-effects--assignment to 'a'--completed before the second one starts, making both assignments be well defined. --- src/nhmd4.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/nhmd4.c b/src/nhmd4.c index 48e260115..ae3a88f8b 100644 --- a/src/nhmd4.c +++ b/src/nhmd4.c @@ -40,11 +40,14 @@ static const unsigned char *body(struct nhmd4_context *, #define H(x, y, z) ((x) ^ (y) ^ (z)) /* - * The MD4 transformation for all four rounds. + * STEP: the MD4 transformation used for all four rounds. + * (Joining two expressions with the comma operator provides a sequence + * point. C89/C90 and later guarantee that the first will be fully complete + * before the second starts, making both assignments to 'a' be well defined.) */ #define STEP(f, a, b, c, d, x, s) \ - (a) += f((b), (c), (d)) + (x); \ - (a) = ((a) << (s)) | ((a) >> (32 - (s))) + (((a) += f((b), (c), (d)) + (x)), \ + ((a) = ((a) << (s)) | ((a) >> (32 - (s))))) /* * SET reads 4 input bytes in little-endian byte order and stores them @@ -55,17 +58,16 @@ static const unsigned char *body(struct nhmd4_context *, * doesn't work. */ #if defined(__i386__) || defined(__x86_64__) -#define SET(n) (*(const quint32 *)&ptr[(n) * 4]) +#define SET(n) (*(const quint32 *) &ptr[(n) * 4]) #define GET(n) SET(n) #else #define SET(n) \ (ctx->block[(n)] = \ - (quint32)ptr[(n) * 4] | \ - ((quint32)ptr[(n) * 4 + 1] << 8) | \ - ((quint32)ptr[(n) * 4 + 2] << 16) | \ - ((quint32)ptr[(n) * 4 + 3] << 24)) -#define GET(n) \ - (ctx->block[(n)]) + ((quint32) ptr[(n) * 4] \ + | ((quint32) ptr[(n) * 4 + 1] << 8) \ + | ((quint32) ptr[(n) * 4 + 2] << 16) \ + | ((quint32) ptr[(n) * 4 + 3] << 24))) +#define GET(n) (ctx->block[(n)]) #endif /*