mbed TLS v3.4.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)
44 #include "psa/crypto.h"
45 #endif
46 
48 #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
49 
50 #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
51 
52 #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
53 
54 #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
55 
56 #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
57 
58 #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
59 
60 #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
61 
62 #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
63 
64 #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
65 
66 #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
67 
68 #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
69 
70 #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
71 
72 #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
73 
74 #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
75 
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 
180 #if !defined(MBEDTLS_USE_PSA_CRYPTO)
181 #if defined(MBEDTLS_ECDSA_C)
182 #define MBEDTLS_PK_CAN_ECDSA_SIGN
183 #define MBEDTLS_PK_CAN_ECDSA_VERIFY
184 #endif
185 #else /* MBEDTLS_USE_PSA_CRYPTO */
186 #if defined(PSA_WANT_ALG_ECDSA)
187 #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR)
188 #define MBEDTLS_PK_CAN_ECDSA_SIGN
189 #endif
190 #if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY)
191 #define MBEDTLS_PK_CAN_ECDSA_VERIFY
192 #endif
193 #endif /* PSA_WANT_ALG_ECDSA */
194 #endif /* MBEDTLS_USE_PSA_CRYPTO */
195 
196 #if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) || defined(MBEDTLS_PK_CAN_ECDSA_SIGN)
197 #define MBEDTLS_PK_CAN_ECDSA_SOME
198 #endif
199 
203 typedef enum {
208 
212 typedef struct mbedtls_pk_debug_item {
214  const char *MBEDTLS_PRIVATE(name);
215  void *MBEDTLS_PRIVATE(value);
217 
219 #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
220 
229 
233 typedef struct mbedtls_pk_context {
235  void *MBEDTLS_PRIVATE(pk_ctx);
237 
238 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
239 
242 typedef struct {
243  const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info);
244  void *MBEDTLS_PRIVATE(rs_ctx);
246 #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
247 /* Now we can declare functions that take a pointer to that */
249 #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
250 
251 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
252 
255 typedef int (*mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, size_t *olen,
256  const unsigned char *input, unsigned char *output,
257  size_t output_max_len);
258 typedef int (*mbedtls_pk_rsa_alt_sign_func)(void *ctx,
259  int (*f_rng)(void *, unsigned char *, size_t),
260  void *p_rng,
261  mbedtls_md_type_t md_alg, unsigned int hashlen,
262  const unsigned char *hash, unsigned char *sig);
263 typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(void *ctx);
264 #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
265 
274 
282 
295 
296 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
297 
303 void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx);
304 
311 void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx);
312 #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
313 
330 
331 #if defined(MBEDTLS_USE_PSA_CRYPTO)
332 
360 int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx,
361  const mbedtls_svc_key_id_t key);
362 #endif /* MBEDTLS_USE_PSA_CRYPTO */
363 
364 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
365 
380 int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key,
381  mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
383  mbedtls_pk_rsa_alt_key_len_func key_len_func);
384 #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
385 
393 size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx);
394 
402 static inline size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
403 {
404  return (mbedtls_pk_get_bitlen(ctx) + 7) / 8;
405 }
406 
420 
421 #if defined(MBEDTLS_USE_PSA_CRYPTO)
422 
449 int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg,
450  psa_key_usage_t usage);
451 #endif /* MBEDTLS_USE_PSA_CRYPTO */
452 
481  const unsigned char *hash, size_t hash_len,
482  const unsigned char *sig, size_t sig_len);
483 
505  mbedtls_md_type_t md_alg,
506  const unsigned char *hash, size_t hash_len,
507  const unsigned char *sig, size_t sig_len,
508  mbedtls_pk_restart_ctx *rs_ctx);
509 
541 int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options,
543  const unsigned char *hash, size_t hash_len,
544  const unsigned char *sig, size_t sig_len);
545 
575  const unsigned char *hash, size_t hash_len,
576  unsigned char *sig, size_t sig_size, size_t *sig_len,
577  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
578 
579 #if defined(MBEDTLS_PSA_CRYPTO_C)
580 
610  mbedtls_pk_context *ctx,
611  mbedtls_md_type_t md_alg,
612  const unsigned char *hash, size_t hash_len,
613  unsigned char *sig, size_t sig_size, size_t *sig_len,
614  int (*f_rng)(void *, unsigned char *, size_t),
615  void *p_rng);
616 #endif /* MBEDTLS_PSA_CRYPTO_C */
617 
648  mbedtls_md_type_t md_alg,
649  const unsigned char *hash, size_t hash_len,
650  unsigned char *sig, size_t sig_size, size_t *sig_len,
651  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
652  mbedtls_pk_restart_ctx *rs_ctx);
653 
672  const unsigned char *input, size_t ilen,
673  unsigned char *output, size_t *olen, size_t osize,
674  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
675 
695  const unsigned char *input, size_t ilen,
696  unsigned char *output, size_t *olen, size_t osize,
697  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
698 
714  const mbedtls_pk_context *prv,
715  int (*f_rng)(void *, unsigned char *, size_t),
716  void *p_rng);
717 
727 
735 const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx);
736 
746 
747 #if defined(MBEDTLS_RSA_C)
748 
759 {
760  switch (mbedtls_pk_get_type(&pk)) {
761  case MBEDTLS_PK_RSA:
762  return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx);
763  default:
764  return NULL;
765  }
766 }
767 #endif /* MBEDTLS_RSA_C */
768 
769 #if defined(MBEDTLS_ECP_C)
770 
782 {
783  switch (mbedtls_pk_get_type(&pk)) {
784  case MBEDTLS_PK_ECKEY:
785  case MBEDTLS_PK_ECKEY_DH:
786  case MBEDTLS_PK_ECDSA:
787  return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
788  default:
789  return NULL;
790  }
791 }
792 #endif /* MBEDTLS_ECP_C */
793 
794 #if defined(MBEDTLS_PK_PARSE_C)
795 
831  const unsigned char *key, size_t keylen,
832  const unsigned char *pwd, size_t pwdlen,
833  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
834 
865  const unsigned char *key, size_t keylen);
866 
867 #if defined(MBEDTLS_FS_IO)
868 
896  const char *path, const char *password,
897  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng);
898 
916 int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path);
917 #endif /* MBEDTLS_FS_IO */
918 #endif /* MBEDTLS_PK_PARSE_C */
919 
920 #if defined(MBEDTLS_PK_WRITE_C)
921 
934 int mbedtls_pk_write_key_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
935 
949 int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
950 
951 #if defined(MBEDTLS_PEM_WRITE_C)
952 
962 int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
963 
974 int mbedtls_pk_write_key_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
975 #endif /* MBEDTLS_PEM_WRITE_C */
976 #endif /* MBEDTLS_PK_WRITE_C */
977 
978 /*
979  * WARNING: Low-level functions. You probably do not want to use these unless
980  * you are certain you do ;)
981  */
982 
983 #if defined(MBEDTLS_PK_PARSE_C)
984 
994 int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end,
995  mbedtls_pk_context *pk);
996 #endif /* MBEDTLS_PK_PARSE_C */
997 
998 #if defined(MBEDTLS_PK_WRITE_C)
999 
1009 int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start,
1010  const mbedtls_pk_context *key);
1011 #endif /* MBEDTLS_PK_WRITE_C */
1012 
1013 /*
1014  * Internal module functions. You probably do not want to use these unless you
1015  * know you do.
1016  */
1017 #if defined(MBEDTLS_FS_IO)
1018 int mbedtls_pk_load_file(const char *path, unsigned char **buf, size_t *n);
1019 #endif
1020 
1021 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1022 
1041 int mbedtls_pk_wrap_as_opaque(mbedtls_pk_context *pk,
1042  mbedtls_svc_key_id_t *key,
1043  psa_algorithm_t alg,
1044  psa_key_usage_t usage,
1045  psa_algorithm_t alg2);
1046 #endif /* MBEDTLS_USE_PSA_CRYPTO */
1047 
1048 #ifdef __cplusplus
1049 }
1050 #endif
1051 
1052 #endif /* MBEDTLS_PK_H */
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext() ...
Definition: pk.h:100
Public key container.
Definition: pk.h:233
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_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_parse_subpubkey(unsigned char **p, const unsigned char *end, mbedtls_pk_context *pk)
Parse a SubjectPublicKeyInfo DER structure.
void mbedtls_pk_init(mbedtls_pk_context *ctx)
Initialize a mbedtls_pk_context (as NONE).
static mbedtls_rsa_context * mbedtls_pk_rsa(const mbedtls_pk_context pk)
Definition: pk.h:758
mbedtls_pk_debug_type
Types for interfacing with the debug module.
Definition: pk.h:203
struct mbedtls_pk_rsassa_pss_options mbedtls_pk_rsassa_pss_options
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext() ...
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.
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_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.
This file provides an API for Elliptic Curves over GF(P) (ECP).
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...
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.
The ECP key-pair structure.
Definition: ecp.h:424
This file contains ECDSA definitions and functions.
Platform Security Architecture cryptography module.
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_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()
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()
size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx)
Get the size in bits of the underlying key.
#define MBEDTLS_PRIVATE(member)
mbedtls_pk_type_t
Public key types.
Definition: pk.h:85
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.
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:258
static size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
Get the length in bytes of the underlying key.
Definition: pk.h:402
size_t(* mbedtls_pk_rsa_alt_key_len_func)(void *ctx)
Definition: pk.h:263
void mbedtls_pk_restart_ctx
Definition: pk.h:248
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:255
int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items)
Export debug information.
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_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_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.
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
Definition: crypto_types.h:139
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
Macro wrapper for struct's members.
mbedtls_md_type_t mgf1_hash_id
Definition: pk.h:109
uint32_t psa_key_usage_t
Encoding of permitted usage on a key.
Definition: crypto_types.h:328
Build-time configuration info.
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.
struct mbedtls_pk_info_t mbedtls_pk_info_t
Public key information and operations.
Definition: pk.h:228
This file contains the generic functions for message-digest (hashing) and HMAC.
This file provides an API for the RSA public-key cryptosystem.
psa_key_id_t mbedtls_svc_key_id_t
Definition: crypto_types.h:297
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).
mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
Get the key type.
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
int mbedtls_pk_load_file(const char *path, unsigned char **buf, size_t *n)
static mbedtls_ecp_keypair * mbedtls_pk_ec(const mbedtls_pk_context pk)
Definition: pk.h:781
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_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.
struct mbedtls_pk_context mbedtls_pk_context
Public key container.
mbedtls_md_type_t
Supported message digests.
Definition: md.h:143
struct mbedtls_pk_debug_item mbedtls_pk_debug_item
Item to send to the debug module.
The RSA context structure.
Definition: rsa.h:91
Item to send to the debug module.
Definition: pk.h:212
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_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path)
Load and parse a public key.
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_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).