Mbed TLS v3.5.0
pk.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright The Mbed TLS Contributors
8  * SPDX-License-Identifier: Apache-2.0
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License"); you may
11  * not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #ifndef MBEDTLS_PK_H
24 #define MBEDTLS_PK_H
25 #include "mbedtls/private_access.h"
26 
27 #include "mbedtls/build_info.h"
28 
29 #include "mbedtls/md.h"
30 
31 #if defined(MBEDTLS_RSA_C)
32 #include "mbedtls/rsa.h"
33 #endif
34 
35 #if defined(MBEDTLS_ECP_C)
36 #include "mbedtls/ecp.h"
37 #endif
38 
39 #if defined(MBEDTLS_ECDSA_C)
40 #include "mbedtls/ecdsa.h"
41 #endif
42 
43 #if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_PSA_CRYPTO_C)
44 #include "psa/crypto.h"
45 #endif
46 
48 #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
50 #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
52 #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
54 #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
56 #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
58 #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
60 #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
62 #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
64 #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
66 #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
68 #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
70 #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
72 #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
74 #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
76 #define MBEDTLS_ERR_PK_BUFFER_TOO_SMALL -0x3880
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
85 typedef enum {
95 
110 
119 
121 
125 /* We need to set MBEDTLS_PK_SIGNATURE_MAX_SIZE to the maximum signature
126  * size among the supported signature types. Do it by starting at 0,
127  * then incrementally increasing to be large enough for each supported
128  * signature mechanism.
129  *
130  * The resulting value can be 0, for example if MBEDTLS_ECDH_C is enabled
131  * (which allows the pk module to be included) but neither MBEDTLS_ECDSA_C
132  * nor MBEDTLS_RSA_C nor any opaque signature mechanism (PSA or RSA_ALT).
133  */
134 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0
135 
136 #if (defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT)) && \
137  MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
138 /* For RSA, the signature can be as large as the bignum module allows.
139  * For RSA_ALT, the signature size is not necessarily tied to what the
140  * bignum module can do, but in the absence of any specific setting,
141  * we use that (rsa_alt_sign_wrap in library/pk_wrap.h will check). */
142 #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
143 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
144 #endif
145 
146 #if defined(MBEDTLS_ECDSA_C) && \
147  MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_PK_SIGNATURE_MAX_SIZE
148 /* For ECDSA, the ecdsa module exports a constant for the maximum
149  * signature size. */
150 #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
151 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN
152 #endif
153 
154 #if defined(MBEDTLS_USE_PSA_CRYPTO)
155 #if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
156 /* PSA_SIGNATURE_MAX_SIZE is the maximum size of a signature made
157  * through the PSA API in the PSA representation. */
158 #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
159 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE
160 #endif
161 
162 #if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE
163 /* The Mbed TLS representation is different for ECDSA signatures:
164  * PSA uses the raw concatenation of r and s,
165  * whereas Mbed TLS uses the ASN.1 representation (SEQUENCE of two INTEGERs).
166  * Add the overhead of ASN.1: up to (1+2) + 2 * (1+2+1) for the
167  * types, lengths (represented by up to 2 bytes), and potential leading
168  * zeros of the INTEGERs and the SEQUENCE. */
169 #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
170 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE (PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11)
171 #endif
172 #endif /* defined(MBEDTLS_USE_PSA_CRYPTO) */
173 
174 /* Internal helper to define which fields in the pk_context structure below
175  * should be used for EC keys: legacy ecp_keypair or the raw (PSA friendly)
176  * format. It should be noted that this only affects how data is stored, not
177  * which functions are used for various operations. The overall picture looks
178  * like this:
179  * - if USE_PSA is not defined and ECP_C is defined then use ecp_keypair data
180  * structure and legacy functions
181  * - if USE_PSA is defined and
182  * - if ECP_C then use ecp_keypair structure, convert data to a PSA friendly
183  * format and use PSA functions
184  * - if !ECP_C then use new raw data and PSA functions directly.
185  *
186  * The main reason for the "intermediate" (USE_PSA + ECP_C) above is that as long
187  * as ECP_C is defined mbedtls_pk_ec() gives the user a read/write access to the
188  * ecp_keypair structure inside the pk_context so they can modify it using
189  * ECP functions which are not under PK module's control.
190  */
191 #if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) && \
192  !defined(MBEDTLS_ECP_C)
193 #define MBEDTLS_PK_USE_PSA_EC_DATA
194 #endif
195 
196 /* Helper symbol to state that the PK module has support for EC keys. This
197  * can either be provided through the legacy ECP solution or through the
198  * PSA friendly MBEDTLS_PK_USE_PSA_EC_DATA. */
199 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA) || defined(MBEDTLS_ECP_C)
200 #define MBEDTLS_PK_HAVE_ECC_KEYS
201 #endif /* MBEDTLS_PK_USE_PSA_EC_DATA || MBEDTLS_ECP_C */
202 
206 typedef enum {
212 
216 typedef struct mbedtls_pk_debug_item {
218  const char *MBEDTLS_PRIVATE(name);
219  void *MBEDTLS_PRIVATE(value);
221 
223 #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
224 
232 typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;
233 
234 #define MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN \
235  PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
239 typedef struct mbedtls_pk_context {
241  void *MBEDTLS_PRIVATE(pk_ctx);
242  /* The following field is used to store the ID of a private key in the
243  * following cases:
244  * - opaque key when MBEDTLS_PSA_CRYPTO_C is defined
245  * - normal key when MBEDTLS_PK_USE_PSA_EC_DATA is defined. In this case:
246  * - the pk_ctx above is not not used to store the private key anymore.
247  * Actually that field not populated at all in this case because also
248  * the public key will be stored in raw format as explained below
249  * - this ID is used for all private key operations (ex: sign, check
250  * key pair, key write, etc) using PSA functions
251  *
252  * Note: this private key storing solution only affects EC keys, not the
253  * other ones. The latters still use the pk_ctx to store their own
254  * context.
255  *
256  * Note: this priv_id is guarded by MBEDTLS_PSA_CRYPTO_C and not by
257  * MBEDTLS_PK_USE_PSA_EC_DATA (as the public counterpart below) because,
258  * when working with opaque keys, it can be used also in
259  * mbedtls_pk_sign_ext for RSA keys. */
260 #if defined(MBEDTLS_PSA_CRYPTO_C)
262 #endif /* MBEDTLS_PSA_CRYPTO_C */
263  /* The following fields are meant for storing the public key in raw format
264  * which is handy for:
265  * - easily importing it into the PSA context
266  * - reducing the ECP module dependencies in the PK one.
267  *
268  * When MBEDTLS_PK_USE_PSA_EC_DATA is enabled:
269  * - the pk_ctx above is not used anymore for storing the public key
270  * inside the ecp_keypair structure
271  * - the following fields are used for all public key operations: signature
272  * verify, key pair check and key write.
273  * Of course, when MBEDTLS_PK_USE_PSA_EC_DATA is not enabled, the legacy
274  * ecp_keypair structure is used for storing the public key and performing
275  * all the operations.
276  *
277  * Note: This new public key storing solution only works for EC keys, not
278  * other ones. The latters still use pk_ctx to store their own
279  * context.
280  */
281 #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
283  size_t MBEDTLS_PRIVATE(pub_raw_len);
284  psa_ecc_family_t MBEDTLS_PRIVATE(ec_family);
285  size_t MBEDTLS_PRIVATE(ec_bits);
286 #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
288 
289 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
293 typedef struct {
294  const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info);
295  void *MBEDTLS_PRIVATE(rs_ctx);
297 #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
298 /* Now we can declare functions that take a pointer to that */
300 #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
301 
302 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
306 typedef int (*mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, size_t *olen,
307  const unsigned char *input, unsigned char *output,
308  size_t output_max_len);
309 typedef int (*mbedtls_pk_rsa_alt_sign_func)(void *ctx,
310  int (*f_rng)(void *, unsigned char *, size_t),
311  void *p_rng,
312  mbedtls_md_type_t md_alg, unsigned int hashlen,
313  const unsigned char *hash, unsigned char *sig);
314 typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(void *ctx);
315 #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
316 
325 
333 
346 
347 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
354 void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx);
355 
362 void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx);
363 #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
364 
381 
382 #if defined(MBEDTLS_USE_PSA_CRYPTO)
411 int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx,
412  const mbedtls_svc_key_id_t key);
413 #endif /* MBEDTLS_USE_PSA_CRYPTO */
414 
415 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
432  mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
434  mbedtls_pk_rsa_alt_key_len_func key_len_func);
435 #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
436 
445 
453 static inline size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
454 {
455  return (mbedtls_pk_get_bitlen(ctx) + 7) / 8;
456 }
457 
471 
472 #if defined(MBEDTLS_USE_PSA_CRYPTO)
500 int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg,
501  psa_key_usage_t usage);
502 #endif /* MBEDTLS_USE_PSA_CRYPTO */
503 
532  const unsigned char *hash, size_t hash_len,
533  const unsigned char *sig, size_t sig_len);
534 
556  mbedtls_md_type_t md_alg,
557  const unsigned char *hash, size_t hash_len,
558  const unsigned char *sig, size_t sig_len,
559  mbedtls_pk_restart_ctx *rs_ctx);
560 
592 int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options,
594  const unsigned char *hash, size_t hash_len,
595  const unsigned char *sig, size_t sig_len);
596 
626  const unsigned char *hash, size_t hash_len,
627  unsigned char *sig, size_t sig_size, size_t *sig_len,
628  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
629 
630 #if defined(MBEDTLS_PSA_CRYPTO_C)
661  mbedtls_pk_context *ctx,
662  mbedtls_md_type_t md_alg,
663  const unsigned char *hash, size_t hash_len,
664  unsigned char *sig, size_t sig_size, size_t *sig_len,
665  int (*f_rng)(void *, unsigned char *, size_t),
666  void *p_rng);
667 #endif /* MBEDTLS_PSA_CRYPTO_C */
668 
699  mbedtls_md_type_t md_alg,
700  const unsigned char *hash, size_t hash_len,
701  unsigned char *sig, size_t sig_size, size_t *sig_len,
702  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
703  mbedtls_pk_restart_ctx *rs_ctx);
704 
723  const unsigned char *input, size_t ilen,
724  unsigned char *output, size_t *olen, size_t osize,
725  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
726 
746  const unsigned char *input, size_t ilen,
747  unsigned char *output, size_t *olen, size_t osize,
748  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
749 
765  const mbedtls_pk_context *prv,
766  int (*f_rng)(void *, unsigned char *, size_t),
767  void *p_rng);
768 
778 
786 const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx);
787 
797 
798 #if defined(MBEDTLS_RSA_C)
810 {
811  switch (mbedtls_pk_get_type(&pk)) {
812  case MBEDTLS_PK_RSA:
813  return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx);
814  default:
815  return NULL;
816  }
817 }
818 #endif /* MBEDTLS_RSA_C */
819 
820 #if defined(MBEDTLS_ECP_C)
833 {
834  switch (mbedtls_pk_get_type(&pk)) {
835  case MBEDTLS_PK_ECKEY:
836  case MBEDTLS_PK_ECKEY_DH:
837  case MBEDTLS_PK_ECDSA:
838  return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
839  default:
840  return NULL;
841  }
842 }
843 #endif /* MBEDTLS_ECP_C */
844 
845 #if defined(MBEDTLS_PK_PARSE_C)
882  const unsigned char *key, size_t keylen,
883  const unsigned char *pwd, size_t pwdlen,
884  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
885 
916  const unsigned char *key, size_t keylen);
917 
918 #if defined(MBEDTLS_FS_IO)
947  const char *path, const char *password,
948  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
949 
968 #endif /* MBEDTLS_FS_IO */
969 #endif /* MBEDTLS_PK_PARSE_C */
970 
971 #if defined(MBEDTLS_PK_WRITE_C)
985 int mbedtls_pk_write_key_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
986 
1000 int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1001 
1002 #if defined(MBEDTLS_PEM_WRITE_C)
1013 int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1014 
1025 int mbedtls_pk_write_key_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1026 #endif /* MBEDTLS_PEM_WRITE_C */
1027 #endif /* MBEDTLS_PK_WRITE_C */
1028 
1029 /*
1030  * WARNING: Low-level functions. You probably do not want to use these unless
1031  * you are certain you do ;)
1032  */
1033 
1034 #if defined(MBEDTLS_PK_PARSE_C)
1045 int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end,
1046  mbedtls_pk_context *pk);
1047 #endif /* MBEDTLS_PK_PARSE_C */
1048 
1049 #if defined(MBEDTLS_PK_WRITE_C)
1060 int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start,
1061  const mbedtls_pk_context *key);
1062 #endif /* MBEDTLS_PK_WRITE_C */
1063 
1064 /*
1065  * Internal module functions. You probably do not want to use these unless you
1066  * know you do.
1067  */
1068 #if defined(MBEDTLS_FS_IO)
1069 int mbedtls_pk_load_file(const char *path, unsigned char **buf, size_t *n);
1070 #endif
1071 
1072 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1092 int mbedtls_pk_wrap_as_opaque(mbedtls_pk_context *pk,
1093  mbedtls_svc_key_id_t *key,
1094  psa_algorithm_t alg,
1095  psa_key_usage_t usage,
1096  psa_algorithm_t alg2);
1097 #endif /* MBEDTLS_USE_PSA_CRYPTO */
1098 
1099 #ifdef __cplusplus
1100 }
1101 #endif
1102 
1103 #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).
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
Definition: crypto_types.h:139
uint8_t psa_ecc_family_t
Definition: crypto_types.h:102
psa_key_id_t mbedtls_svc_key_id_t
Definition: crypto_types.h:297
uint32_t psa_key_usage_t
Encoding of permitted usage on a key.
Definition: crypto_types.h:328
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:173
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_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_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:453
int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Check if a public-private pair of keys matches.
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end, mbedtls_pk_context *pk)
Parse a SubjectPublicKeyInfo DER structure.
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_sign_func)(void *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Definition: pk.h:309
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:306
mbedtls_pk_type_t
Public key types.
Definition: pk.h:85
@ MBEDTLS_PK_NONE
Definition: pk.h:86
@ MBEDTLS_PK_OPAQUE
Definition: pk.h:93
@ MBEDTLS_PK_ECDSA
Definition: pk.h:90
@ MBEDTLS_PK_RSASSA_PSS
Definition: pk.h:92
@ MBEDTLS_PK_RSA_ALT
Definition: pk.h:91
@ MBEDTLS_PK_RSA
Definition: pk.h:87
@ MBEDTLS_PK_ECKEY_DH
Definition: pk.h:89
@ MBEDTLS_PK_ECKEY
Definition: pk.h:88
int mbedtls_pk_decrypt(mbedtls_pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int(*f_rng)(void *, unsigned char *, size_t), 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.
static mbedtls_ecp_keypair * mbedtls_pk_ec(const mbedtls_pk_context pk)
Definition: pk.h:832
struct mbedtls_pk_info_t mbedtls_pk_info_t
Public key information and operations.
Definition: pk.h:232
int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx, const char *path, const char *password, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Load and parse a private key.
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_load_file(const char *path, unsigned char **buf, size_t *n)
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_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....
struct mbedtls_pk_context mbedtls_pk_context
Public key container.
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, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Make signature given a signature type.
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, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_pk_restart_ctx *rs_ctx)
Restartable version of mbedtls_pk_sign()
struct mbedtls_pk_rsassa_pss_options mbedtls_pk_rsassa_pss_options
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext()
mbedtls_pk_debug_type
Types for interfacing with the debug module.
Definition: pk.h:206
@ MBEDTLS_PK_DEBUG_MPI
Definition: pk.h:208
@ MBEDTLS_PK_DEBUG_ECP
Definition: pk.h:209
@ MBEDTLS_PK_DEBUG_NONE
Definition: pk.h:207
@ MBEDTLS_PK_DEBUG_PSA_EC
Definition: pk.h:210
void mbedtls_pk_init(mbedtls_pk_context *ctx)
Initialize a mbedtls_pk_context (as NONE).
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_parse_key(mbedtls_pk_context *ctx, const unsigned char *key, size_t keylen, const unsigned char *pwd, size_t pwdlen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Parse a private key in PEM or DER format.
static mbedtls_rsa_context * mbedtls_pk_rsa(const mbedtls_pk_context pk)
Definition: pk.h:809
mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
Get the key type.
struct mbedtls_pk_debug_item mbedtls_pk_debug_item
Item to send to the debug module.
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.
#define MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN
Definition: pk.h:234
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:314
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.
void mbedtls_pk_restart_ctx
Definition: pk.h:299
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.
int mbedtls_pk_encrypt(mbedtls_pk_context *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Encrypt message (including padding if relevant).
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, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Make signature, including padding if relevant.
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.
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:439
Public key container.
Definition: pk.h:239
Item to send to the debug module.
Definition: pk.h:216
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext()
Definition: pk.h:100
mbedtls_md_type_t mgf1_hash_id
Definition: pk.h:109
The RSA context structure.
Definition: rsa.h:97