Mbed TLS v3.6.6
Loading...
Searching...
No Matches
pk.h
Go to the documentation of this file.
1
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 */
10
11#ifndef MBEDTLS_PK_H
12#define MBEDTLS_PK_H
14
15#include "mbedtls/build_info.h"
16
17#include "mbedtls/md.h"
18
19#if defined(MBEDTLS_RSA_C)
20#include "mbedtls/rsa.h"
21#endif
22
23#if defined(MBEDTLS_ECP_C)
24#include "mbedtls/ecp.h"
25#endif
26
27#if defined(MBEDTLS_ECDSA_C)
28#include "mbedtls/ecdsa.h"
29#endif
30
31#if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
32#include "psa/crypto.h"
33#endif
34
36#define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
38#define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
40#define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
42#define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
44#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
46#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
48#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
50#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
52#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
54#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
56#define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
58#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
60#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
62#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
64#define MBEDTLS_ERR_PK_BUFFER_TOO_SMALL -0x3880
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
83
109
113/* We need to set MBEDTLS_PK_SIGNATURE_MAX_SIZE to the maximum signature
114 * size among the supported signature types. Do it by starting at 0,
115 * then incrementally increasing to be large enough for each supported
116 * signature mechanism.
117 *
118 * The resulting value can be 0, for example if MBEDTLS_ECDH_C is enabled
119 * (which allows the pk module to be included) but neither MBEDTLS_ECDSA_C
120 * nor MBEDTLS_RSA_C nor any opaque signature mechanism (PSA or RSA_ALT).
121 */
122#define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0
123
124#if (defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT)) && \
125 MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
126/* For RSA, the signature can be as large as the bignum module allows.
127 * For RSA_ALT, the signature size is not necessarily tied to what the
128 * bignum module can do, but in the absence of any specific setting,
129 * we use that (rsa_alt_sign_wrap in library/pk_wrap.h will check). */
130#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
131#define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
132#endif
133
134#if defined(MBEDTLS_ECDSA_C) && \
135 MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_PK_SIGNATURE_MAX_SIZE
136/* For ECDSA, the ecdsa module exports a constant for the maximum
137 * signature size. */
138#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
139#define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN
140#endif
141
142#if defined(MBEDTLS_USE_PSA_CRYPTO)
143#if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
144/* PSA_SIGNATURE_MAX_SIZE is the maximum size of a signature made
145 * through the PSA API in the PSA representation. */
146#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
147#define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE
148#endif
149
150#if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE
151/* The Mbed TLS representation is different for ECDSA signatures:
152 * PSA uses the raw concatenation of r and s,
153 * whereas Mbed TLS uses the ASN.1 representation (SEQUENCE of two INTEGERs).
154 * Add the overhead of ASN.1: up to (1+2) + 2 * (1+2+1) for the
155 * types, lengths (represented by up to 2 bytes), and potential leading
156 * zeros of the INTEGERs and the SEQUENCE. */
157#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
158#define MBEDTLS_PK_SIGNATURE_MAX_SIZE (PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11)
159#endif
160#endif /* defined(MBEDTLS_USE_PSA_CRYPTO) */
161
162/* Internal helper to define which fields in the pk_context structure below
163 * should be used for EC keys: legacy ecp_keypair or the raw (PSA friendly)
164 * format. It should be noted that this only affects how data is stored, not
165 * which functions are used for various operations. The overall picture looks
166 * like this:
167 * - if USE_PSA is not defined and ECP_C is defined then use ecp_keypair data
168 * structure and legacy functions
169 * - if USE_PSA is defined and
170 * - if ECP_C then use ecp_keypair structure, convert data to a PSA friendly
171 * format and use PSA functions
172 * - if !ECP_C then use new raw data and PSA functions directly.
173 *
174 * The main reason for the "intermediate" (USE_PSA + ECP_C) above is that as long
175 * as ECP_C is defined mbedtls_pk_ec() gives the user a read/write access to the
176 * ecp_keypair structure inside the pk_context so they can modify it using
177 * ECP functions which are not under PK module's control.
178 */
179#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) && \
180 !defined(MBEDTLS_ECP_C)
181#define MBEDTLS_PK_USE_PSA_EC_DATA
182#endif
183
193
202
204#define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
205
214
215#define MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN \
216 PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
217
220typedef struct mbedtls_pk_context {
224 void *MBEDTLS_PRIVATE(pk_ctx);
225
226 /* The following field is used to store the ID of a private key in the
227 * following cases:
228 * - opaque key when MBEDTLS_USE_PSA_CRYPTO is defined
229 * - normal key when MBEDTLS_PK_USE_PSA_EC_DATA is defined. In this case:
230 * - the pk_ctx above is not not used to store the private key anymore.
231 * Actually that field not populated at all in this case because also
232 * the public key will be stored in raw format as explained below
233 * - this ID is used for all private key operations (ex: sign, check
234 * key pair, key write, etc) using PSA functions
235 *
236 * Note: this private key storing solution only affects EC keys, not the
237 * other ones. The latters still use the pk_ctx to store their own
238 * context. */
239#if defined(MBEDTLS_USE_PSA_CRYPTO)
241#endif /* MBEDTLS_USE_PSA_CRYPTO */
242 /* The following fields are meant for storing the public key in raw format
243 * which is handy for:
244 * - easily importing it into the PSA context
245 * - reducing the ECP module dependencies in the PK one.
246 *
247 * When MBEDTLS_PK_USE_PSA_EC_DATA is enabled:
248 * - the pk_ctx above is not used anymore for storing the public key
249 * inside the ecp_keypair structure
250 * - the following fields are used for all public key operations: signature
251 * verify, key pair check and key write.
252 * - For a key pair, priv_id contains the private key. For a public key,
253 * priv_id is null.
254 * Of course, when MBEDTLS_PK_USE_PSA_EC_DATA is not enabled, the legacy
255 * ecp_keypair structure is used for storing the public key and performing
256 * all the operations.
257 *
258 * Note: This new public key storing solution only works for EC keys, not
259 * other ones. The latters still use pk_ctx to store their own
260 * context.
261 */
262#if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
264 size_t MBEDTLS_PRIVATE(pub_raw_len);
266 size_t MBEDTLS_PRIVATE(ec_bits);
267#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
269
270#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
274typedef struct {
275 const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info);
276 void *MBEDTLS_PRIVATE(rs_ctx);
278#else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
279/* Now we can declare functions that take a pointer to that */
281#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
282
283#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
287typedef int (*mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, size_t *olen,
288 const unsigned char *input, unsigned char *output,
289 size_t output_max_len);
290typedef int (*mbedtls_pk_rsa_alt_sign_func)(void *ctx,
291 mbedtls_f_rng_t *f_rng,
292 void *p_rng,
293 mbedtls_md_type_t md_alg, unsigned int hashlen,
294 const unsigned char *hash, unsigned char *sig);
295typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(void *ctx);
296#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
297
306
314
327
328#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
335void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx);
336
343void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx);
344#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
345
362
363#if defined(MBEDTLS_USE_PSA_CRYPTO)
400int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx,
401 const mbedtls_svc_key_id_t key);
402#endif /* MBEDTLS_USE_PSA_CRYPTO */
403
404#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
424#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
425
434
442static inline size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
443{
444 return (mbedtls_pk_get_bitlen(ctx) + 7) / 8;
445}
446
460
461#if defined(MBEDTLS_USE_PSA_CRYPTO)
489int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg,
490 psa_key_usage_t usage);
491#endif /* MBEDTLS_USE_PSA_CRYPTO */
492
493#if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
604 psa_key_usage_t usage,
605 psa_key_attributes_t *attributes);
606
651 const psa_key_attributes_t *attributes,
652 mbedtls_svc_key_id_t *key_id);
653
689
722#endif /* MBEDTLS_PSA_CRYPTO_CLIENT */
723
755 const unsigned char *hash, size_t hash_len,
756 const unsigned char *sig, size_t sig_len);
757
779 mbedtls_md_type_t md_alg,
780 const unsigned char *hash, size_t hash_len,
781 const unsigned char *sig, size_t sig_len,
782 mbedtls_pk_restart_ctx *rs_ctx);
783
815int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options,
817 const unsigned char *hash, size_t hash_len,
818 const unsigned char *sig, size_t sig_len);
819
853 const unsigned char *hash, size_t hash_len,
854 unsigned char *sig, size_t sig_size, size_t *sig_len,
855 mbedtls_f_rng_t *f_rng, void *p_rng);
856
888 mbedtls_md_type_t md_alg,
889 const unsigned char *hash, size_t hash_len,
890 unsigned char *sig, size_t sig_size, size_t *sig_len,
891 mbedtls_f_rng_t *f_rng,
892 void *p_rng);
893
924 mbedtls_md_type_t md_alg,
925 const unsigned char *hash, size_t hash_len,
926 unsigned char *sig, size_t sig_size, size_t *sig_len,
927 mbedtls_f_rng_t *f_rng, void *p_rng,
928 mbedtls_pk_restart_ctx *rs_ctx);
929
951 const unsigned char *input, size_t ilen,
952 unsigned char *output, size_t *olen, size_t osize,
953 mbedtls_f_rng_t *f_rng, void *p_rng);
954
977 const unsigned char *input, size_t ilen,
978 unsigned char *output, size_t *olen, size_t osize,
979 mbedtls_f_rng_t *f_rng, void *p_rng);
980
996 const mbedtls_pk_context *prv,
997 mbedtls_f_rng_t *f_rng,
998 void *p_rng);
999
1009
1018
1028
1029#if defined(MBEDTLS_RSA_C)
1041{
1042 switch (mbedtls_pk_get_type(&pk)) {
1043 case MBEDTLS_PK_RSA:
1044 return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx);
1045 default:
1046 return NULL;
1047 }
1048}
1049#endif /* MBEDTLS_RSA_C */
1050
1051#if defined(MBEDTLS_ECP_C)
1064{
1065 switch (mbedtls_pk_get_type(&pk)) {
1066 case MBEDTLS_PK_ECKEY:
1068 case MBEDTLS_PK_ECDSA:
1069 return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
1070 default:
1071 return NULL;
1072 }
1073}
1074#endif /* MBEDTLS_ECP_C */
1075
1076#if defined(MBEDTLS_PK_PARSE_C)
1113 const unsigned char *key, size_t keylen,
1114 const unsigned char *pwd, size_t pwdlen,
1115 mbedtls_f_rng_t *f_rng, void *p_rng);
1116
1147 const unsigned char *key, size_t keylen);
1148
1149#if defined(MBEDTLS_FS_IO)
1178 const char *path, const char *password,
1179 mbedtls_f_rng_t *f_rng, void *p_rng);
1180
1199#endif /* MBEDTLS_FS_IO */
1200#endif /* MBEDTLS_PK_PARSE_C */
1201
1202#if defined(MBEDTLS_PK_WRITE_C)
1216int mbedtls_pk_write_key_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1217
1231int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1232
1233#if defined(MBEDTLS_PEM_WRITE_C)
1244int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1245
1256int mbedtls_pk_write_key_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1257#endif /* MBEDTLS_PEM_WRITE_C */
1258#endif /* MBEDTLS_PK_WRITE_C */
1259
1260/*
1261 * WARNING: Low-level functions. You probably do not want to use these unless
1262 * you are certain you do ;)
1263 */
1264
1265#if defined(MBEDTLS_PK_PARSE_C)
1276int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end,
1277 mbedtls_pk_context *pk);
1278#endif /* MBEDTLS_PK_PARSE_C */
1279
1280#if defined(MBEDTLS_PK_WRITE_C)
1291int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start,
1292 const mbedtls_pk_context *key);
1293#endif /* MBEDTLS_PK_WRITE_C */
1294
1295#ifdef __cplusplus
1296}
1297#endif
1298
1299#endif /* MBEDTLS_PK_H */
Platform Security Architecture cryptography module.
This file contains ECDSA definitions and functions.
This file provides an API for Elliptic Curves over GF(P) (ECP).
struct psa_key_attributes_s psa_key_attributes_t
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
uint8_t psa_ecc_family_t
psa_key_id_t mbedtls_svc_key_id_t
uint32_t psa_key_usage_t
Encoding of permitted usage on a key.
Build-time configuration info.
This file contains the generic functions for message-digest (hashing) and HMAC.
mbedtls_md_type_t
Supported message digests.
Definition md.h:47
int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size)
Write a public key to a PEM string.
int mbedtls_pk_encrypt(mbedtls_pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, mbedtls_f_rng_t *f_rng, void *p_rng)
Encrypt message (including padding if relevant).
int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items)
Export debug information.
static size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
Get the length in bytes of the underlying key.
Definition pk.h:442
int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, unsigned char *sig, size_t sig_size, size_t *sig_len, mbedtls_f_rng_t *f_rng, void *p_rng, mbedtls_pk_restart_ctx *rs_ctx)
Restartable version of mbedtls_pk_sign().
int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end, mbedtls_pk_context *pk)
Parse a SubjectPublicKeyInfo DER structure.
int mbedtls_pk_copy_public_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk)
Create a PK context for the public key of a PSA key.
int mbedtls_pk_write_key_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size)
Write a private key to a PKCS#1 or SEC1 DER structure Note: data is written at the end of the buffer!...
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.
int(* mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Types for RSA-alt abstraction.
Definition pk.h:287
mbedtls_pk_type_t
Public key types.
Definition pk.h:73
@ MBEDTLS_PK_NONE
Definition pk.h:74
@ MBEDTLS_PK_OPAQUE
Definition pk.h:81
@ MBEDTLS_PK_ECDSA
Definition pk.h:78
@ MBEDTLS_PK_RSASSA_PSS
Definition pk.h:80
@ MBEDTLS_PK_RSA_ALT
Definition pk.h:79
@ MBEDTLS_PK_RSA
Definition pk.h:75
@ MBEDTLS_PK_ECKEY_DH
Definition pk.h:77
@ MBEDTLS_PK_ECKEY
Definition pk.h:76
int mbedtls_pk_decrypt(mbedtls_pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, mbedtls_f_rng_t *f_rng, void *p_rng)
Decrypt message (including padding if relevant).
size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx)
Get the size in bits of the underlying key.
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_size, size_t *sig_len, mbedtls_f_rng_t *f_rng, void *p_rng)
Make signature, including padding if relevant.
struct mbedtls_pk_info_t mbedtls_pk_info_t
Public key information and operations.
Definition pk.h:213
static mbedtls_rsa_context * mbedtls_pk_rsa(const mbedtls_pk_context pk)
Definition pk.h:1040
int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size)
Write a public key to a SubjectPublicKeyInfo DER structure Note: data is written at the end of the bu...
int(* mbedtls_pk_rsa_alt_sign_func)(void *ctx, mbedtls_f_rng_t *f_rng, void *p_rng, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Definition pk.h:290
int mbedtls_pk_get_psa_attributes(const mbedtls_pk_context *pk, psa_key_usage_t usage, psa_key_attributes_t *attributes)
Determine valid PSA attributes that can be used to import a key into PSA.
static mbedtls_ecp_keypair * mbedtls_pk_ec(const mbedtls_pk_context pk)
Definition pk.h:1063
int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info)
Initialize a PK context with the information given and allocates the type-specific PK subcontext.
int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv, mbedtls_f_rng_t *f_rng, void *p_rng)
Check if a public-private pair of keys matches.
int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options, mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature, with options. (Includes verification of the padding depending on type....
mbedtls_pk_debug_type
Types for interfacing with the debug module.
Definition pk.h:187
@ MBEDTLS_PK_DEBUG_MPI
Definition pk.h:189
@ MBEDTLS_PK_DEBUG_ECP
Definition pk.h:190
@ MBEDTLS_PK_DEBUG_NONE
Definition pk.h:188
@ MBEDTLS_PK_DEBUG_PSA_EC
Definition pk.h:191
void mbedtls_pk_init(mbedtls_pk_context *ctx)
Initialize a mbedtls_pk_context (as NONE).
const mbedtls_pk_info_t * mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type)
Return information associated with the given PK type.
int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len, mbedtls_pk_restart_ctx *rs_ctx)
Restartable version of mbedtls_pk_verify().
int mbedtls_pk_sign_ext(mbedtls_pk_type_t pk_type, mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, unsigned char *sig, size_t sig_size, size_t *sig_len, mbedtls_f_rng_t *f_rng, void *p_rng)
Make signature given a signature type.
mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
Get the key type.
int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key, mbedtls_pk_rsa_alt_decrypt_func decrypt_func, mbedtls_pk_rsa_alt_sign_func sign_func, mbedtls_pk_rsa_alt_key_len_func key_len_func)
Initialize an RSA-alt context.
int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk)
Create a PK context starting from a key stored in PSA. This key:
#define MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN
Definition pk.h:215
int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature (including padding if relevant).
size_t(* mbedtls_pk_rsa_alt_key_len_func)(void *ctx)
Definition pk.h:295
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start, const mbedtls_pk_context *key)
Write a subjectPublicKey to ASN.1 data Note: function works backwards in data buffer.
int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx, const char *path, const char *password, mbedtls_f_rng_t *f_rng, void *p_rng)
Load and parse a private key.
int mbedtls_pk_parse_key(mbedtls_pk_context *ctx, const unsigned char *key, size_t keylen, const unsigned char *pwd, size_t pwdlen, mbedtls_f_rng_t *f_rng, void *p_rng)
Parse a private key in PEM or DER format.
int mbedtls_pk_import_into_psa(const mbedtls_pk_context *pk, const psa_key_attributes_t *attributes, mbedtls_svc_key_id_t *key_id)
Import a key into the PSA key store.
void mbedtls_pk_restart_ctx
Definition pk.h:280
int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx, const unsigned char *key, size_t keylen)
Parse a public key in PEM or DER format.
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path)
Load and parse a public key.
int mbedtls_pk_write_key_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size)
Write a private key to a PKCS#1 or SEC1 PEM string.
int mbedtls_f_rng_t(void *p_rng, unsigned char *output, size_t output_size)
The type of custom random generator (RNG) callbacks.
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
This file provides an API for the RSA public-key cryptosystem.
The ECP key-pair structure.
Definition ecp.h:428
Public key container.
Definition pk.h:220
Item to send to the debug module.
Definition pk.h:197
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext().
Definition pk.h:88
mbedtls_md_type_t mgf1_hash_id
Definition pk.h:97
The RSA context structure.
Definition rsa.h:85