summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/asn1_lib.c
diff options
context:
space:
mode:
authorjsing <>2022-04-28 18:30:57 +0000
committerjsing <>2022-04-28 18:30:57 +0000
commit308c1defb0063d1aa0ab378d1a88c5ce12e650d9 (patch)
tree897dde441b9fb1700461ec4356623e41d0139e0a /src/lib/libcrypto/asn1/asn1_lib.c
parent7e4a5a70be4f9de72ee5cafeda9f8966ced355f5 (diff)
downloadopenbsd-308c1defb0063d1aa0ab378d1a88c5ce12e650d9.tar.gz
openbsd-308c1defb0063d1aa0ab378d1a88c5ce12e650d9.tar.bz2
openbsd-308c1defb0063d1aa0ab378d1a88c5ce12e650d9.zip
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@
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_lib.c')
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c6
1 files changed, 3 insertions, 3 deletions
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 @@
1/* $OpenBSD: asn1_lib.c,v 1.52 2022/03/26 14:47:58 jsing Exp $ */ 1/* $OpenBSD: asn1_lib.c,v 1.53 2022/04/28 18:30:57 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2021 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -20,7 +20,7 @@
20 20
21#include "bytestring.h" 21#include "bytestring.h"
22 22
23static int 23int
24asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class, 24asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class,
25 int *out_constructed, uint32_t *out_tag_number) 25 int *out_constructed, uint32_t *out_tag_number)
26{ 26{
@@ -76,7 +76,7 @@ asn1_get_identifier_cbs(CBS *cbs, int der_mode, uint8_t *out_class,
76 return 1; 76 return 1;
77} 77}
78 78
79static int 79int
80asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite, 80asn1_get_length_cbs(CBS *cbs, int der_mode, int *out_indefinite,
81 uint32_t *out_length) 81 uint32_t *out_length)
82{ 82{