asn1.h
mbedtls/private_access.h
mbedtls/build_info.h
mbedtls/platform_util.h
stddef.h
mbedtls/bignum.h
asn1write.h
oid.h
pkcs12.h
pkcs5.h
pkcs7.h
x509.h
asn1.h
mbedtls/bignum.h
mbedtls/build_info.h
mbedtls/check_config.h
mbedtls/config_adjust_legacy_crypto.h
mbedtls/config_adjust_psa_from_legacy.h
mbedtls/config_adjust_psa_superset_legacy.h
mbedtls/config_adjust_ssl.h
mbedtls/config_adjust_x509.h
mbedtls/config_psa.h
mbedtls/mbedtls_config.h
mbedtls/platform_time.h
mbedtls/platform_util.h
mbedtls/private_access.h
psa/crypto_adjust_auto_enabled.h
psa/crypto_adjust_config_dependencies.h
psa/crypto_adjust_config_key_pair_types.h
psa/crypto_adjust_config_synonyms.h
psa/crypto_legacy.h
inttypes.h
limits.h
stddef.h
stdint.h
stdio.h
time.h
asn1.h
asn1write.h
debug.h
net_sockets.h
oid.h
pkcs12.h
pkcs5.h
pkcs7.h
psa_util.h
ssl.h
ssl_cache.h
ssl_cookie.h
ssl_ticket.h
x509.h
x509_crl.h
x509_crt.h
x509_csr.h
mbedtls_asn1_buf
mbedtls_asn1_bitstring
mbedtls_asn1_sequence
mbedtls_asn1_named_data
ASN1 Error codes

These error codes are combined with other error codes for higher error granularity. e.g. X.509 and PKCS #7 error codes ASN1 is a standard to specify data structures.

- MBEDTLS_ERR_ASN1_OUT_OF_DATA
- MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
- MBEDTLS_ERR_ASN1_INVALID_LENGTH
- MBEDTLS_ERR_ASN1_LENGTH_MISMATCH
- MBEDTLS_ERR_ASN1_INVALID_DATA
- MBEDTLS_ERR_ASN1_ALLOC_FAILED
- MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
DER constants

These constants comply with the DER encoded ASN.1 type tags. DER encoding uses hexadecimal representation. An example DER sequence is:

- 0x02 tag indicating INTEGER

- 0x01 length in octets

- 0x05 value Such sequences are typically read into `mbedtls_x509_buf`.

- MBEDTLS_ASN1_BOOLEAN
- MBEDTLS_ASN1_INTEGER
- MBEDTLS_ASN1_BIT_STRING
- MBEDTLS_ASN1_OCTET_STRING
- MBEDTLS_ASN1_NULL
- MBEDTLS_ASN1_OID
- MBEDTLS_ASN1_ENUMERATED
- MBEDTLS_ASN1_UTF8_STRING
- MBEDTLS_ASN1_SEQUENCE
- MBEDTLS_ASN1_SET
- MBEDTLS_ASN1_PRINTABLE_STRING
- MBEDTLS_ASN1_T61_STRING
- MBEDTLS_ASN1_IA5_STRING
- MBEDTLS_ASN1_UTC_TIME
- MBEDTLS_ASN1_GENERALIZED_TIME
- MBEDTLS_ASN1_UNIVERSAL_STRING
- MBEDTLS_ASN1_BMP_STRING
- MBEDTLS_ASN1_PRIMITIVE
- MBEDTLS_ASN1_CONSTRUCTED
- MBEDTLS_ASN1_CONTEXT_SPECIFIC
- MBEDTLS_ASN1_IS_STRING_TAG
- MBEDTLS_ASN1_TAG_CLASS_MASK
- MBEDTLS_ASN1_TAG_PC_MASK
- MBEDTLS_ASN1_TAG_VALUE_MASK
Functions to parse ASN.1 data structures
- mbedtls_asn1_buf
- mbedtls_asn1_bitstring
- mbedtls_asn1_sequence
- mbedtls_asn1_named_data
- mbedtls_asn1_get_len
- mbedtls_asn1_get_tag
- mbedtls_asn1_get_bool
- mbedtls_asn1_get_int
- mbedtls_asn1_get_enum
- mbedtls_asn1_get_bitstring
- mbedtls_asn1_get_bitstring_null
- mbedtls_asn1_get_sequence_of
- mbedtls_asn1_sequence_free
- mbedtls_asn1_traverse_sequence_of
- mbedtls_asn1_get_mpi
- mbedtls_asn1_get_alg
- mbedtls_asn1_get_alg_null
- mbedtls_asn1_find_named_data
- mbedtls_asn1_free_named_data
- mbedtls_asn1_free_named_data_list
- mbedtls_asn1_free_named_data_list_shallow
- MBEDTLS_OID_SIZE
- MBEDTLS_OID_CMP
- MBEDTLS_OID_CMP_RAW

