diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-07 14:32:58 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-07 14:32:58 +0200 |
commit | 811a82296969a037d1e580d65bb5a73241ffae1f (patch) | |
tree | 404759c5e429d450c91f110497758424fb4eaf1d /process.c | |
parent | Don't marshal w (diff) | |
download | libsha1-811a82296969a037d1e580d65bb5a73241ffae1f.tar.gz libsha1-811a82296969a037d1e580d65bb5a73241ffae1f.tar.bz2 libsha1-811a82296969a037d1e580d65bb5a73241ffae1f.tar.xz |
Use uint_least32_t instead of uint32_t
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 44 |
1 files changed, 23 insertions, 21 deletions
@@ -2,33 +2,34 @@ #include "common.h" -static inline uint32_t -rorl(uint32_t n, int k) +static inline uint_least32_t +rorl(uint_least32_t n, int k) { - return (n << k) | (n >> (32 - k)); + return TRUNC32((n << k) | (n >> (32 - k))); } void libsha1_process(struct libsha1_state *restrict state, const unsigned char *restrict chunk) { -#define F0(b, c, d) (d ^ (b & (c ^ d))) -#define F1(b, c, d) (b ^ c ^ d) -#define F2(b, c, d) ((b & c) | (d & (b | c))) -#define F3(b, c, d) (b ^ c ^ d) -#define G0(a, b, c, d, e, i) (e += rorl(a, 5) + F0(b, c, d) + state->w[i] + (uint32_t)0x5A827999UL, b = rorl(b, 30)) -#define G1(a, b, c, d, e, i) (e += rorl(a, 5) + F1(b, c, d) + state->w[i] + (uint32_t)0x6ED9EBA1UL, b = rorl(b, 30)) -#define G2(a, b, c, d, e, i) (e += rorl(a, 5) + F2(b, c, d) + state->w[i] + (uint32_t)0x8F1BBCDCUL, b = rorl(b, 30)) -#define G3(a, b, c, d, e, i) (e += rorl(a, 5) + F3(b, c, d) + state->w[i] + (uint32_t)0xCA62C1D6UL, b = rorl(b, 30)) +#define F0(B, C, D) (D ^ (B & (C ^ D))) +#define F1(B, C, D) (B ^ C ^ D) +#define F2(B, C, D) ((B & C) | (D & (B | C))) +#define F3(B, C, D) (B ^ C ^ D) +#define G_(A, B, C, D, E, I, F, X) (E = TRUNC32(E + rorl(A, 5) + F(B, C, D) + state->w[I] + (uint_least32_t)X##UL), B = rorl(B, 30)) +#define G0(A, B, C, D, E, I) G_(A, B, C, D, E, I, F0, 0x5A827999) +#define G1(A, B, C, D, E, I) G_(A, B, C, D, E, I, F1, 0x6ED9EBA1) +#define G2(A, B, C, D, E, I) G_(A, B, C, D, E, I, F2, 0x8F1BBCDC) +#define G3(A, B, C, D, E, I) G_(A, B, C, D, E, I, F3, 0xCA62C1D6) - uint32_t a, b, c, d, e; + uint_least32_t a, b, c, d, e; int i; for (i = 0; i < 16; i++) { - state->w[i] = (uint32_t)chunk[4 * i + 0] << 24; - state->w[i] |= (uint32_t)chunk[4 * i + 1] << 16; - state->w[i] |= (uint32_t)chunk[4 * i + 2] << 8; - state->w[i] |= (uint32_t)chunk[4 * i + 3]; + state->w[i] = (uint_least32_t)chunk[4 * i + 0] << 24; + state->w[i] |= (uint_least32_t)chunk[4 * i + 1] << 16; + state->w[i] |= (uint_least32_t)chunk[4 * i + 2] << 8; + state->w[i] |= (uint_least32_t)chunk[4 * i + 3]; } if (state->algorithm == LIBSHA1_1) { for (; i < 80; i++) @@ -70,16 +71,17 @@ libsha1_process(struct libsha1_state *restrict state, const unsigned char *restr G3(c, d, e, a, b, i++); G3(b, c, d, e, a, i++); } - state->h[0] += a; - state->h[1] += b; - state->h[2] += c; - state->h[3] += d; - state->h[4] += e; + state->h[0] = TRUNC32(state->h[0] + a); + state->h[1] = TRUNC32(state->h[1] + b); + state->h[2] = TRUNC32(state->h[2] + c); + state->h[3] = TRUNC32(state->h[3] + d); + state->h[4] = TRUNC32(state->h[4] + e); #undef F0 #undef F1 #undef F2 #undef F3 +#undef G_ #undef G0 #undef G1 #undef G2 |