]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
FIPS PRF: Avoid duplicate SHA1Init() functionality
authorJouni Malinen <j@w1.fi>
Thu, 26 May 2022 20:40:09 +0000 (23:40 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 26 May 2022 21:32:12 +0000 (00:32 +0300)
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 <j@w1.fi>
src/crypto/fips_prf_internal.c

index a4bf50a47f44575854c43b10c73814e2ccbb7782..f9347d0df55e8eba9049f2e60518fe3ce5e67e5e 100644 (file)
 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]);