26 #if !defined(POLARSSL_CONFIG_FILE)
29 #include POLARSSL_CONFIG_FILE
32 #if defined(POLARSSL_ASN1_WRITE_C)
36 #if defined(POLARSSL_PLATFORM_C)
40 #define polarssl_malloc malloc
41 #define polarssl_free free
44 int asn1_write_len(
unsigned char **p,
unsigned char *start,
size_t len )
51 *--(*p) = (
unsigned char) len;
60 *--(*p) = (
unsigned char) len;
71 *--(*p) = ( len / 256 ) % 256;
77 int asn1_write_tag(
unsigned char **p,
unsigned char *start,
unsigned char tag )
88 const unsigned char *buf,
size_t size )
92 if( *p - start < (
int) size )
97 memcpy( *p, buf, len );
102 #if defined(POLARSSL_BIGNUM_C)
112 if( *p - start < (
int) len )
121 if( X->
s ==1 && **p & 0x80 )
154 const char *
oid,
size_t oid_len )
160 (
const unsigned char *) oid, oid_len ) );
168 const char *oid,
size_t oid_len,
188 int asn1_write_bool(
unsigned char **p,
unsigned char *start,
int boolean )
196 *--(*p) = (boolean) ? 1 : 0;
220 if( val > 0 && **p & 0x80 )
236 const char *text,
size_t text_len )
242 (
const unsigned char *) text, text_len ) );
251 const char *text,
size_t text_len )
257 (
const unsigned char *) text, text_len ) );
266 const unsigned char *buf,
size_t bits )
269 size_t len = 0, size;
271 size = ( bits / 8 ) + ( ( bits % 8 ) ? 1 : 0 );
275 if( *p - start < (
int) size + 1 )
280 memcpy( *p, buf, size );
284 *--(*p) = (
unsigned char) (size * 8 - bits);
293 const unsigned char *buf,
size_t size )
307 const char *oid,
size_t oid_len,
308 const unsigned char *val,
324 if( cur->
oid.
p == NULL )
332 if( cur->
val.
p == NULL )
339 memcpy( cur->
oid.
p, oid, oid_len );
344 else if( cur->
val.
len < val_len )
353 if( cur->
val.
p == NULL )
362 memcpy( cur->
val.
p, val, val_len );
#define ASN1_PRINTABLE_STRING
int asn1_write_octet_string(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t size)
Write an octet string tag (ASN1_OCTET_STRING) and value in ASN.1 format Note: function works backward...
int asn1_write_ia5_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write an IA5 string tag (ASN1_IA5_STRING) and value in ASN.1 format Note: function works backwards in...
asn1_named_data * asn1_store_named_data(asn1_named_data **list, const char *oid, size_t oid_len, const unsigned char *val, size_t val_len)
Create or find a specific named_data entry for writing in a sequence or list based on the OID...
#define POLARSSL_ERR_ASN1_BUF_TOO_SMALL
Buffer too small when writing ASN.1 data structure.
Configuration options (set of defines)
int asn1_write_len(unsigned char **p, unsigned char *start, size_t len)
Write a length field in ASN.1 format Note: function works backwards in data buffer.
int asn1_write_printable_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write a printable string tag (ASN1_PRINTABLE_STRING) and value in ASN.1 format Note: function works b...
asn1_buf val
The named value.
asn1_buf oid
The object identifier.
int asn1_write_raw_buffer(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t size)
Write raw buffer data Note: function works backwards in data buffer.
unsigned char * p
ASN1 data, e.g.
int asn1_write_null(unsigned char **p, unsigned char *start)
Write a NULL tag (ASN1_NULL) with zero data in ASN.1 format Note: function works backwards in data bu...
int asn1_write_mpi(unsigned char **p, unsigned char *start, mpi *X)
Write a big number (ASN1_INTEGER) in ASN.1 format Note: function works backwards in data buffer...
int asn1_write_bitstring(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t bits)
Write a bitstring tag (ASN1_BIT_STRING) and value in ASN.1 format Note: function works backwards in d...
int asn1_write_int(unsigned char **p, unsigned char *start, int val)
Write an int tag (ASN1_INTEGER) and value in ASN.1 format Note: function works backwards in data buff...
Container for a sequence or list of 'named' ASN.1 data items.
size_t len
ASN1 length, e.g.
#define ASN1_CHK_ADD(g, f)
int asn1_write_algorithm_identifier(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len, size_t par_len)
Write an AlgorithmIdentifier sequence in ASN.1 format Note: function works backwards in data buffer...
size_t mpi_size(const mpi *X)
Return the total size in bytes.
int asn1_write_bool(unsigned char **p, unsigned char *start, int boolean)
Write a boolean tag (ASN1_BOOLEAN) and value in ASN.1 format Note: function works backwards in data b...
int mpi_write_binary(const mpi *X, unsigned char *buf, size_t buflen)
Export X into unsigned binary data, big endian.
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.
struct _asn1_named_data * next
The next entry in the sequence.
ASN.1 buffer writing functionality.
int asn1_write_oid(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len)
Write an OID tag (ASN1_OID) and data in ASN.1 format Note: function works backwards in data buffer...
#define ASN1_OCTET_STRING
int asn1_write_tag(unsigned char **p, unsigned char *start, unsigned char tag)
Write a ASN.1 tag in ASN.1 format Note: function works backwards in data buffer.