Fixed size check in ecc_get_key, Fixes #630

This commit is contained in:
Ulrich Koschella 2023-08-04 14:57:49 +02:00 committed by Jamie Reece Wilson
parent 71c93ed301
commit 03b3538830

View File

@ -33,8 +33,11 @@ int ecc_get_key(unsigned char *out, unsigned long *outlen, int type, const ecc_k
} }
else if (type == PK_PRIVATE) { else if (type == PK_PRIVATE) {
if (key->type != PK_PRIVATE) return CRYPT_PK_TYPE_MISMATCH; if (key->type != PK_PRIVATE) return CRYPT_PK_TYPE_MISMATCH;
if (size > *outlen) {
*outlen = size;
return CRYPT_BUFFER_OVERFLOW;
}
*outlen = size; *outlen = size;
if (size > *outlen) return CRYPT_BUFFER_OVERFLOW;
if ((ksize = mp_unsigned_bin_size(key->k)) > size) return CRYPT_BUFFER_OVERFLOW; if ((ksize = mp_unsigned_bin_size(key->k)) > size) return CRYPT_BUFFER_OVERFLOW;
/* pad and store k */ /* pad and store k */
if ((err = mp_to_unsigned_bin(key->k, out + (size - ksize))) != CRYPT_OK) return err; if ((err = mp_to_unsigned_bin(key->k, out + (size - ksize))) != CRYPT_OK) return err;