From: Eric Biggers <ebiggers3@gmail.com>
To: keyrings@vger.kernel.org
Cc: linux-crypto@vger.kernel.org,
Stephan Mueller <smueller@chronox.de>,
David Howells <dhowells@redhat.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
mathew.j.martineau@linux.intel.com,
Eric Biggers <ebiggers@google.com>
Subject: [PATCH 4/5] KEYS: DH: ensure the KDF counter is properly aligned
Date: Wed, 19 Apr 2017 22:46:32 -0700 [thread overview]
Message-ID: <20170420054633.14572-5-ebiggers3@gmail.com> (raw)
In-Reply-To: <20170420054633.14572-1-ebiggers3@gmail.com>
From: Eric Biggers <ebiggers@google.com>
Accessing a 'u8[4]' through a '__be32 *' violates alignment rules. Just
make the counter a __be32 instead.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
security/keys/dh.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/security/keys/dh.c b/security/keys/dh.c
index a3a8607107f5..e6b757c33289 100644
--- a/security/keys/dh.c
+++ b/security/keys/dh.c
@@ -130,14 +130,6 @@ static void kdf_dealloc(struct kdf_sdesc *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
* 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,
unsigned int h = crypto_shash_digestsize(desc->tfm);
int err = 0;
u8 *dst_orig = dst;
- u32 i = 1;
- u8 iteration[sizeof(u32)];
+ __be32 counter = cpu_to_be32(1);
while (dlen) {
err = crypto_shash_init(desc);
if (err)
goto err;
- crypto_kw_cpu_to_be32(i, iteration);
- err = crypto_shash_update(desc, iteration, sizeof(u32));
+ err = crypto_shash_update(desc, (u8 *)&counter, sizeof(__be32));
if (err)
goto err;
@@ -189,7 +179,7 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen,
dlen -= h;
dst += h;
- i++;
+ counter = cpu_to_be32(be32_to_cpu(counter) + 1);
}
}
--
2.12.2
next prev parent reply other threads:[~2017-04-20 5:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-20 5:46 [PATCH 0/5] KEYS: fixes for new keyctl_dh_compute() KDF extension Eric Biggers
2017-04-20 5:46 ` [PATCH 1/5] KEYS: DH: forbid using digest_null as the KDF hash Eric Biggers
2017-04-20 5:46 ` [PATCH 2/5] KEYS: DH: don't feed uninitialized "otherinfo" into KDF Eric Biggers
2017-04-20 5:46 ` [PATCH 3/5] KEYS: DH: don't feed uninitialized result memory " Eric Biggers
2017-04-20 13:27 ` Stephan Müller
2017-04-20 17:46 ` Eric Biggers
2017-04-20 18:38 ` Stephan Müller
2017-04-21 3:44 ` Eric Biggers
2017-04-27 15:15 ` David Howells
2017-04-28 5:26 ` Eric Biggers
2017-04-20 5:46 ` Eric Biggers [this message]
2017-04-20 5:46 ` [PATCH 5/5] KEYS: DH: add __user annotations to keyctl_kdf_params Eric Biggers
2017-04-28 15:53 ` [PATCH 0/5] KEYS: fixes for new keyctl_dh_compute() KDF extension David Howells
2017-04-28 15:56 ` Stephan Müller
2017-05-01 14:52 ` Stephan Müller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170420054633.14572-5-ebiggers3@gmail.com \
--to=ebiggers3@gmail.com \
--cc=dhowells@redhat.com \
--cc=ebiggers@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=mathew.j.martineau@linux.intel.com \
--cc=smueller@chronox.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.