Commit 0ddd9f1a authored by Eric Biggers's avatar Eric Biggers Committed by James Morris

KEYS: DH: ensure the KDF counter is properly aligned

Accessing a 'u8[4]' through a '__be32 *' violates alignment rules.  Just
make the counter a __be32 instead.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarStephan Mueller <smueller@chronox.de>
Signed-off-by: default avatarJames Morris <james.l.morris@oracle.com>
parent 281590b4
...@@ -130,14 +130,6 @@ static void kdf_dealloc(struct kdf_sdesc *sdesc) ...@@ -130,14 +130,6 @@ static void kdf_dealloc(struct kdf_sdesc *sdesc)
kzfree(sdesc); kzfree(sdesc);
} }
/* convert 32 bit integer into its string representation */
static inline void crypto_kw_cpu_to_be32(u32 val, u8 *buf)
{
__be32 *a = (__be32 *)buf;
*a = cpu_to_be32(val);
}
/* /*
* Implementation of the KDF in counter mode according to SP800-108 section 5.1 * Implementation of the KDF in counter mode according to SP800-108 section 5.1
* as well as SP800-56A section 5.8.1 (Single-step KDF). * as well as SP800-56A section 5.8.1 (Single-step KDF).
...@@ -154,16 +146,14 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen, ...@@ -154,16 +146,14 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen,
unsigned int h = crypto_shash_digestsize(desc->tfm); unsigned int h = crypto_shash_digestsize(desc->tfm);
int err = 0; int err = 0;
u8 *dst_orig = dst; u8 *dst_orig = dst;
u32 i = 1; __be32 counter = cpu_to_be32(1);
u8 iteration[sizeof(u32)];
while (dlen) { while (dlen) {
err = crypto_shash_init(desc); err = crypto_shash_init(desc);
if (err) if (err)
goto err; goto err;
crypto_kw_cpu_to_be32(i, iteration); err = crypto_shash_update(desc, (u8 *)&counter, sizeof(__be32));
err = crypto_shash_update(desc, iteration, sizeof(u32));
if (err) if (err)
goto err; goto err;
...@@ -189,7 +179,7 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen, ...@@ -189,7 +179,7 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen,
dlen -= h; dlen -= h;
dst += h; dst += h;
i++; counter = cpu_to_be32(be32_to_cpu(counter) + 1);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment