Commit 546ce0bd authored by Stefan Berger's avatar Stefan Berger Committed by Herbert Xu

crypto: ecdsa - Use ecc_digits_from_bytes to convert signature

Since ecc_digits_from_bytes will provide zeros when an insufficient number
of bytes are passed in the input byte array, use it to convert the r and s
components of the signature to digits directly from the input byte
array. This avoids going through an intermediate byte array that has the
first few bytes filled with zeros.
Signed-off-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 2fd2a82c
...@@ -38,7 +38,6 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag, ...@@ -38,7 +38,6 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag,
size_t bufsize = ndigits * sizeof(u64); size_t bufsize = ndigits * sizeof(u64);
ssize_t diff = vlen - bufsize; ssize_t diff = vlen - bufsize;
const char *d = value; const char *d = value;
u8 rs[ECC_MAX_BYTES];
if (!value || !vlen) if (!value || !vlen)
return -EINVAL; return -EINVAL;
...@@ -46,7 +45,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag, ...@@ -46,7 +45,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag,
/* diff = 0: 'value' has exacly the right size /* diff = 0: 'value' has exacly the right size
* diff > 0: 'value' has too many bytes; one leading zero is allowed that * diff > 0: 'value' has too many bytes; one leading zero is allowed that
* makes the value a positive integer; error on more * makes the value a positive integer; error on more
* diff < 0: 'value' is missing leading zeros, which we add * diff < 0: 'value' is missing leading zeros
*/ */
if (diff > 0) { if (diff > 0) {
/* skip over leading zeros that make 'value' a positive int */ /* skip over leading zeros that make 'value' a positive int */
...@@ -61,14 +60,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag, ...@@ -61,14 +60,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag,
if (-diff >= bufsize) if (-diff >= bufsize)
return -EINVAL; return -EINVAL;
if (diff) { ecc_digits_from_bytes(d, vlen, dest, ndigits);
/* leading zeros not given in 'value' */
memset(rs, 0, -diff);
}
memcpy(&rs[-diff], d, vlen);
ecc_swap_digits((u64 *)rs, dest, ndigits);
return 0; return 0;
} }
......
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