From: Jouni Malinen Date: Thu, 26 May 2022 20:40:09 +0000 (+0300) Subject: FIPS PRF: Avoid duplicate SHA1Init() functionality X-Git-Tag: hostap_2_11~1871 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd92f7f98a32607fe9a73b417582e04121594b38;p=thirdparty%2Fhostap.git FIPS PRF: Avoid duplicate SHA1Init() functionality The initialization values used for the FIPS 186-2 PRF are identical to the ones used in SHA1Init(), so use that internal function instead of maintaining a duplicate set of values here. fips186_2_prf() was already using an internal SHA1Transform() function so using another internal function does not make this any worse. Signed-off-by: Jouni Malinen --- diff --git a/src/crypto/fips_prf_internal.c b/src/crypto/fips_prf_internal.c index a4bf50a47..f9347d0df 100644 --- a/src/crypto/fips_prf_internal.c +++ b/src/crypto/fips_prf_internal.c @@ -17,10 +17,11 @@ int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen) { u8 xkey[64]; - u32 t[5], _t[5]; + u32 _t[5]; int i, j, m, k; u8 *xpos = x; u32 carry; + struct SHA1Context ctx; if (seed_len < sizeof(xkey)) os_memset(xkey + seed_len, 0, sizeof(xkey) - seed_len); @@ -30,11 +31,7 @@ int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen) /* FIPS 186-2 + change notice 1 */ os_memcpy(xkey, seed, seed_len); - t[0] = 0x67452301; - t[1] = 0xEFCDAB89; - t[2] = 0x98BADCFE; - t[3] = 0x10325476; - t[4] = 0xC3D2E1F0; + SHA1Init(&ctx); m = xlen / 40; for (j = 0; j < m; j++) { @@ -43,7 +40,7 @@ int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen) /* XVAL = (XKEY + XSEED_j) mod 2^b */ /* w_i = G(t, XVAL) */ - os_memcpy(_t, t, 20); + os_memcpy(_t, ctx.state, 20); SHA1Transform(_t, xkey); _t[0] = host_to_be32(_t[0]); _t[1] = host_to_be32(_t[1]);