1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00

psa_util: remove raw_len param from convert_der_to_raw_single_int()

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti
2024-01-29 18:02:03 +01:00
parent ee5238fcf4
commit 122c94fd26

View File

@ -460,7 +460,6 @@ int mbedtls_ecdsa_raw_to_der(const unsigned char *raw, size_t raw_len,
* \param raw Output buffer that will be filled with the * \param raw Output buffer that will be filled with the
* converted data. This should be at least * converted data. This should be at least
* coordinate_size bytes. * coordinate_size bytes.
* \param raw_len Size (in bytes) of the output raw buffer.
* \param coordinate_size Size (in bytes) of a single coordinate in raw * \param coordinate_size Size (in bytes) of a single coordinate in raw
* format. * format.
* *
@ -475,17 +474,12 @@ int mbedtls_ecdsa_raw_to_der(const unsigned char *raw, size_t raw_len,
* \warning Der and raw buffers must not be overlapping. * \warning Der and raw buffers must not be overlapping.
*/ */
static int convert_der_to_raw_single_int(unsigned char *der, size_t der_len, static int convert_der_to_raw_single_int(unsigned char *der, size_t der_len,
unsigned char *raw, size_t raw_len, unsigned char *raw, size_t coordinate_size)
size_t coordinate_size)
{ {
unsigned char *p = der; unsigned char *p = der;
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
size_t unpadded_len, padding_len = 0; size_t unpadded_len, padding_len = 0;
if (raw_len < coordinate_size) {
return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
}
/* Get the length of ASN.1 element (i.e. the integer we need to parse). */ /* Get the length of ASN.1 element (i.e. the integer we need to parse). */
ret = mbedtls_asn1_get_tag(&p, p + der_len, &unpadded_len, ret = mbedtls_asn1_get_tag(&p, p + der_len, &unpadded_len,
MBEDTLS_ASN1_INTEGER); MBEDTLS_ASN1_INTEGER);
@ -543,8 +537,7 @@ int mbedtls_ecdsa_der_to_raw(const unsigned char *der, size_t der_len,
memset(raw_tmp, 0, sizeof(raw_tmp)); memset(raw_tmp, 0, sizeof(raw_tmp));
/* Extract r */ /* Extract r */
ret = convert_der_to_raw_single_int(p, data_len, raw_tmp, sizeof(raw_tmp), ret = convert_der_to_raw_single_int(p, data_len, raw_tmp, coordinate_size);
coordinate_size);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
@ -553,7 +546,6 @@ int mbedtls_ecdsa_der_to_raw(const unsigned char *der, size_t der_len,
/* Extract s */ /* Extract s */
ret = convert_der_to_raw_single_int(p, data_len, raw_tmp + coordinate_size, ret = convert_der_to_raw_single_int(p, data_len, raw_tmp + coordinate_size,
sizeof(raw_tmp) - coordinate_size,
coordinate_size); coordinate_size);
if (ret < 0) { if (ret < 0) {
return ret; return ret;