Generic ASN.1 parsing.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */
    #ifndefMBEDTLS_ASN1_H
    #defineMBEDTLS_ASN1_H
    #include"mbedtls/private_access.h"

    #include"mbedtls/build_info.h"
    #include"mbedtls/platform_util.h"

    #include<stddef.h>

    #ifdefined(MBEDTLS_BIGNUM_C)
    #include"mbedtls/bignum.h"
    #endif

    #defineMBEDTLS_ERR_ASN1_OUT_OF_DATA-0x0060
    #defineMBEDTLS_ERR_ASN1_UNEXPECTED_TAG-0x0062
    #defineMBEDTLS_ERR_ASN1_INVALID_LENGTH-0x0064
    #defineMBEDTLS_ERR_ASN1_LENGTH_MISMATCH-0x0066
    #defineMBEDTLS_ERR_ASN1_INVALID_DATA-0x0068
    #defineMBEDTLS_ERR_ASN1_ALLOC_FAILED-0x006A
    #defineMBEDTLS_ERR_ASN1_BUF_TOO_SMALL-0x006C

    #defineMBEDTLS_ASN1_BOOLEAN0x01
    #defineMBEDTLS_ASN1_INTEGER0x02
    #defineMBEDTLS_ASN1_BIT_STRING0x03
    #defineMBEDTLS_ASN1_OCTET_STRING0x04
    #defineMBEDTLS_ASN1_NULL0x05
    #defineMBEDTLS_ASN1_OID0x06
    #defineMBEDTLS_ASN1_ENUMERATED0x0A
    #defineMBEDTLS_ASN1_UTF8_STRING0x0C
    #defineMBEDTLS_ASN1_SEQUENCE0x10
    #defineMBEDTLS_ASN1_SET0x11
    #defineMBEDTLS_ASN1_PRINTABLE_STRING0x13
    #defineMBEDTLS_ASN1_T61_STRING0x14
    #defineMBEDTLS_ASN1_IA5_STRING0x16
    #defineMBEDTLS_ASN1_UTC_TIME0x17
    #defineMBEDTLS_ASN1_GENERALIZED_TIME0x18
    #defineMBEDTLS_ASN1_UNIVERSAL_STRING0x1C
    #defineMBEDTLS_ASN1_BMP_STRING0x1E
    #defineMBEDTLS_ASN1_PRIMITIVE0x00
    #defineMBEDTLS_ASN1_CONSTRUCTED0x20
    #defineMBEDTLS_ASN1_CONTEXT_SPECIFIC0x80

    /*Slightlysmallerwaytocheckiftagisastringtag
    *comparedtocanonicalimplementation.*/
    #defineMBEDTLS_ASN1_IS_STRING_TAG(tag)\
    ((unsignedint)(tag)<32u&&(\
    ((1u<<(tag))&((1u<<MBEDTLS_ASN1_BMP_STRING)|\
    (1u<<MBEDTLS_ASN1_UTF8_STRING)|\
    (1u<<MBEDTLS_ASN1_T61_STRING)|\
    (1u<<MBEDTLS_ASN1_IA5_STRING)|\
    (1u<<MBEDTLS_ASN1_UNIVERSAL_STRING)|\
    (1u<<MBEDTLS_ASN1_PRINTABLE_STRING)))!=0))

    /*
    *BitmasksforeachofthecomponentsofanASN.1tagasspecifiedin
    *ITUX.690(08/2015),section8.1"Generalrulesforencoding",
    *paragraph8.1.2.2:
    *
    *Bit87651
    *+-------+-----+------------+
    *|Class|P/C|Tagnumber|
    *+-------+-----+------------+
    */
    #defineMBEDTLS_ASN1_TAG_CLASS_MASK0xC0
    #defineMBEDTLS_ASN1_TAG_PC_MASK0x20
    #defineMBEDTLS_ASN1_TAG_VALUE_MASK0x1F

    #defineMBEDTLS_OID_SIZE(x)(sizeof(x)-1)

    #defineMBEDTLS_OID_CMP(oid_str,oid_buf)\
    ((MBEDTLS_OID_SIZE(oid_str)!=(oid_buf)->len)||\
    memcmp((oid_str),(oid_buf)->p,(oid_buf)->len)!=0)

    #defineMBEDTLS_OID_CMP_RAW(oid_str,oid_buf,oid_buf_len)\
    ((MBEDTLS_OID_SIZE(oid_str)!=(oid_buf_len))||\
    memcmp((oid_str),(oid_buf),(oid_buf_len))!=0)

    #ifdef__cplusplus
    extern"C"{
    #endif

    typedefstructmbedtls_asn1_buf{
    inttag;
    size_tlen;
    unsignedchar*p;
    }
    mbedtls_asn1_buf;

    typedefstructmbedtls_asn1_bitstring{
    size_tlen;
    unsignedcharunused_bits;
    unsignedchar*p;
    }
    mbedtls_asn1_bitstring;

    typedefstructmbedtls_asn1_sequence{
    mbedtls_asn1_bufbuf;

    structmbedtls_asn1_sequence*next;
    }
    mbedtls_asn1_sequence;

    typedefstructmbedtls_asn1_named_data{
    mbedtls_asn1_bufoid;
    mbedtls_asn1_bufval;

    structmbedtls_asn1_named_data*next;

    unsignedcharMBEDTLS_PRIVATE(next_merged);
    }
    mbedtls_asn1_named_data;

    #ifdefined(MBEDTLS_ASN1_PARSE_C)||defined(MBEDTLS_X509_CREATE_C)||\
    defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA)
    intmbedtls_asn1_get_len(unsignedchar**p,
    constunsignedchar*end,
    size_t*len);

    intmbedtls_asn1_get_tag(unsignedchar**p,
    constunsignedchar*end,
    size_t*len,inttag);
    #endif/*MBEDTLS_ASN1_PARSE_C||MBEDTLS_X509_CREATE_C||MBEDTLS_PSA_UTIL_HAVE_ECDSA*/

    #ifdefined(MBEDTLS_ASN1_PARSE_C)
    intmbedtls_asn1_get_bool(unsignedchar**p,
    constunsignedchar*end,
    int*val);

    intmbedtls_asn1_get_int(unsignedchar**p,
    constunsignedchar*end,
    int*val);

    intmbedtls_asn1_get_enum(unsignedchar**p,
    constunsignedchar*end,
    int*val);

    intmbedtls_asn1_get_bitstring(unsignedchar**p,constunsignedchar*end,
    mbedtls_asn1_bitstring*bs);

    intmbedtls_asn1_get_bitstring_null(unsignedchar**p,
    constunsignedchar*end,
    size_t*len);

    intmbedtls_asn1_get_sequence_of(unsignedchar**p,
    constunsignedchar*end,
    mbedtls_asn1_sequence*cur,
    inttag);
    voidmbedtls_asn1_sequence_free(mbedtls_asn1_sequence*seq);

    intmbedtls_asn1_traverse_sequence_of(
    unsignedchar**p,
    constunsignedchar*end,
    unsignedchartag_must_mask,unsignedchartag_must_val,
    unsignedchartag_may_mask,unsignedchartag_may_val,
    int(*cb)(void*ctx,inttag,
    unsignedchar*start,size_tlen),
    void*ctx);

    #ifdefined(MBEDTLS_BIGNUM_C)
    intmbedtls_asn1_get_mpi(unsignedchar**p,
    constunsignedchar*end,
    mbedtls_mpi*X);
    #endif/*MBEDTLS_BIGNUM_C*/

    intmbedtls_asn1_get_alg(unsignedchar**p,
    constunsignedchar*end,
    mbedtls_asn1_buf*alg,mbedtls_asn1_buf*params);

    intmbedtls_asn1_get_alg_null(unsignedchar**p,
    constunsignedchar*end,
    mbedtls_asn1_buf*alg);

    constmbedtls_asn1_named_data*mbedtls_asn1_find_named_data(constmbedtls_asn1_named_data*list,
    constchar*oid,size_tlen);

    #if!defined(MBEDTLS_DEPRECATED_REMOVED)
    voidMBEDTLS_DEPRECATEDmbedtls_asn1_free_named_data(mbedtls_asn1_named_data*entry);
    #endif/*MBEDTLS_DEPRECATED_REMOVED*/

    voidmbedtls_asn1_free_named_data_list(mbedtls_asn1_named_data**head);

    voidmbedtls_asn1_free_named_data_list_shallow(mbedtls_asn1_named_data*name);

    #endif/*MBEDTLS_ASN1_PARSE_C*/

    #ifdef__cplusplus
    }
    #endif

    #endif/*asn1.h*/