From b5419867cdc84acd58b750f1278806287a14caa1 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Wed, 20 Feb 2019 14:20:45 +0000 Subject: [PATCH] Reduce code-size of mbedtls_asn1_get_alg() The previous code - checked that at least 1 byte of ASN.1 tag data is available, - read and stored that ASN.1 tag, - called the ASN.1 parsing function, part of which is checking that enough space is available and that the ASN.1 tag matches the expected value MBEDTLS_ASN1_OID. Since the ASN.1 parsing function includes bounds checks, this can be streamlined to: - call the ASN.1 parsing function directly, - on success, store MBEDTLS_ASN1_OID in the tag field. This commit applies this simplification to mbedtls_asn1_get_alg(). --- library/asn1parse.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/asn1parse.c b/library/asn1parse.c index 171c340b8..b844fc69e 100644 --- a/library/asn1parse.c +++ b/library/asn1parse.c @@ -295,15 +295,12 @@ int mbedtls_asn1_get_alg( unsigned char **p, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) return( ret ); - if( ( end - *p ) < 1 ) - return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); - - alg->tag = **p; end = *p + len; if( ( ret = mbedtls_asn1_get_tag( p, end, &alg->len, MBEDTLS_ASN1_OID ) ) != 0 ) return( ret ); + alg->tag = MBEDTLS_ASN1_OID; alg->p = *p; *p += alg->len;