26 #if !defined(POLARSSL_CONFIG_FILE)
29 #include POLARSSL_CONFIG_FILE
32 #if defined(POLARSSL_ASN1_PARSE_C)
36 #if defined(POLARSSL_BIGNUM_C)
40 #if defined(POLARSSL_PLATFORM_C)
43 #define polarssl_malloc malloc
44 #define polarssl_free free
54 const unsigned char *end,
57 if( ( end - *p ) < 1 )
60 if( ( **p & 0x80 ) == 0 )
67 if( ( end - *p ) < 2 )
75 if( ( end - *p ) < 3 )
78 *len = ( (*p)[1] << 8 ) | (*p)[2];
83 if( ( end - *p ) < 4 )
86 *len = ( (*p)[1] << 16 ) | ( (*p)[2] << 8 ) | (*p)[3];
91 if( ( end - *p ) < 5 )
94 *len = ( (*p)[1] << 24 ) | ( (*p)[2] << 16 ) | ( (*p)[3] << 8 ) |
104 if( *len > (
size_t) ( end - *p ) )
111 const unsigned char *end,
112 size_t *len,
int tag )
114 if( ( end - *p ) < 1 )
126 const unsigned char *end,
138 *val = ( **p != 0 ) ? 1 : 0;
145 const unsigned char *end,
154 if( len >
sizeof(
int ) || ( **p & 0x80 ) != 0 )
161 *val = ( *val << 8 ) | **p;
168 #if defined(POLARSSL_BIGNUM_C)
170 const unsigned char *end,
228 if( (*len)-- < 2 || *(*p)++ != 0 )
240 const unsigned char *end,
253 if( *p + len != end )
273 if( cur->
next == NULL )
290 const unsigned char *end,
300 if( ( end - *p ) < 1 )
314 memset( params, 0,
sizeof(
asn1_buf) );
334 const unsigned char *end,
340 memset( ¶ms, 0,
sizeof(
asn1_buf) );
342 if( ( ret =
asn1_get_alg( p, end, alg, ¶ms ) ) != 0 )
366 while( ( cur = *head ) != NULL )
375 const char *
oid,
size_t len )
377 while( list != NULL )
379 if( list->
oid.
len == len &&
380 memcmp( list->
oid.
p, oid, len ) == 0 )
int asn1_get_sequence_of(unsigned char **p, const unsigned char *end, asn1_sequence *cur, int tag)
Parses and splits an ASN.1 "SEQUENCE OF <tag>" Updated the pointer to immediately behind the full seq...
asn1_buf buf
Buffer containing the given ASN.1 item.
#define POLARSSL_ERR_ASN1_LENGTH_MISMATCH
Actual length differs from expected length.
int asn1_get_int(unsigned char **p, const unsigned char *end, int *val)
Retrieve an integer ASN.1 tag and its value.
size_t len
ASN1 length, e.g.
Configuration options (set of defines)
#define POLARSSL_ERR_ASN1_INVALID_DATA
Data is invalid.
unsigned char unused_bits
Number of unused bits at the end of the string.
#define POLARSSL_ERR_ASN1_INVALID_LENGTH
Error when trying to determine the length or invalid length.
Container for ASN1 bit strings.
Multi-precision integer library.
asn1_buf val
The named value.
Container for a sequence of ASN.1 items.
unsigned char * p
Raw ASN1 data for the bit string.
asn1_buf oid
The object identifier.
int asn1_get_alg_null(unsigned char **p, const unsigned char *end, asn1_buf *alg)
Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no params.
int asn1_get_alg(unsigned char **p, const unsigned char *end, asn1_buf *alg, asn1_buf *params)
Retrieve an AlgorithmIdentifier ASN.1 sequence.
unsigned char * p
ASN1 data, e.g.
int asn1_get_bool(unsigned char **p, const unsigned char *end, int *val)
Retrieve a boolean ASN.1 tag and its value.
#define POLARSSL_ERR_ASN1_OUT_OF_DATA
Out of data when parsing an ASN1 data structure.
void asn1_free_named_data(asn1_named_data *entry)
Free a asn1_named_data entry.
#define POLARSSL_ERR_ASN1_MALLOC_FAILED
Memory allocation failed.
int mpi_read_binary(mpi *X, const unsigned char *buf, size_t buflen)
Import X from unsigned binary data, big endian.
Container for a sequence or list of 'named' ASN.1 data items.
Type-length-value structure that allows for ASN1 using DER.
int asn1_get_bitstring_null(unsigned char **p, const unsigned char *end, size_t *len)
Retrieve a bitstring ASN.1 tag without unused bits and its value.
size_t len
ASN1 length, e.g.
void asn1_free_named_data_list(asn1_named_data **head)
Free all entries in a asn1_named_data list Head will be set to NULL.
int asn1_get_len(unsigned char **p, const unsigned char *end, size_t *len)
Get the length of an ASN.1 element.
int asn1_get_tag(unsigned char **p, const unsigned char *end, size_t *len, int tag)
Get the tag and length of the tag.
asn1_named_data * asn1_find_named_data(asn1_named_data *list, const char *oid, size_t len)
Find a specific named_data entry in a sequence or list based on the OID.
int asn1_get_bitstring(unsigned char **p, const unsigned char *end, asn1_bitstring *bs)
Retrieve a bitstring ASN.1 tag and its value.
struct _asn1_named_data * next
The next entry in the sequence.
int asn1_get_mpi(unsigned char **p, const unsigned char *end, mpi *X)
Retrieve a MPI value from an integer ASN.1 tag.
#define POLARSSL_ERR_ASN1_UNEXPECTED_TAG
ASN1 tag was of an unexpected value.
struct _asn1_sequence * next
The next entry in the sequence.