]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
ASN.1: Add a helper for parsing AlgorithmIdentifier
authorJouni Malinen <jouni@codeaurora.org>
Thu, 30 Jan 2020 13:04:03 +0000 (15:04 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 30 Jan 2020 13:23:32 +0000 (15:23 +0200)
Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
src/tls/asn1.c
src/tls/asn1.h

index 13b7fe1a5ae255fed1b4191a87c1eb95f4adc427..54c17deaec9d851e2812666c5ce2288eb4aa7f37 100644 (file)
@@ -325,3 +325,27 @@ int asn1_get_sequence(const u8 *buf, size_t len, struct asn1_hdr *hdr,
                *next = hdr->payload + hdr->length;
        return 0;
 }
+
+
+int asn1_get_alg_id(const u8 *buf, size_t len, struct asn1_oid *oid,
+                   const u8 **params, size_t *params_len, const u8 **next)
+{
+       const u8 *pos = buf, *end = buf + len;
+       struct asn1_hdr hdr;
+
+       /*
+        * AlgorithmIdentifier ::= SEQUENCE {
+        *     algorithm            OBJECT IDENTIFIER,
+        *     parameters           ANY DEFINED BY algorithm OPTIONAL}
+        */
+       if (asn1_get_sequence(pos, end - pos, &hdr, next) < 0 ||
+           asn1_get_oid(hdr.payload, hdr.length, oid, &pos) < 0)
+               return -1;
+
+       if (params && params_len) {
+               *params = pos;
+               *params_len = hdr.payload + hdr.length - pos;
+       }
+
+       return 0;
+}
index d769a4e9bb48df7ceec84a5e11af760f12df71c4..25a05c78bd5c21b523c1636025b120c6e7364a49 100644 (file)
@@ -68,6 +68,8 @@ int asn1_oid_equal(const struct asn1_oid *a, const struct asn1_oid *b);
 int asn1_get_integer(const u8 *buf, size_t len, int *integer, const u8 **next);
 int asn1_get_sequence(const u8 *buf, size_t len, struct asn1_hdr *hdr,
                      const u8 **next);
+int asn1_get_alg_id(const u8 *buf, size_t len, struct asn1_oid *oid,
+                   const u8 **params, size_t *params_len, const u8 **next);
 
 extern struct asn1_oid asn1_sha1_oid;
 extern struct asn1_oid asn1_sha256_oid;