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
51 static void polarssl_zeroize(
void *v,
size_t n ) {
52 volatile unsigned char *p = v;
while( n-- ) *p++ = 0;
59 const unsigned char *end,
62 if( ( end - *p ) < 1 )
65 if( ( **p & 0x80 ) == 0 )
72 if( ( end - *p ) < 2 )
80 if( ( end - *p ) < 3 )
83 *len = ( (*p)[1] << 8 ) | (*p)[2];
88 if( ( end - *p ) < 4 )
91 *len = ( (*p)[1] << 16 ) | ( (*p)[2] << 8 ) | (*p)[3];
96 if( ( end - *p ) < 5 )
99 *len = ( (*p)[1] << 24 ) | ( (*p)[2] << 16 ) | ( (*p)[3] << 8 ) |
109 if( *len > (
size_t) ( end - *p ) )
116 const unsigned char *end,
117 size_t *len,
int tag )
119 if( ( end - *p ) < 1 )
131 const unsigned char *end,
143 *val = ( **p != 0 ) ? 1 : 0;
150 const unsigned char *end,
159 if( len >
sizeof(
int ) || ( **p & 0x80 ) != 0 )
166 *val = ( *val << 8 ) | **p;
173 #if defined(POLARSSL_BIGNUM_C)
175 const unsigned char *end,
233 if( (*len)-- < 2 || *(*p)++ != 0 )
245 const unsigned char *end,
258 if( *p + len != end )
278 if( cur->
next == NULL )
295 const unsigned char *end,
305 if( ( end - *p ) < 1 )
319 polarssl_zeroize( params,
sizeof(
asn1_buf) );
339 const unsigned char *end,
345 memset( ¶ms, 0,
sizeof(
asn1_buf) );
347 if( ( ret =
asn1_get_alg( p, end, alg, ¶ms ) ) != 0 )
371 while( ( cur = *head ) != NULL )
380 const char *
oid,
size_t len )
382 while( list != NULL )
384 if( list->
oid.
len == len &&
385 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 " 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.