52#if !defined(MBEDTLS_CONFIG_FILE)
55#include MBEDTLS_CONFIG_FILE
58#if defined(MBEDTLS_X509_CSR_WRITE_C)
68#if defined(MBEDTLS_PEM_WRITE_C)
76#if MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_MPI_MAX_SIZE
77#define SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN
79#define SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
82#if defined(MBEDTLS_PLATFORM_C)
86#define mbedtls_calloc calloc
87#define mbedtls_free free
105 ctx->md_alg = md_alg;
114 const char *subject_name )
120 const char *oid,
size_t oid_len,
121 const unsigned char *
val,
size_t val_len )
127static size_t csr_get_unused_bits_for_named_bitstring(
unsigned char bitstring,
133 for( unused_bits = bit_offset; unused_bits < 8; unused_bits++ )
134 if( ( ( bitstring >> unused_bits ) & 0x1 ) != 0 )
137 return( unused_bits );
142 unsigned char buf[4];
149 unused_bits = csr_get_unused_bits_for_named_bitstring( key_usage, 0 );
154 else if( ret < 3 || ret > 4 )
167 unsigned char ns_cert_type )
169 unsigned char buf[4];
176 unused_bits = csr_get_unused_bits_for_named_bitstring( ns_cert_type, 0 );
184 else if( ret < 3 || ret > 4 )
200 int (*f_rng)(
void *,
unsigned char *,
size_t),
205 size_t sig_oid_len = 0;
206 unsigned char *
c, *c2;
207 unsigned char hash[64];
208 size_t pub_len = 0, sig_and_oid_len = 0, sig_len;
281 f_rng, p_rng ) ) != 0 )
294 &sig_oid, &sig_oid_len ) ) != 0 )
323 len += sig_and_oid_len;
338 int (*f_rng)(
void *,
unsigned char *,
size_t),
349 ret = x509write_csr_der_internal(
ctx,
buf,
size, sig, f_rng, p_rng );
356#define PEM_BEGIN_CSR "-----BEGIN CERTIFICATE REQUEST-----\n"
357#define PEM_END_CSR "-----END CERTIFICATE REQUEST-----\n"
359#if defined(MBEDTLS_PEM_WRITE_C)
361 int (*f_rng)(
void *,
unsigned char *,
size_t),
369 f_rng, p_rng ) ) < 0 )
374 if( (
ret = mbedtls_pem_write_buffer( PEM_BEGIN_CSR, PEM_END_CSR,
ASN.1 buffer writing functionality.
int mbedtls_asn1_write_tag(unsigned char **p, unsigned char *start, unsigned char tag)
Write an ASN.1 tag in ASN.1 format.
int mbedtls_asn1_write_bitstring(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t bits)
Write a bitstring tag (MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format.
#define MBEDTLS_ASN1_CHK_ADD(g, f)
int mbedtls_asn1_write_int(unsigned char **p, unsigned char *start, int val)
Write an int tag (MBEDTLS_ASN1_INTEGER) and value in ASN.1 format.
int mbedtls_asn1_write_len(unsigned char **p, unsigned char *start, size_t len)
Write a length field in ASN.1 format.
int mbedtls_asn1_write_oid(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len)
Write an OID tag (MBEDTLS_ASN1_OID) and data in ASN.1 format.
GLenum GLuint GLenum GLsizei const GLchar * buf
#define MBEDTLS_ASN1_SEQUENCE
#define MBEDTLS_ASN1_CONTEXT_SPECIFIC
#define MBEDTLS_ASN1_CONSTRUCTED
#define MBEDTLS_OID_SIZE(x)
void mbedtls_asn1_free_named_data_list(mbedtls_asn1_named_data **head)
Free all entries in a mbedtls_asn1_named_data list Head will be set to NULL.
int mbedtls_x509_write_extensions(unsigned char **p, unsigned char *start, mbedtls_asn1_named_data *first)
int mbedtls_x509_write_sig(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len, unsigned char *sig, size_t size)
int mbedtls_x509_set_extension(mbedtls_asn1_named_data **head, const char *oid, size_t oid_len, int critical, const unsigned char *val, size_t val_len)
#define MBEDTLS_ERR_X509_INVALID_FORMAT
int mbedtls_x509_write_names(unsigned char **p, unsigned char *start, mbedtls_asn1_named_data *first)
#define MBEDTLS_ERR_X509_ALLOC_FAILED
#define MBEDTLS_ERR_X509_INVALID_ALG
int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *name)
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
mbedtls_md_type_t
Supported message digests.
int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
This function calculates the message-digest of a buffer, with respect to a configurable message-diges...
#define memmove(s1, s2, n)
Object Identifier (OID) database.
#define MBEDTLS_OID_PKCS9_CSR_EXT_REQ
#define MBEDTLS_OID_KEY_USAGE
#define MBEDTLS_OID_NS_CERT_TYPE
int mbedtls_oid_get_oid_by_sig_alg(mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg, const char **oid, size_t *olen)
Translate md_type and pk_type into SignatureAlgorithm OID.
Privacy Enhanced Mail (PEM) decoding.
int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type)
Tell if a context can do the operation given by type.
mbedtls_pk_type_t
Public key types.
int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, unsigned char *sig, size_t *sig_len, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Make signature, including padding if relevant.
#define mbedtls_md_info_from_type
Configuration options (set of defines)
X.509 certificate signing request parsing and writing.