diff --git a/src/pk/ecc/ecc_get_key.c b/src/pk/ecc/ecc_get_key.c index d30fd0682..891a74136 100644 --- a/src/pk/ecc/ecc_get_key.c +++ b/src/pk/ecc/ecc_get_key.c @@ -33,8 +33,11 @@ int ecc_get_key(unsigned char *out, unsigned long *outlen, int type, const ecc_k } else if (type == PK_PRIVATE) { if (key->type != PK_PRIVATE) return CRYPT_PK_TYPE_MISMATCH; + if (size > *outlen) { + *outlen = size; + return CRYPT_BUFFER_OVERFLOW; + } *outlen = size; - if (size > *outlen) return CRYPT_BUFFER_OVERFLOW; if ((ksize = mp_unsigned_bin_size(key->k)) > size) return CRYPT_BUFFER_OVERFLOW; /* pad and store k */ if ((err = mp_to_unsigned_bin(key->k, out + (size - ksize))) != CRYPT_OK) return err;