47#if !defined(MBEDTLS_CONFIG_FILE)
50#include MBEDTLS_CONFIG_FILE
53#if defined(MBEDTLS_PK_C)
59#if defined(MBEDTLS_RSA_C)
62#if defined(MBEDTLS_ECP_C)
65#if defined(MBEDTLS_ECDSA_C)
73#define PK_VALIDATE_RET( cond ) \
74 MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_PK_BAD_INPUT_DATA )
75#define PK_VALIDATE( cond ) \
76 MBEDTLS_INTERNAL_VALIDATE( cond )
98 ctx->pk_info->ctx_free_func(
ctx->pk_ctx );
103#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
120 ctx->pk_info->rs_free_func ==
NULL )
125 ctx->pk_info->rs_free_func(
ctx->rs_ctx );
138#if defined(MBEDTLS_RSA_C)
142#if defined(MBEDTLS_ECP_C)
148#if defined(MBEDTLS_ECDSA_C)
163 PK_VALIDATE_RET(
ctx !=
NULL );
167 if( (
ctx->pk_ctx =
info->ctx_alloc_func() ) ==
NULL )
175#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
187 PK_VALIDATE_RET(
ctx !=
NULL );
191 if( (
ctx->pk_ctx =
info->ctx_alloc_func() ) ==
NULL )
218 return(
ctx->pk_info->can_do(
type ) );
241#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
256 if( (
ctx->rs_ctx =
info->rs_alloc_func() ) ==
NULL )
270 const unsigned char *
hash,
size_t hash_len,
271 const unsigned char *sig,
size_t sig_len,
274 PK_VALIDATE_RET(
ctx !=
NULL );
277 PK_VALIDATE_RET( sig !=
NULL );
280 pk_hashlen_helper( md_alg, &hash_len ) != 0 )
283#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
285 if( rs_ctx !=
NULL &&
286 mbedtls_ecp_restart_is_enabled() &&
287 ctx->pk_info->verify_rs_func !=
NULL )
291 if( (
ret = pk_restart_setup( rs_ctx,
ctx->pk_info ) ) != 0 )
294 ret =
ctx->pk_info->verify_rs_func(
ctx->pk_ctx,
295 md_alg,
hash, hash_len, sig, sig_len, rs_ctx->rs_ctx );
298 mbedtls_pk_restart_free( rs_ctx );
306 if(
ctx->pk_info->verify_func ==
NULL )
309 return(
ctx->pk_info->verify_func(
ctx->pk_ctx, md_alg,
hash, hash_len,
317 const unsigned char *
hash,
size_t hash_len,
318 const unsigned char *sig,
size_t sig_len )
321 sig, sig_len,
NULL ) );
329 const unsigned char *
hash,
size_t hash_len,
330 const unsigned char *sig,
size_t sig_len )
332 PK_VALIDATE_RET(
ctx !=
NULL );
335 PK_VALIDATE_RET( sig !=
NULL );
345#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21)
349#if SIZE_MAX > UINT_MAX
364 md_alg, (
unsigned int) hash_len,
hash,
392 const unsigned char *
hash,
size_t hash_len,
393 unsigned char *sig,
size_t *sig_len,
394 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng,
397 PK_VALIDATE_RET(
ctx !=
NULL );
400 PK_VALIDATE_RET( sig !=
NULL );
403 pk_hashlen_helper( md_alg, &hash_len ) != 0 )
406#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
408 if( rs_ctx !=
NULL &&
409 mbedtls_ecp_restart_is_enabled() &&
410 ctx->pk_info->sign_rs_func !=
NULL )
414 if( (
ret = pk_restart_setup( rs_ctx,
ctx->pk_info ) ) != 0 )
417 ret =
ctx->pk_info->sign_rs_func(
ctx->pk_ctx, md_alg,
418 hash, hash_len, sig, sig_len, f_rng, p_rng, rs_ctx->rs_ctx );
421 mbedtls_pk_restart_free( rs_ctx );
429 if(
ctx->pk_info->sign_func ==
NULL )
432 return(
ctx->pk_info->sign_func(
ctx->pk_ctx, md_alg,
hash, hash_len,
433 sig, sig_len, f_rng, p_rng ) );
440 const unsigned char *
hash,
size_t hash_len,
441 unsigned char *sig,
size_t *sig_len,
442 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
445 sig, sig_len, f_rng, p_rng,
NULL ) );
452 const unsigned char *
input,
size_t ilen,
453 unsigned char *output,
size_t *olen,
size_t osize,
454 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
456 PK_VALIDATE_RET(
ctx !=
NULL );
457 PK_VALIDATE_RET(
input !=
NULL || ilen == 0 );
458 PK_VALIDATE_RET( output !=
NULL || osize == 0 );
459 PK_VALIDATE_RET( olen !=
NULL );
464 if(
ctx->pk_info->decrypt_func ==
NULL )
467 return(
ctx->pk_info->decrypt_func(
ctx->pk_ctx,
input, ilen,
468 output, olen, osize, f_rng, p_rng ) );
475 const unsigned char *
input,
size_t ilen,
476 unsigned char *output,
size_t *olen,
size_t osize,
477 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
479 PK_VALIDATE_RET(
ctx !=
NULL );
480 PK_VALIDATE_RET(
input !=
NULL || ilen == 0 );
481 PK_VALIDATE_RET( output !=
NULL || osize == 0 );
482 PK_VALIDATE_RET( olen !=
NULL );
487 if(
ctx->pk_info->encrypt_func ==
NULL )
490 return(
ctx->pk_info->encrypt_func(
ctx->pk_ctx,
input, ilen,
491 output, olen, osize, f_rng, p_rng ) );
499 PK_VALIDATE_RET( pub !=
NULL );
500 PK_VALIDATE_RET( prv !=
NULL );
533 return(
ctx->pk_info->get_bitlen(
ctx->pk_ctx ) );
541 PK_VALIDATE_RET(
ctx !=
NULL );
545 if(
ctx->pk_info->debug_func ==
NULL )
558 return(
"invalid PK" );
560 return(
ctx->pk_info->name );
571 return(
ctx->pk_info->type );
This file contains ECDSA definitions and functions.
GLuint GLuint GLsizei GLenum type
GLenum GLenum GLenum input
mbedtls_md_type_t
Supported message digests.
unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info)
This function extracts the message-digest size from the message-digest information structure.
Public Key abstraction layer.
int(* mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Types for RSA-alt abstraction.
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.
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.
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).
static mbedtls_rsa_context * mbedtls_pk_rsa(const mbedtls_pk_context pk)
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.
#define MBEDTLS_ERR_PK_TYPE_MISMATCH
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....
int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, const mbedtls_pk_context *prv)
Check if a public-private pair of keys matches.
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()
#define MBEDTLS_ERR_PK_BAD_INPUT_DATA
mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
Get the key type.
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_ERR_PK_SIG_LEN_MISMATCH
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)
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
int(* mbedtls_pk_rsa_alt_sign_func)(void *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
#define MBEDTLS_ERR_PK_ALLOC_FAILED
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).
#define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
Public Key abstraction layer: wrapper functions.
const mbedtls_pk_info_t mbedtls_rsa_alt_info
const mbedtls_pk_info_t mbedtls_rsa_info
const mbedtls_pk_info_t mbedtls_ecdsa_info
const mbedtls_pk_info_t mbedtls_eckeydh_info
const mbedtls_pk_info_t mbedtls_eckey_info
This file provides an API for the RSA public-key cryptosystem.
#define MBEDTLS_RSA_PUBLIC
#define MBEDTLS_ERR_RSA_VERIFY_FAILED
int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, mbedtls_md_type_t mgf1_hash_id, int expected_salt_len, const unsigned char *sig)
This function performs a PKCS#1 v2.1 PSS verification operation (RSASSA-PSS-VERIFY).
#define mbedtls_md_info_from_type
#define mbedtls_pk_get_bitlen
Configuration options (set of defines)
This file provides an API for Elliptic Curves over GF(P) (ECP).
#define MBEDTLS_ERR_ECP_IN_PROGRESS
const mbedtls_pk_info_t * pk_info
Item to send to the debug module.
int(* check_pair_func)(const void *pub, const void *prv)
Options for RSASSA-PSS signature verification. See mbedtls_rsa_rsassa_pss_verify_ext()
mbedtls_md_type_t mgf1_hash_id
mbedtls_pk_rsa_alt_key_len_func key_len_func
mbedtls_pk_rsa_alt_decrypt_func decrypt_func
mbedtls_pk_rsa_alt_sign_func sign_func