psa_util: some code improvement to convert_der_to_raw_single_int()
This commit also fixes test_suite_psa_crypto_util.data due to the change in one of the return values. Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
f8ce457fb6
commit
9b9b5a52d9
2 changed files with 8 additions and 4 deletions
|
@ -494,7 +494,7 @@ static int convert_der_to_raw_single_int(unsigned char *der, size_t der_len,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip possible leading zero */
|
/* Skip possible leading zero */
|
||||||
if (*p == 0x00) {
|
if ((*p == 0x00) && (unpadded_len > 0)) {
|
||||||
p++;
|
p++;
|
||||||
unpadded_len--;
|
unpadded_len--;
|
||||||
/* It should never happen that the input number is all zeros. */
|
/* It should never happen that the input number is all zeros. */
|
||||||
|
@ -503,9 +503,13 @@ static int convert_der_to_raw_single_int(unsigned char *der, size_t der_len,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unpadded_len < coordinate_size) {
|
if (unpadded_len > coordinate_size) {
|
||||||
|
/* Parsed number is longer than the maximum expected value. */
|
||||||
|
return MBEDTLS_ERR_ASN1_INVALID_DATA;
|
||||||
|
} else {
|
||||||
padding_len = coordinate_size - unpadded_len;
|
padding_len = coordinate_size - unpadded_len;
|
||||||
memset(raw, 0x00, padding_len);
|
/* raw buffer was already zeroed in mbedtls_ecdsa_der_to_raw() so
|
||||||
|
* zero-padding operation is skipped here. */
|
||||||
}
|
}
|
||||||
memcpy(raw + padding_len, p, unpadded_len);
|
memcpy(raw + padding_len, p, unpadded_len);
|
||||||
p += unpadded_len;
|
p += unpadded_len;
|
||||||
|
|
|
@ -52,7 +52,7 @@ ecdsa_der_to_raw:256:"3044021911111111111111111111111111111111111111111111111111
|
||||||
|
|
||||||
ECDSA DER -> Raw, 256bit, Wrong r integer length (too large)
|
ECDSA DER -> Raw, 256bit, Wrong r integer length (too large)
|
||||||
depends_on:PSA_WANT_ECC_SECP_K1_256
|
depends_on:PSA_WANT_ECC_SECP_K1_256
|
||||||
ecdsa_der_to_raw:256:"30440221111111111111111111111111111111111111111111111111111111111111111102202222222222222222222222222222222222222222222222222222222222222222":"11111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222":MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
|
ecdsa_der_to_raw:256:"30440221111111111111111111111111111111111111111111111111111111111111111102202222222222222222222222222222222222222222222222222222222222222222":"11111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222":MBEDTLS_ERR_ASN1_INVALID_DATA
|
||||||
|
|
||||||
ECDSA DER -> Raw, 256bit, Wrong s integer length (too small)
|
ECDSA DER -> Raw, 256bit, Wrong s integer length (too small)
|
||||||
depends_on:PSA_WANT_ECC_SECP_K1_256
|
depends_on:PSA_WANT_ECC_SECP_K1_256
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue