31#if !defined(MBEDTLS_CONFIG_FILE)
34#include MBEDTLS_CONFIG_FILE
40#if defined(MBEDTLS_THREADING_C)
54#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080
55#define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100
56#define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180
57#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200
58#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280
59#define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300
60#define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380
61#define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
62#define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480
66#define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500
69#define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580
74#define MBEDTLS_RSA_PUBLIC 0
75#define MBEDTLS_RSA_PRIVATE 1
77#define MBEDTLS_RSA_PKCS_V15 0
78#define MBEDTLS_RSA_PKCS_V21 1
80#define MBEDTLS_RSA_SIGN 1
81#define MBEDTLS_RSA_CRYPT 2
83#define MBEDTLS_RSA_SALT_LEN_ANY -1
94#if !defined(MBEDTLS_RSA_ALT)
136#if defined(MBEDTLS_THREADING_C)
137 mbedtls_threading_mutex_t mutex;
246 unsigned char const *N,
size_t N_len,
247 unsigned char const *P,
size_t P_len,
248 unsigned char const *Q,
size_t Q_len,
249 unsigned char const *D,
size_t D_len,
250 unsigned char const *E,
size_t E_len );
378 unsigned char *N,
size_t N_len,
379 unsigned char *P,
size_t P_len,
380 unsigned char *Q,
size_t Q_len,
381 unsigned char *D,
size_t D_len,
382 unsigned char *E,
size_t E_len );
447 int (*f_rng)(
void *,
unsigned char *,
size_t),
449 unsigned int nbits,
int exponent );
539 const unsigned char *input,
540 unsigned char *output );
574 int (*f_rng)(
void *,
unsigned char *,
size_t),
576 const unsigned char *input,
577 unsigned char *output );
619 int (*f_rng)(
void *,
unsigned char *,
size_t),
621 int mode,
size_t ilen,
622 const unsigned char *input,
623 unsigned char *output );
660 int (*f_rng)(
void *,
unsigned char *,
size_t),
662 int mode,
size_t ilen,
663 const unsigned char *input,
664 unsigned char *output );
705 int (*f_rng)(
void *,
unsigned char *,
size_t),
708 const unsigned char *label,
size_t label_len,
710 const unsigned char *input,
711 unsigned char *output );
758 int (*f_rng)(
void *,
unsigned char *,
size_t),
760 int mode,
size_t *olen,
761 const unsigned char *input,
762 unsigned char *output,
763 size_t output_max_len );
808 int (*f_rng)(
void *,
unsigned char *,
size_t),
810 int mode,
size_t *olen,
811 const unsigned char *input,
812 unsigned char *output,
813 size_t output_max_len );
862 int (*f_rng)(
void *,
unsigned char *,
size_t),
865 const unsigned char *label,
size_t label_len,
867 const unsigned char *input,
868 unsigned char *output,
869 size_t output_max_len );
922 int (*f_rng)(
void *,
unsigned char *,
size_t),
926 unsigned int hashlen,
927 const unsigned char *hash,
928 unsigned char *sig );
970 int (*f_rng)(
void *,
unsigned char *,
size_t),
974 unsigned int hashlen,
975 const unsigned char *hash,
976 unsigned char *sig );
1032 int (*f_rng)(
void *,
unsigned char *,
size_t),
1036 unsigned int hashlen,
1037 const unsigned char *hash,
1038 unsigned char *sig );
1085 int (*f_rng)(
void *,
unsigned char *,
size_t),
1089 unsigned int hashlen,
1090 const unsigned char *hash,
1091 const unsigned char *sig );
1131 int (*f_rng)(
void *,
unsigned char *,
size_t),
1135 unsigned int hashlen,
1136 const unsigned char *hash,
1137 const unsigned char *sig );
1188 int (*f_rng)(
void *,
unsigned char *,
size_t),
1192 unsigned int hashlen,
1193 const unsigned char *hash,
1194 const unsigned char *sig );
1236 int (*f_rng)(
void *,
unsigned char *,
size_t),
1240 unsigned int hashlen,
1241 const unsigned char *hash,
1243 int expected_salt_len,
1244 const unsigned char *sig );
1266#if defined(MBEDTLS_SELF_TEST)
1274int mbedtls_rsa_self_test(
int verbose );
Multi-precision integer library.
Configuration options (set of defines)
mbedtls_md_type_t
Supported message digests.
int mbedtls_rsa_pkcs1_encrypt(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t ilen, const unsigned char *input, unsigned char *output)
This function adds the message padding, then performs an RSA operation.
int mbedtls_rsa_complete(mbedtls_rsa_context *ctx)
This function completes an RSA context from a set of imported core parameters.
int mbedtls_rsa_pkcs1_verify(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, const unsigned char *sig)
This function performs a public RSA operation and checks the message digest.
void mbedtls_rsa_init(mbedtls_rsa_context *ctx, int padding, int hash_id)
This function initializes an RSA context.
int mbedtls_rsa_rsassa_pkcs1_v15_verify(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, const unsigned char *sig)
This function performs a PKCS#1 v1.5 verification operation (RSASSA-PKCS1-v1_5-VERIFY).
int mbedtls_rsa_import(mbedtls_rsa_context *ctx, const mbedtls_mpi *N, const mbedtls_mpi *P, const mbedtls_mpi *Q, const mbedtls_mpi *D, const mbedtls_mpi *E)
This function imports a set of core parameters into an RSA context.
int mbedtls_rsa_check_pub_priv(const mbedtls_rsa_context *pub, const mbedtls_rsa_context *prv)
This function checks a public-private RSA key pair.
int mbedtls_rsa_import_raw(mbedtls_rsa_context *ctx, unsigned char const *N, size_t N_len, unsigned char const *P, size_t P_len, unsigned char const *Q, size_t Q_len, unsigned char const *D, size_t D_len, unsigned char const *E, size_t E_len)
This function imports core RSA parameters, in raw big-endian binary format, into an RSA context.
int mbedtls_rsa_private(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, const unsigned char *input, unsigned char *output)
This function performs an RSA private key operation.
int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, unsigned int nbits, int exponent)
This function generates an RSA keypair.
int mbedtls_rsa_pkcs1_sign(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, unsigned char *sig)
This function performs a private RSA operation to sign a message digest using PKCS#1.
size_t mbedtls_rsa_get_len(const mbedtls_rsa_context *ctx)
This function retrieves the length of RSA modulus in Bytes.
int mbedtls_rsa_rsaes_pkcs1_v15_encrypt(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t ilen, const unsigned char *input, unsigned char *output)
This function performs a PKCS#1 v1.5 encryption operation (RSAES-PKCS1-v1_5-ENCRYPT).
int mbedtls_rsa_rsaes_pkcs1_v15_decrypt(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
This function performs a PKCS#1 v1.5 decryption operation (RSAES-PKCS1-v1_5-DECRYPT).
int mbedtls_rsa_pkcs1_decrypt(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
This function performs an RSA operation, then removes the message padding.
int mbedtls_rsa_export(const mbedtls_rsa_context *ctx, mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q, mbedtls_mpi *D, mbedtls_mpi *E)
This function exports the core parameters of an RSA key.
int mbedtls_rsa_export_raw(const mbedtls_rsa_context *ctx, unsigned char *N, size_t N_len, unsigned char *P, size_t P_len, unsigned char *Q, size_t Q_len, unsigned char *D, size_t D_len, unsigned char *E, size_t E_len)
This function exports core parameters of an RSA key in raw big-endian binary format.
int mbedtls_rsa_copy(mbedtls_rsa_context *dst, const mbedtls_rsa_context *src)
This function copies the components of an RSA context.
int mbedtls_rsa_rsassa_pss_verify(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, const unsigned char *sig)
This function performs a PKCS#1 v2.1 PSS verification operation (RSASSA-PSS-VERIFY).
void mbedtls_rsa_free(mbedtls_rsa_context *ctx)
This function frees the components of an RSA key.
int mbedtls_rsa_export_crt(const mbedtls_rsa_context *ctx, mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP)
This function exports CRT parameters of a private RSA key.
int mbedtls_rsa_public(mbedtls_rsa_context *ctx, const unsigned char *input, unsigned char *output)
This function performs an RSA public key operation.
int mbedtls_rsa_check_privkey(const mbedtls_rsa_context *ctx)
This function checks if a context contains an RSA private key and perform basic consistency checks.
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).
int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, const unsigned char *label, size_t label_len, size_t ilen, const unsigned char *input, unsigned char *output)
This function performs a PKCS#1 v2.1 OAEP encryption operation (RSAES-OAEP-ENCRYPT).
int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context *ctx)
This function checks if a context contains at least an RSA public key.
void mbedtls_rsa_set_padding(mbedtls_rsa_context *ctx, int padding, int hash_id)
This function sets padding for an already initialized RSA context.
int mbedtls_rsa_rsassa_pss_sign(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, unsigned char *sig)
This function performs a PKCS#1 v2.1 PSS signature operation (RSASSA-PSS-SIGN).
int mbedtls_rsa_rsassa_pkcs1_v15_sign(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, unsigned char *sig)
This function performs a PKCS#1 v1.5 signature operation (RSASSA-PKCS1-v1_5-SIGN).
int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, const unsigned char *label, size_t label_len, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
This function performs a PKCS#1 v2.1 OAEP decryption operation (RSAES-OAEP-DECRYPT).
This file contains the generic message-digest wrapper.
This file provides an API for the RSA public-key cryptosystem.
The RSA context structure.
Threading abstraction layer.