blob: 604c94c3e59abbb4ec736ef919c1c0cf66a131f0 [file] [log] [blame]
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001/*
2 * X.509 Certificate Signing Request writing
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker7c6b2c32013-09-16 13:49:26 +02006 */
7/*
8 * References:
9 * - CSRs: PKCS#10 v1.7 aka RFC 2986
10 * - attributes: PKCS#9 v2.0 aka RFC 2985
11 */
12
Harry Ramsey0f6bc412024-10-04 10:36:54 +010013#include "x509_internal.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020014
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020015#if defined(MBEDTLS_X509_CSR_WRITE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020016
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000017#include "mbedtls/x509_csr.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000018#include "mbedtls/asn1write.h"
Janos Follath73c616b2019-12-18 15:07:04 +000019#include "mbedtls/error.h"
20#include "mbedtls/oid.h"
Andres Amaya Garcia1f6301b2018-04-17 09:51:09 -050021#include "mbedtls/platform_util.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020022
Andrzej Kurekd4a65532018-10-31 06:18:39 -040023#if defined(MBEDTLS_USE_PSA_CRYPTO)
24#include "psa/crypto.h"
Manuel Pégourié-Gonnard2be8c632023-06-07 13:07:21 +020025#include "psa_util_internal.h"
Valerio Setti384fbde2024-01-02 13:26:40 +010026#include "mbedtls/psa_util.h"
pespacek7599a772022-02-07 14:40:55 +010027#endif /* MBEDTLS_USE_PSA_CRYPTO */
Andrzej Kurekd4a65532018-10-31 06:18:39 -040028
Rich Evans00ab4702015-02-06 13:43:58 +000029#include <string.h>
30#include <stdlib.h>
31
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000033#include "mbedtls/pem.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020034#endif
35
Doru Gucea2957b352018-12-14 21:08:35 +020036#include "mbedtls/platform.h"
Doru Gucea2957b352018-12-14 21:08:35 +020037
Gilles Peskine449bd832023-01-11 14:50:10 +010038void mbedtls_x509write_csr_init(mbedtls_x509write_csr *ctx)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020039{
Gilles Peskine449bd832023-01-11 14:50:10 +010040 memset(ctx, 0, sizeof(mbedtls_x509write_csr));
Paul Bakker7c6b2c32013-09-16 13:49:26 +020041}
42
Gilles Peskine449bd832023-01-11 14:50:10 +010043void mbedtls_x509write_csr_free(mbedtls_x509write_csr *ctx)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020044{
Troy-Butler9ac3e232024-03-22 14:46:04 -040045 if (ctx == NULL) {
46 return;
47 }
48
Gilles Peskine449bd832023-01-11 14:50:10 +010049 mbedtls_asn1_free_named_data_list(&ctx->subject);
50 mbedtls_asn1_free_named_data_list(&ctx->extensions);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020051
Gilles Peskine449bd832023-01-11 14:50:10 +010052 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_x509write_csr));
Paul Bakker7c6b2c32013-09-16 13:49:26 +020053}
54
Gilles Peskine449bd832023-01-11 14:50:10 +010055void mbedtls_x509write_csr_set_md_alg(mbedtls_x509write_csr *ctx, mbedtls_md_type_t md_alg)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020056{
57 ctx->md_alg = md_alg;
58}
59
Gilles Peskine449bd832023-01-11 14:50:10 +010060void mbedtls_x509write_csr_set_key(mbedtls_x509write_csr *ctx, mbedtls_pk_context *key)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020061{
62 ctx->key = key;
63}
64
Gilles Peskine449bd832023-01-11 14:50:10 +010065int mbedtls_x509write_csr_set_subject_name(mbedtls_x509write_csr *ctx,
66 const char *subject_name)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020067{
Gilles Peskine449bd832023-01-11 14:50:10 +010068 return mbedtls_x509_string_to_names(&ctx->subject, subject_name);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020069}
70
Gilles Peskine449bd832023-01-11 14:50:10 +010071int mbedtls_x509write_csr_set_extension(mbedtls_x509write_csr *ctx,
72 const char *oid, size_t oid_len,
73 int critical,
74 const unsigned char *val, size_t val_len)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020075{
Gilles Peskine449bd832023-01-11 14:50:10 +010076 return mbedtls_x509_set_extension(&ctx->extensions, oid, oid_len,
77 critical, val, val_len);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020078}
79
Hannes Tschofenig6b108602022-12-28 18:38:53 +010080int mbedtls_x509write_csr_set_subject_alternative_name(mbedtls_x509write_csr *ctx,
81 const mbedtls_x509_san_list *san_list)
82{
Andrzej Kurekc508dc22023-07-07 08:20:02 -040083 return mbedtls_x509_write_set_san_common(&ctx->extensions, san_list);
Hannes Tschofenig6b108602022-12-28 18:38:53 +010084}
85
Gilles Peskine449bd832023-01-11 14:50:10 +010086int mbedtls_x509write_csr_set_key_usage(mbedtls_x509write_csr *ctx, unsigned char key_usage)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020087{
Gilles Peskine449bd832023-01-11 14:50:10 +010088 unsigned char buf[4] = { 0 };
Paul Bakker7c6b2c32013-09-16 13:49:26 +020089 unsigned char *c;
Janos Follath865b3eb2019-12-16 11:46:15 +000090 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020091
92 c = buf + 4;
93
Gilles Peskine449bd832023-01-11 14:50:10 +010094 ret = mbedtls_asn1_write_named_bitstring(&c, buf, &key_usage, 8);
95 if (ret < 3 || ret > 4) {
96 return ret;
97 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +020098
Gilles Peskine449bd832023-01-11 14:50:10 +010099 ret = mbedtls_x509write_csr_set_extension(ctx, MBEDTLS_OID_KEY_USAGE,
100 MBEDTLS_OID_SIZE(MBEDTLS_OID_KEY_USAGE),
101 0, c, (size_t) ret);
102 if (ret != 0) {
103 return ret;
104 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200105
Gilles Peskine449bd832023-01-11 14:50:10 +0100106 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200107}
108
Gilles Peskine449bd832023-01-11 14:50:10 +0100109int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr *ctx,
110 unsigned char ns_cert_type)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200111{
Gilles Peskine449bd832023-01-11 14:50:10 +0100112 unsigned char buf[4] = { 0 };
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200113 unsigned char *c;
Janos Follath865b3eb2019-12-16 11:46:15 +0000114 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200115
116 c = buf + 4;
117
Gilles Peskine449bd832023-01-11 14:50:10 +0100118 ret = mbedtls_asn1_write_named_bitstring(&c, buf, &ns_cert_type, 8);
119 if (ret < 3 || ret > 4) {
120 return ret;
121 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200122
Gilles Peskine449bd832023-01-11 14:50:10 +0100123 ret = mbedtls_x509write_csr_set_extension(ctx, MBEDTLS_OID_NS_CERT_TYPE,
124 MBEDTLS_OID_SIZE(MBEDTLS_OID_NS_CERT_TYPE),
125 0, c, (size_t) ret);
126 if (ret != 0) {
127 return ret;
128 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200129
Gilles Peskine449bd832023-01-11 14:50:10 +0100130 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200131}
132
Gilles Peskine449bd832023-01-11 14:50:10 +0100133static int x509write_csr_der_internal(mbedtls_x509write_csr *ctx,
134 unsigned char *buf,
135 size_t size,
136 unsigned char *sig, size_t sig_size,
137 int (*f_rng)(void *, unsigned char *, size_t),
138 void *p_rng)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200139{
Janos Follath865b3eb2019-12-16 11:46:15 +0000140 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200141 const char *sig_oid;
142 size_t sig_oid_len = 0;
143 unsigned char *c, *c2;
Manuel Pégourié-Gonnard88579842023-03-28 11:20:23 +0200144 unsigned char hash[MBEDTLS_MD_MAX_SIZE];
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200145 size_t pub_len = 0, sig_and_oid_len = 0, sig_len;
146 size_t len = 0;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200147 mbedtls_pk_type_t pk_alg;
Andrzej Kurekd4a65532018-10-31 06:18:39 -0400148#if defined(MBEDTLS_USE_PSA_CRYPTO)
Andrzej Kurekd4a65532018-10-31 06:18:39 -0400149 size_t hash_len;
Manuel Pégourié-Gonnard2d6d9932023-03-28 11:38:08 +0200150 psa_algorithm_t hash_alg = mbedtls_md_psa_alg_from_type(ctx->md_alg);
Andrzej Kurekd4a65532018-10-31 06:18:39 -0400151#endif /* MBEDTLS_USE_PSA_CRYPTO */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200152
Simon Leet40ca54a2020-06-26 21:23:32 +0000153 /* Write the CSR backwards starting from the end of buf */
Doru Gucea2957b352018-12-14 21:08:35 +0200154 c = buf + size;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200155
Gilles Peskine449bd832023-01-11 14:50:10 +0100156 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_x509_write_extensions(&c, buf,
157 ctx->extensions));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200158
Gilles Peskine449bd832023-01-11 14:50:10 +0100159 if (len) {
160 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
161 MBEDTLS_ASN1_CHK_ADD(len,
162 mbedtls_asn1_write_tag(
163 &c, buf,
164 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200165
Gilles Peskine449bd832023-01-11 14:50:10 +0100166 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
167 MBEDTLS_ASN1_CHK_ADD(len,
168 mbedtls_asn1_write_tag(
169 &c, buf,
170 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200171
Gilles Peskine449bd832023-01-11 14:50:10 +0100172 MBEDTLS_ASN1_CHK_ADD(len,
173 mbedtls_asn1_write_oid(
174 &c, buf, MBEDTLS_OID_PKCS9_CSR_EXT_REQ,
175 MBEDTLS_OID_SIZE(MBEDTLS_OID_PKCS9_CSR_EXT_REQ)));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200176
Gilles Peskine449bd832023-01-11 14:50:10 +0100177 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
178 MBEDTLS_ASN1_CHK_ADD(len,
179 mbedtls_asn1_write_tag(
180 &c, buf,
181 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200182 }
183
Gilles Peskine449bd832023-01-11 14:50:10 +0100184 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
185 MBEDTLS_ASN1_CHK_ADD(len,
186 mbedtls_asn1_write_tag(
187 &c, buf,
188 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200189
Gilles Peskine449bd832023-01-11 14:50:10 +0100190 MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_pk_write_pubkey_der(ctx->key,
Dave Rodgmane4a6f5a2023-11-04 12:20:09 +0000191 buf, (size_t) (c - buf)));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200192 c -= pub_len;
193 len += pub_len;
194
195 /*
196 * Subject ::= Name
197 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100198 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_x509_write_names(&c, buf,
199 ctx->subject));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200200
201 /*
202 * Version ::= INTEGER { v1(0), v2(1), v3(2) }
203 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100204 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_int(&c, buf, 0));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200205
Gilles Peskine449bd832023-01-11 14:50:10 +0100206 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
207 MBEDTLS_ASN1_CHK_ADD(len,
208 mbedtls_asn1_write_tag(
209 &c, buf,
210 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200211
212 /*
Simon Leet40ca54a2020-06-26 21:23:32 +0000213 * Sign the written CSR data into the sig buffer
Andrzej Kurekd4a65532018-10-31 06:18:39 -0400214 * Note: hash errors can happen only after an internal error
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200215 */
Andrzej Kurekd4a65532018-10-31 06:18:39 -0400216#if defined(MBEDTLS_USE_PSA_CRYPTO)
Gilles Peskine449bd832023-01-11 14:50:10 +0100217 if (psa_hash_compute(hash_alg,
218 c,
219 len,
220 hash,
221 sizeof(hash),
222 &hash_len) != PSA_SUCCESS) {
223 return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
Andrzej Kurekd4a65532018-10-31 06:18:39 -0400224 }
225#else /* MBEDTLS_USE_PSA_CRYPTO */
Gilles Peskine449bd832023-01-11 14:50:10 +0100226 ret = mbedtls_md(mbedtls_md_info_from_type(ctx->md_alg), c, len, hash);
227 if (ret != 0) {
228 return ret;
229 }
Andrzej Kurekd4a65532018-10-31 06:18:39 -0400230#endif
Gilles Peskine449bd832023-01-11 14:50:10 +0100231 if ((ret = mbedtls_pk_sign(ctx->key, ctx->md_alg, hash, 0,
232 sig, sig_size, &sig_len,
233 f_rng, p_rng)) != 0) {
234 return ret;
Hanno Beckerfc771442017-09-13 08:45:48 +0100235 }
236
Gilles Peskine449bd832023-01-11 14:50:10 +0100237 if (mbedtls_pk_can_do(ctx->key, MBEDTLS_PK_RSA)) {
Hanno Beckerfc771442017-09-13 08:45:48 +0100238 pk_alg = MBEDTLS_PK_RSA;
Gilles Peskine449bd832023-01-11 14:50:10 +0100239 } else if (mbedtls_pk_can_do(ctx->key, MBEDTLS_PK_ECDSA)) {
Hanno Beckerfc771442017-09-13 08:45:48 +0100240 pk_alg = MBEDTLS_PK_ECDSA;
Gilles Peskine449bd832023-01-11 14:50:10 +0100241 } else {
242 return MBEDTLS_ERR_X509_INVALID_ALG;
243 }
Hanno Beckerfc771442017-09-13 08:45:48 +0100244
Gilles Peskine449bd832023-01-11 14:50:10 +0100245 if ((ret = mbedtls_oid_get_oid_by_sig_alg(pk_alg, ctx->md_alg,
246 &sig_oid, &sig_oid_len)) != 0) {
247 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200248 }
249
250 /*
Simon Leet40ca54a2020-06-26 21:23:32 +0000251 * Move the written CSR data to the start of buf to create space for
252 * writing the signature into buf.
253 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100254 memmove(buf, c, len);
Doru Gucea2957b352018-12-14 21:08:35 +0200255
Simon Leet40ca54a2020-06-26 21:23:32 +0000256 /*
257 * Write sig and its OID into buf backwards from the end of buf.
258 * Note: mbedtls_x509_write_sig will check for c2 - ( buf + len ) < sig_len
259 * and return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL if needed.
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200260 */
261 c2 = buf + size;
Gilles Peskine449bd832023-01-11 14:50:10 +0100262 MBEDTLS_ASN1_CHK_ADD(sig_and_oid_len,
263 mbedtls_x509_write_sig(&c2, buf + len, sig_oid, sig_oid_len,
Marek Jansta8bde6492022-11-07 12:38:38 +0100264 sig, sig_len, pk_alg));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200265
Simon Leet40ca54a2020-06-26 21:23:32 +0000266 /*
267 * Compact the space between the CSR data and signature by moving the
268 * CSR data to the start of the signature.
269 */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200270 c2 -= len;
Gilles Peskine449bd832023-01-11 14:50:10 +0100271 memmove(c2, buf, len);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200272
Simon Leet40ca54a2020-06-26 21:23:32 +0000273 /* ASN encode the total size and tag the CSR data with it. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200274 len += sig_and_oid_len;
Gilles Peskine449bd832023-01-11 14:50:10 +0100275 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c2, buf, len));
276 MBEDTLS_ASN1_CHK_ADD(len,
277 mbedtls_asn1_write_tag(
278 &c2, buf,
279 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
Simon Leet40ca54a2020-06-26 21:23:32 +0000280
281 /* Zero the unused bytes at the start of buf */
Dave Rodgmane4a6f5a2023-11-04 12:20:09 +0000282 memset(buf, 0, (size_t) (c2 - buf));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200283
Gilles Peskine449bd832023-01-11 14:50:10 +0100284 return (int) len;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200285}
286
Gilles Peskine449bd832023-01-11 14:50:10 +0100287int mbedtls_x509write_csr_der(mbedtls_x509write_csr *ctx, unsigned char *buf,
288 size_t size,
289 int (*f_rng)(void *, unsigned char *, size_t),
290 void *p_rng)
Doru Gucea2957b352018-12-14 21:08:35 +0200291{
292 int ret;
293 unsigned char *sig;
294
Gilles Peskine449bd832023-01-11 14:50:10 +0100295 if ((sig = mbedtls_calloc(1, MBEDTLS_PK_SIGNATURE_MAX_SIZE)) == NULL) {
296 return MBEDTLS_ERR_X509_ALLOC_FAILED;
Doru Gucea2957b352018-12-14 21:08:35 +0200297 }
298
Gilles Peskine449bd832023-01-11 14:50:10 +0100299 ret = x509write_csr_der_internal(ctx, buf, size,
300 sig, MBEDTLS_PK_SIGNATURE_MAX_SIZE,
301 f_rng, p_rng);
Doru Gucea2957b352018-12-14 21:08:35 +0200302
Gilles Peskine449bd832023-01-11 14:50:10 +0100303 mbedtls_free(sig);
Doru Gucea2957b352018-12-14 21:08:35 +0200304
Gilles Peskine449bd832023-01-11 14:50:10 +0100305 return ret;
Doru Gucea2957b352018-12-14 21:08:35 +0200306}
307
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200308#define PEM_BEGIN_CSR "-----BEGIN CERTIFICATE REQUEST-----\n"
309#define PEM_END_CSR "-----END CERTIFICATE REQUEST-----\n"
310
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200311#if defined(MBEDTLS_PEM_WRITE_C)
Gilles Peskine449bd832023-01-11 14:50:10 +0100312int mbedtls_x509write_csr_pem(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
313 int (*f_rng)(void *, unsigned char *, size_t),
314 void *p_rng)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200315{
Janos Follath865b3eb2019-12-16 11:46:15 +0000316 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200317 size_t olen = 0;
318
Gilles Peskine449bd832023-01-11 14:50:10 +0100319 if ((ret = mbedtls_x509write_csr_der(ctx, buf, size,
320 f_rng, p_rng)) < 0) {
321 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200322 }
323
Gilles Peskine449bd832023-01-11 14:50:10 +0100324 if ((ret = mbedtls_pem_write_buffer(PEM_BEGIN_CSR, PEM_END_CSR,
325 buf + size - ret,
326 ret, buf, size, &olen)) != 0) {
327 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200328 }
329
Gilles Peskine449bd832023-01-11 14:50:10 +0100330 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200331}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332#endif /* MBEDTLS_PEM_WRITE_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200333
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200334#endif /* MBEDTLS_X509_CSR_WRITE_C */