26#if !defined(MBEDTLS_CONFIG_FILE)
29#include MBEDTLS_CONFIG_FILE
34#if defined(MBEDTLS_RSA_C)
38#if defined(MBEDTLS_ECP_C)
42#if defined(MBEDTLS_ECDSA_C)
46#if defined(MBEDTLS_USE_PSA_CRYPTO)
50#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
51 !defined(inline) && !defined(__cplusplus)
52#define inline __inline
55#define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
56#define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
57#define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
58#define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
59#define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
60#define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
61#define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
62#define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
63#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
64#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
65#define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
66#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
67#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
68#define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
71#define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880
98 int expected_salt_len;
114#define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0
116#if ( defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT) ) && \
117 MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
122#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
123#define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
126#if defined(MBEDTLS_ECDSA_C) && \
127 MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_PK_SIGNATURE_MAX_SIZE
130#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
131#define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN
134#if defined(MBEDTLS_USE_PSA_CRYPTO)
135#if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
138#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
139#define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE
142#if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE
149#undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
150#define MBEDTLS_PK_SIGNATURE_MAX_SIZE ( PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 )
159 MBEDTLS_PK_DEBUG_NONE = 0,
160 MBEDTLS_PK_DEBUG_MPI,
161 MBEDTLS_PK_DEBUG_ECP,
175#define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
191#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
199} mbedtls_pk_restart_ctx;
202typedef void mbedtls_pk_restart_ctx;
205#if defined(MBEDTLS_RSA_C)
218#if defined(MBEDTLS_ECP_C)
231#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
235typedef int (*mbedtls_pk_rsa_alt_decrypt_func)(
void *ctx,
int mode,
size_t *olen,
236 const unsigned char *input,
unsigned char *output,
237 size_t output_max_len );
238typedef int (*mbedtls_pk_rsa_alt_sign_func)(
void *ctx,
239 int (*f_rng)(
void *,
unsigned char *, size_t),
void *p_rng,
241 const unsigned char *hash,
unsigned char *sig );
242typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(
void *ctx );
275#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
282void mbedtls_pk_restart_init( mbedtls_pk_restart_ctx *ctx );
290void mbedtls_pk_restart_free( mbedtls_pk_restart_ctx *ctx );
310#if defined(MBEDTLS_USE_PSA_CRYPTO)
343#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
360 mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
361 mbedtls_pk_rsa_alt_sign_func sign_func,
362 mbedtls_pk_rsa_alt_key_len_func key_len_func );
425 const unsigned char *hash,
size_t hash_len,
426 const unsigned char *sig,
size_t sig_len );
450 const unsigned char *hash,
size_t hash_len,
451 const unsigned char *sig,
size_t sig_len,
452 mbedtls_pk_restart_ctx *rs_ctx );
485 const unsigned char *hash,
size_t hash_len,
486 const unsigned char *sig,
size_t sig_len );
519 const unsigned char *hash,
size_t hash_len,
520 unsigned char *sig,
size_t *sig_len,
521 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
553 const unsigned char *hash,
size_t hash_len,
554 unsigned char *sig,
size_t *sig_len,
555 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng,
556 mbedtls_pk_restart_ctx *rs_ctx );
576 const unsigned char *input,
size_t ilen,
577 unsigned char *output,
size_t *olen,
size_t osize,
578 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
597 const unsigned char *input,
size_t ilen,
598 unsigned char *output,
size_t *olen,
size_t osize,
599 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
644#if defined(MBEDTLS_PK_PARSE_C)
675 const unsigned char *key,
size_t keylen,
676 const unsigned char *pwd,
size_t pwdlen );
701 const unsigned char *key,
size_t keylen );
703#if defined(MBEDTLS_FS_IO)
726 const char *path,
const char *password );
749#if defined(MBEDTLS_PK_WRITE_C)
763int mbedtls_pk_write_key_der(
mbedtls_pk_context *ctx,
unsigned char *buf,
size_t size );
778int mbedtls_pk_write_pubkey_der(
mbedtls_pk_context *ctx,
unsigned char *buf,
size_t size );
780#if defined(MBEDTLS_PEM_WRITE_C)
791int mbedtls_pk_write_pubkey_pem(
mbedtls_pk_context *ctx,
unsigned char *buf,
size_t size );
803int mbedtls_pk_write_key_pem(
mbedtls_pk_context *ctx,
unsigned char *buf,
size_t size );
812#if defined(MBEDTLS_PK_PARSE_C)
823int mbedtls_pk_parse_subpubkey(
unsigned char **p,
const unsigned char *end,
827#if defined(MBEDTLS_PK_WRITE_C)
838int mbedtls_pk_write_pubkey(
unsigned char **p,
unsigned char *start,
846#if defined(MBEDTLS_FS_IO)
847int mbedtls_pk_load_file(
const char *path,
unsigned char **buf,
size_t *n );
850#if defined(MBEDTLS_USE_PSA_CRYPTO)
Configuration options (set of defines)
Platform Security Architecture cryptography module.
This file contains ECDSA definitions and functions.
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
uint32_t psa_key_id_t
Encoding of identifiers of persistent keys.
mbedtls_md_type_t
Supported message digests.
This file provides an API for Elliptic Curves over GF(P) (ECP).
This file contains the generic message-digest wrapper.
int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items)
Export debug information.
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_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_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.
@ MBEDTLS_PK_OPAQUE
OPAQUE.
@ MBEDTLS_PK_RSASSA_PSS
RSASSA PSS.
@ MBEDTLS_PK_RSA_ALT
RSA Alt.
@ MBEDTLS_PK_ECKEY_DH
ECKEY DH.
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.
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.
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.
int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv)
Check if a public-private pair of keys matches.
mbedtls_pk_debug_type
Types for interfacing with the debug module.
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()
mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
Get the key type.
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).
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
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).
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
This file provides an API for the RSA public-key cryptosystem.
The ECP key-pair structure.
void * pk_ctx
Underlying public key context
const mbedtls_pk_info_t * pk_info
Public key information
Item to send to the debug module.
Options for RSASSA-PSS signature verification.
The RSA context structure.