From 5ed7fff8cef42203c6a4807220e34da61be4182d Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Mon, 6 May 2019 12:15:44 -0400 Subject: [PATCH] Add a test of the OID->MD map functions --- ChangeLog | 4 ++-- tests/suites/test_suite_oid.data | 32 ++++++++++++++++++++++++++++ tests/suites/test_suite_oid.function | 26 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 282241118..ef5b104f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,10 +7,10 @@ Features rfc 5280 section 4.2.1.4. * It is now possible to use NIST key wrap mode via the mbedtls_cipher API. Contributed by Jack Lloyd and Fortanix Inc. - * It is now possible to perform RSA PKCS v1.5 signatures with RIPEMD-160 digest. - Contributed by Jack Lloyd and Fortanix Inc. * Add the Wi-SUN Field Area Network (FAN) device extended key usage. * Add the oid certificate policy x509 extension. + * It is now possible to perform RSA PKCS v1.5 signatures with RIPEMD-160 digest. + Contributed by Jack Lloyd and Fortanix Inc. Bugfix * Fix private key DER output in the key_app_writer example. File contents diff --git a/tests/suites/test_suite_oid.data b/tests/suites/test_suite_oid.data index 3d5d9db3f..326193520 100644 --- a/tests/suites/test_suite_oid.data +++ b/tests/suites/test_suite_oid.data @@ -57,3 +57,35 @@ oid_get_x509_extension:"5533445566":0 OID get x509 extension - wrong oid - id-ce oid_get_x509_extension:"551D":0 + +OID hash id - id-md5 +depends_on:MBEDTLS_MD5_C +oid_get_md_alg_id:"2A864886f70d0205":MBEDTLS_MD_MD5 + +OID hash id - id-sha1 +depends_on:MBEDTLS_SHA1_C +oid_get_md_alg_id:"2b0e03021a":MBEDTLS_MD_SHA1 + +OID hash id - id-sha224 +depends_on:MBEDTLS_SHA256_C +oid_get_md_alg_id:"608648016503040204":MBEDTLS_MD_SHA224 + +OID hash id - id-sha256 +depends_on:MBEDTLS_SHA256_C +oid_get_md_alg_id:"608648016503040201":MBEDTLS_MD_SHA256 + +OID hash id - id-sha384 +depends_on:MBEDTLS_SHA512_C +oid_get_md_alg_id:"608648016503040202":MBEDTLS_MD_SHA384 + +OID hash id - id-sha512 +depends_on:MBEDTLS_SHA512_C +oid_get_md_alg_id:"608648016503040203":MBEDTLS_MD_SHA512 + +OID hash id - id-ripemd160 +depends_on:MBEDTLS_RIPEMD160_C +oid_get_md_alg_id:"2b24030201":MBEDTLS_MD_RIPEMD160 + +OID hash id - invalid oid +oid_get_md_alg_id:"2B864886f70d0204":-1 + diff --git a/tests/suites/test_suite_oid.function b/tests/suites/test_suite_oid.function index cb8abe638..065295a7a 100644 --- a/tests/suites/test_suite_oid.function +++ b/tests/suites/test_suite_oid.function @@ -78,3 +78,29 @@ void oid_get_x509_extension( data_t *oid, int exp_type ) } } /* END_CASE */ + +/* BEGIN_CASE */ +void oid_get_md_alg_id( data_t *oid, int exp_md_id ) +{ + mbedtls_asn1_buf md_oid = { 0, 0, NULL }; + int ret; + mbedtls_md_type_t md_id = 0; + + md_oid.tag = MBEDTLS_ASN1_OID; + md_oid.p = oid->x; + md_oid.len = oid->len; + + ret = mbedtls_oid_get_md_alg( &md_oid, &md_id ); + + if( exp_md_id < 0 ) + { + TEST_ASSERT( ret == MBEDTLS_ERR_OID_NOT_FOUND ); + TEST_ASSERT( md_id == 0); + } + else + { + TEST_ASSERT( ret == 0 ); + TEST_ASSERT( (mbedtls_md_type_t)exp_md_id == md_id ); + } +} +/* END_CASE */