27 #if !defined(MBEDTLS_CONFIG_FILE)
30 #include MBEDTLS_CONFIG_FILE
35 #if defined(MBEDTLS_RSA_C)
39 #if defined(MBEDTLS_ECP_C)
43 #if defined(MBEDTLS_ECDSA_C)
47 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
48 !defined(inline) && !defined(__cplusplus)
49 #define inline __inline
52 #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
53 #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
54 #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
55 #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
56 #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
57 #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
58 #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
59 #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
60 #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
61 #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
62 #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
63 #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
64 #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
65 #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
116 #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
132 #if defined(MBEDTLS_RSA_C)
141 return( (mbedtls_rsa_context *) (pk).pk_ctx );
145 #if defined(MBEDTLS_ECP_C)
158 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
162 typedef int (*mbedtls_pk_rsa_alt_decrypt_func)(
void *ctx,
int mode,
size_t *olen,
163 const unsigned char *input,
unsigned char *output,
164 size_t output_max_len );
165 typedef int (*mbedtls_pk_rsa_alt_sign_func)(
void *ctx,
166 int (*f_rng)(
void *,
unsigned char *, size_t),
void *p_rng,
168 const unsigned char *hash,
unsigned char *sig );
169 typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(
void *ctx );
207 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
225 mbedtls_pk_rsa_alt_key_len_func key_len_func );
284 const unsigned char *hash,
size_t hash_len,
285 const unsigned char *sig,
size_t sig_len );
318 const unsigned char *hash,
size_t hash_len,
319 const unsigned char *sig,
size_t sig_len );
346 const unsigned char *hash,
size_t hash_len,
347 unsigned char *sig,
size_t *sig_len,
348 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
367 const unsigned char *input,
size_t ilen,
368 unsigned char *output,
size_t *olen,
size_t osize,
369 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
388 const unsigned char *input,
size_t ilen,
389 unsigned char *output,
size_t *olen,
size_t osize,
390 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng );
430 #if defined(MBEDTLS_PK_PARSE_C)
451 const unsigned char *key,
size_t keylen,
452 const unsigned char *pwd,
size_t pwdlen );
472 const unsigned char *key,
size_t keylen );
474 #if defined(MBEDTLS_FS_IO)
492 const char *path,
const char *password );
513 #if defined(MBEDTLS_PK_WRITE_C)
527 int mbedtls_pk_write_key_der(
mbedtls_pk_context *ctx,
unsigned char *buf,
size_t size );
542 int mbedtls_pk_write_pubkey_der(
mbedtls_pk_context *ctx,
unsigned char *buf,
size_t size );
544 #if defined(MBEDTLS_PEM_WRITE_C)
554 int mbedtls_pk_write_pubkey_pem(
mbedtls_pk_context *ctx,
unsigned char *buf,
size_t size );
565 int mbedtls_pk_write_key_pem(
mbedtls_pk_context *ctx,
unsigned char *buf,
size_t size );
574 #if defined(MBEDTLS_PK_PARSE_C)
584 int mbedtls_pk_parse_subpubkey(
unsigned char **p,
const unsigned char *end,
588 #if defined(MBEDTLS_PK_WRITE_C)
599 int mbedtls_pk_write_pubkey(
unsigned char **p,
unsigned char *start,
607 #if defined(MBEDTLS_FS_IO)
608 int mbedtls_pk_load_file(
const char *path,
unsigned char **buf,
size_t *n );
Options for RSASSA-PSS signature verification.
void mbedtls_pk_init(mbedtls_pk_context *ctx)
Initialize a mbedtls_pk_context (as NONE)
mbedtls_pk_debug_type
Types for interfacing with the debug module.
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.
Elliptic curves over GF(p)
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.
const mbedtls_pk_info_t * pk_info
Public key informations.
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).
size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx)
Get the size in bits of the underlying key.
mbedtls_pk_type_t
Public key types.
Compatibility names (set of defines)
static size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
Get the length in bytes of the underlying key.
mbedtls_pk_type_t type
Public key type.
int(* decrypt_func)(void *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.
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_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items)
Export debug information.
void * pk_ctx
Underlying public key context.
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free a mbedtls_pk_context.
mbedtls_md_type_t mgf1_hash_id
Generic message digest wrapper.
The RSA public-key cryptosystem.
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_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...
mbedtls_pk_debug_type type
int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv)
Check if a public-private pair of keys matches.
Item to send to the debug module.
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(* sign_func)(void *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.