From 308c1defb0063d1aa0ab378d1a88c5ce12e650d9 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Thu, 28 Apr 2022 18:30:57 +0000 Subject: Rewrite asn1_check_tlen() using CBS. Rather than calling asn1_get_object_cbs(), call asn1_get_identifier_cbs(), then immediately proceed with the tag number and tag class check. Only if that succeeds (or it is not required) do we call asn1_get_length_cbs(). This avoids incurring the overhead of decoding the length in the case where the tag number and tag class do not match. While here rename asn1_check_tlen() to asn1_check_tag() - while we decode the length, what we are normally checking is the tag number and tag class. Also rename the arguments for readability. For now the argument types and encoding remain unchanged. ok inoguchi@ tb@ --- src/lib/libcrypto/asn1/asn1_lib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib/libcrypto/asn1/asn1_lib.c') diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index 6a29c327fe..97ce6caeef 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1_lib.c,v 1.52 2022/03/26 14:47:58 jsing Exp $ */ +/* $OpenBSD: asn1_lib.c,v 1.53 2022/04/28 18:30:57 jsing Exp $ */ /* * Copyright (c) 2021 Joel Sing * @@ -20,7 +20,7 @@ #include "bytestring.h" -static int +int asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class, int *out_constructed, uint32_t *out_tag_number) { @@ -76,7 +76,7 @@ asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class, return 1; } -static int +int asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite, uint32_t *out_length) { -- cgit v1.2.3-55-g6feb