31 #if defined(MBEDTLS_RSA_C)
35 #if defined(MBEDTLS_ECP_C)
39 #if defined(MBEDTLS_ECDSA_C)
43 #if defined(MBEDTLS_USE_PSA_CRYPTO)
47 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
48 !defined(inline) && !defined(__cplusplus)
49 #define inline __inline
53 #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
55 #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
57 #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
59 #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
61 #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
63 #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
65 #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
67 #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
69 #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
71 #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
73 #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
75 #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
77 #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
79 #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
81 #define MBEDTLS_ERR_PK_BUFFER_TOO_SMALL -0x3880
124 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0
126 #if ( defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT) ) && \
127 MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
132 #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
133 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
136 #if defined(MBEDTLS_ECDSA_C) && \
137 MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_PK_SIGNATURE_MAX_SIZE
140 #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
141 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN
144 #if defined(MBEDTLS_USE_PSA_CRYPTO)
145 #if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
148 #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
149 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE
152 #if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE
159 #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
160 #define MBEDTLS_PK_SIGNATURE_MAX_SIZE ( PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 )
185 #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
205 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
219 #if defined(MBEDTLS_RSA_C)
232 #if defined(MBEDTLS_ECP_C)
245 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
250 const unsigned char *input,
unsigned char *output,
251 size_t output_max_len );
253 int (*f_rng)(
void *,
unsigned char *, size_t),
void *p_rng,
255 const unsigned char *hash,
unsigned char *sig );
289 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
324 #if defined(MBEDTLS_USE_PSA_CRYPTO)
357 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
442 const unsigned char *hash,
size_t hash_len,
443 const unsigned char *sig,
size_t sig_len );
467 const unsigned char *hash,
size_t hash_len,
468 const unsigned char *sig,
size_t sig_len,
469 mbedtls_pk_restart_ctx *rs_ctx );
502 const unsigned char *hash,
size_t hash_len,
503 const unsigned char *sig,
size_t sig_len );
534 const unsigned char *hash,
size_t hash_len,
535 unsigned char *sig,
size_t sig_size,
size_t *sig_len,
536 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
569 const unsigned char *hash,
size_t hash_len,
570 unsigned char *sig,
size_t sig_size,
size_t *sig_len,
571 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng,
572 mbedtls_pk_restart_ctx *rs_ctx );
592 const unsigned char *input,
size_t ilen,
593 unsigned char *output,
size_t *olen,
size_t osize,
594 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
615 const unsigned char *input,
size_t ilen,
616 unsigned char *output,
size_t *olen,
size_t osize,
617 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
635 int (*f_rng)(
void *,
unsigned char *,
size_t),
667 #if defined(MBEDTLS_PK_PARSE_C)
700 const unsigned char *key,
size_t keylen,
701 const unsigned char *pwd,
size_t pwdlen,
702 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
727 const unsigned char *key,
size_t keylen );
729 #if defined(MBEDTLS_FS_IO)
754 const char *path,
const char *password,
755 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
778 #if defined(MBEDTLS_PK_WRITE_C)
809 #if defined(MBEDTLS_PEM_WRITE_C)
841 #if defined(MBEDTLS_PK_PARSE_C)
856 #if defined(MBEDTLS_PK_WRITE_C)
875 #if defined(MBEDTLS_FS_IO)
879 #if defined(MBEDTLS_USE_PSA_CRYPTO)
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext() ...
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)
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)
mbedtls_pk_debug_type
Types for interfacing with the debug module.
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.
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.
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 size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
Get the length in bytes of the underlying key.
void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx)
Initialize a restart context.
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_setup_opaque(mbedtls_pk_context *ctx, const psa_key_id_t key)
Initialize a PK context to wrap 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_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.
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
Macro wrapper for struct's memebrs.
Build-time configuration info.
size_t(* mbedtls_pk_rsa_alt_key_len_func)(void *ctx)
struct mbedtls_pk_info_t mbedtls_pk_info_t
Public key information and operations.
This file contains the generic message-digest wrapper.
This file provides an API for the RSA public-key cryptosystem.
void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx)
Free the components of a restart context.
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)
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.
Context for resuming operations.
struct mbedtls_pk_context mbedtls_pk_context
Public key container.
mbedtls_md_type_t
Supported message digests.
struct mbedtls_pk_debug_item mbedtls_pk_debug_item
Item to send to the debug module.
Item to send to the debug module.
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).
int mbedtls_pk_wrap_as_opaque(mbedtls_pk_context *pk, psa_key_id_t *key, psa_algorithm_t hash_alg)
Turn an EC key into an opaque one.
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.