From b59d3f1692b6df35ab5ebf40aa21bfab114f6498 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 22 Feb 2019 17:49:34 +0000 Subject: [PATCH] Add single function to parse ASN.1 AlgorithmIdentifier to x509.c --- include/mbedtls/x509.h | 4 ++++ library/x509.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/mbedtls/x509.h b/include/mbedtls/x509.h index c02c7c8ba..8297910cc 100644 --- a/include/mbedtls/x509.h +++ b/include/mbedtls/x509.h @@ -305,6 +305,10 @@ int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params, int *salt_len ); #endif int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig ); +int mbedtls_x509_get_sig_alg_raw( unsigned char **p, unsigned char const *end, + mbedtls_md_type_t *md_alg, + mbedtls_pk_type_t *pk_alg, + void **sig_opts ); int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params, mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg, void **sig_opts ); diff --git a/library/x509.c b/library/x509.c index be170bb46..05d995c59 100644 --- a/library/x509.c +++ b/library/x509.c @@ -802,6 +802,21 @@ int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x return( 0 ); } +int mbedtls_x509_get_sig_alg_raw( unsigned char **p, unsigned char const *end, + mbedtls_md_type_t *md_alg, + mbedtls_pk_type_t *pk_alg, + void **sig_opts ) +{ + int ret; + mbedtls_asn1_buf alg, params; + ret = mbedtls_asn1_get_alg( p, end, &alg, ¶ms ); + if( ret != 0 ) + return( MBEDTLS_ERR_X509_INVALID_ALG + ret ); + + return( mbedtls_x509_get_sig_alg( &alg, ¶ms, md_alg, + pk_alg, sig_opts ) ); +} + /* * Get signature algorithm from alg OID and optional parameters */