]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
RSA: Use ASN.1 helper functions
authorJouni Malinen <j@w1.fi>
Fri, 12 Mar 2021 21:24:54 +0000 (23:24 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 14 Mar 2021 09:37:58 +0000 (11:37 +0200)
Simplify ASN.1 parser operations by using the shared helper functions.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/tls/rsa.c

index 1b01f5843dae67912945152c07cceeba13289d6c..56ae7d7795aaf81da1c19b721cbca7b0b4069cb4 100644 (file)
@@ -37,9 +37,8 @@ static const u8 * crypto_rsa_parse_integer(const u8 *pos, const u8 *end,
                return NULL;
 
        if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
-           hdr.class != ASN1_CLASS_UNIVERSAL || hdr.tag != ASN1_TAG_INTEGER) {
-               wpa_printf(MSG_DEBUG, "RSA: Expected INTEGER - found class %d "
-                          "tag 0x%x", hdr.class, hdr.tag);
+           !asn1_is_integer(&hdr)) {
+               asn1_unexpected(&hdr, "RSA: Expected INTEGER");
                return NULL;
        }
 
@@ -84,12 +83,8 @@ crypto_rsa_import_public_key(const u8 *buf, size_t len)
         * }
         */
 
-       if (asn1_get_next(buf, len, &hdr) < 0 ||
-           hdr.class != ASN1_CLASS_UNIVERSAL ||
-           hdr.tag != ASN1_TAG_SEQUENCE) {
-               wpa_printf(MSG_DEBUG, "RSA: Expected SEQUENCE "
-                          "(public key) - found class %d tag 0x%x",
-                          hdr.class, hdr.tag);
+       if (asn1_get_next(buf, len, &hdr) < 0 || !asn1_is_sequence(&hdr)) {
+               asn1_unexpected(&hdr, "RSA: Expected SEQUENCE (public key)");
                goto error;
        }
        pos = hdr.payload;
@@ -191,12 +186,8 @@ crypto_rsa_import_private_key(const u8 *buf, size_t len)
         *
         * Version ::= INTEGER -- shall be 0 for this version of the standard
         */
-       if (asn1_get_next(buf, len, &hdr) < 0 ||
-           hdr.class != ASN1_CLASS_UNIVERSAL ||
-           hdr.tag != ASN1_TAG_SEQUENCE) {
-               wpa_printf(MSG_DEBUG, "RSA: Expected SEQUENCE "
-                          "(public key) - found class %d tag 0x%x",
-                          hdr.class, hdr.tag);
+       if (asn1_get_next(buf, len, &hdr) < 0 || !asn1_is_sequence(&hdr)) {
+               asn1_unexpected(&hdr, "RSA: Expected SEQUENCE (public key)");
                goto error;
        }
        pos = hdr.payload;