test_suite_psa_crypto_util: add test function and data for ECDSA conversion functions
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
bd5b9c61fe
commit
aed21640bd
2 changed files with 115 additions and 0 deletions
71
tests/suites/test_suite_psa_crypto_util.data
Normal file
71
tests/suites/test_suite_psa_crypto_util.data
Normal file
|
@ -0,0 +1,71 @@
|
|||
ECDSA Raw -> DER, 192bit, Success
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_RAW_TO_DER:192:"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":"303402180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":0
|
||||
|
||||
ECDSA Raw -> DER, 192bit, Raw data too short
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_RAW_TO_DER:192:"0101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202":"303402180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_INVALID_DATA
|
||||
|
||||
ECDSA Raw -> DER, 192bit, DER buffer too small
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_RAW_TO_DER:192:"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":"30340218010101010101010101010101010101010101010101010101":MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ECDSA Raw -> DER, 192bit, Null r
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_RAW_TO_DER:192:"000000000000000000000000000000000000000000000000020202020202020202020202020202020202020202020202":"303402180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_INVALID_DATA
|
||||
|
||||
ECDSA Raw -> DER, 192bit, Null s
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_RAW_TO_DER:192:"010101010101010101010101010101010101010101010101000000000000000000000000000000000000000000000000":"303402180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_INVALID_DATA
|
||||
|
||||
ECDSA Raw -> DER, 192bit, r with MSb set
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_RAW_TO_DER:192:"810101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":"30350219008101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":0
|
||||
|
||||
ECDSA Raw -> DER, 192bit, s with MSb set
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_RAW_TO_DER:192:"010101010101010101010101010101010101010101010101820202020202020202020202020202020202020202020202":"30350218010101010101010101010101010101010101010101010101021900820202020202020202020202020202020202020202020202":0
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Success
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"303402180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":0
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Raw buffer too small
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"303402180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":"0101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Wrong sequence tag
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"403402180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Invalid sequence length
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"30FF02180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_INVALID_LENGTH
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Wrong integer tag
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"303401180101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Wrong r integer length (too small)
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"303402170101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Wrong r integer length (too large)
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"303402190101010101010101010101010101010101010101010101010218020202020202020202020202020202020202020202020202":"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Wrong s integer length (too small)
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"303402180101010101010101010101010101010101010101010101010217020202020202020202020202020202020202020202020202":"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_LENGTH_MISMATCH
|
||||
|
||||
ECDSA DER -> Raw, 192bit, Wrong s integer length (too large)
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_192
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:192:"303402180101010101010101010101010101010101010101010101010219020202020202020202020202020202020202020202020202":"010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202":MBEDTLS_ERR_ASN1_OUT_OF_DATA
|
||||
|
||||
ECDSA Raw -> DER, 256bit, Success
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_256
|
||||
ecdsa_raw_to_der:ECDSA_RAW_TO_DER:256:"01010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202":"30440220010101010101010101010101010101010101010101010101010101010101010102200202020202020202020202020202020202020202020202020202020202020202":0
|
||||
|
||||
ECDSA DER -> Raw, 256bit, Success
|
||||
depends_on:PSA_WANT_ECC_SECP_R1_256
|
||||
ecdsa_raw_to_der:ECDSA_DER_TO_RAW:256:"30440220010101010101010101010101010101010101010101010101010101010101010102200202020202020202020202020202020202020202020202020202020202020202":"01010101010101010101010101010101010101010101010101010101010101010202020202020202020202020202020202020202020202020202020202020202":0
|
44
tests/suites/test_suite_psa_crypto_util.function
Normal file
44
tests/suites/test_suite_psa_crypto_util.function
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* BEGIN_HEADER */
|
||||
#include <stdint.h>
|
||||
#include <test/helpers.h>
|
||||
#include <mbedtls/psa_util.h>
|
||||
#include <mbedtls/asn1write.h>
|
||||
|
||||
enum {
|
||||
ECDSA_RAW_TO_DER = 0,
|
||||
ECDSA_DER_TO_RAW,
|
||||
};
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES
|
||||
* depends_on:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_ASN1_WRITE_C:MBEDTLS_ASN1_PARSE_C
|
||||
* END_DEPENDENCIES
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecdsa_raw_to_der(int direction, int key_bits, data_t *input, data_t *exp_result, int exp_ret)
|
||||
{
|
||||
unsigned char *tmp_buf = NULL;
|
||||
size_t tmp_buf_len = exp_result->len;
|
||||
size_t ret_len;
|
||||
|
||||
TEST_CALLOC(tmp_buf, tmp_buf_len);
|
||||
|
||||
if (direction == ECDSA_RAW_TO_DER) {
|
||||
TEST_EQUAL(mbedtls_ecdsa_raw_to_der(input->x, input->len,
|
||||
tmp_buf, tmp_buf_len, &ret_len,
|
||||
key_bits), exp_ret);
|
||||
} else {
|
||||
TEST_EQUAL(mbedtls_ecdsa_der_to_raw(input->x, input->len,
|
||||
tmp_buf, tmp_buf_len, &ret_len,
|
||||
key_bits), exp_ret);
|
||||
}
|
||||
|
||||
if (exp_ret == 0) {
|
||||
ASSERT_COMPARE(exp_result->x, exp_result->len, tmp_buf, ret_len);
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_free(tmp_buf);
|
||||
}
|
||||
/* END_CASE */
|
Loading…
Reference in a new issue