Commit d7921344 authored by Stephan Müller's avatar Stephan Müller Committed by Herbert Xu

security: DH - remove dead code for zero padding

Remove the specific code that adds a zero padding that was intended
to be invoked when the DH operation result was smaller than the
modulus. However, this cannot occur any more these days because the
function mpi_write_to_sgl is used in the code path that calculates the
shared secret in dh_compute_value. This MPI service function guarantees
that leading zeros are introduced as needed to ensure the resulting data
is exactly as long as the modulus. This implies that the specific code
to add zero padding is dead code which can be safely removed.
Signed-off-by: default avatarStephan Mueller <smueller@chronox.de>
Acked-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 026a733e
...@@ -141,7 +141,7 @@ static void kdf_dealloc(struct kdf_sdesc *sdesc) ...@@ -141,7 +141,7 @@ static void kdf_dealloc(struct kdf_sdesc *sdesc)
* 'dlen' must be a multiple of the digest size. * 'dlen' must be a multiple of the digest size.
*/ */
static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen, static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen,
u8 *dst, unsigned int dlen, unsigned int zlen) u8 *dst, unsigned int dlen)
{ {
struct shash_desc *desc = &sdesc->shash; struct shash_desc *desc = &sdesc->shash;
unsigned int h = crypto_shash_digestsize(desc->tfm); unsigned int h = crypto_shash_digestsize(desc->tfm);
...@@ -158,22 +158,6 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen, ...@@ -158,22 +158,6 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen,
if (err) if (err)
goto err; goto err;
if (zlen && h) {
u8 tmpbuffer[32];
size_t chunk = min_t(size_t, zlen, sizeof(tmpbuffer));
memset(tmpbuffer, 0, chunk);
do {
err = crypto_shash_update(desc, tmpbuffer,
chunk);
if (err)
goto err;
zlen -= chunk;
chunk = min_t(size_t, zlen, sizeof(tmpbuffer));
} while (zlen);
}
if (src && slen) { if (src && slen) {
err = crypto_shash_update(desc, src, slen); err = crypto_shash_update(desc, src, slen);
if (err) if (err)
...@@ -198,7 +182,7 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen, ...@@ -198,7 +182,7 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen,
static int keyctl_dh_compute_kdf(struct kdf_sdesc *sdesc, static int keyctl_dh_compute_kdf(struct kdf_sdesc *sdesc,
char __user *buffer, size_t buflen, char __user *buffer, size_t buflen,
uint8_t *kbuf, size_t kbuflen, size_t lzero) uint8_t *kbuf, size_t kbuflen)
{ {
uint8_t *outbuf = NULL; uint8_t *outbuf = NULL;
int ret; int ret;
...@@ -211,7 +195,7 @@ static int keyctl_dh_compute_kdf(struct kdf_sdesc *sdesc, ...@@ -211,7 +195,7 @@ static int keyctl_dh_compute_kdf(struct kdf_sdesc *sdesc,
goto err; goto err;
} }
ret = kdf_ctr(sdesc, kbuf, kbuflen, outbuf, outbuf_len, lzero); ret = kdf_ctr(sdesc, kbuf, kbuflen, outbuf, outbuf_len);
if (ret) if (ret)
goto err; goto err;
...@@ -384,8 +368,7 @@ long __keyctl_dh_compute(struct keyctl_dh_params __user *params, ...@@ -384,8 +368,7 @@ long __keyctl_dh_compute(struct keyctl_dh_params __user *params,
} }
ret = keyctl_dh_compute_kdf(sdesc, buffer, buflen, outbuf, ret = keyctl_dh_compute_kdf(sdesc, buffer, buflen, outbuf,
req->dst_len + kdfcopy->otherinfolen, req->dst_len + kdfcopy->otherinfolen);
outlen - req->dst_len);
} else if (copy_to_user(buffer, outbuf, req->dst_len) == 0) { } else if (copy_to_user(buffer, outbuf, req->dst_len) == 0) {
ret = req->dst_len; ret = req->dst_len;
} else { } else {
......
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