24 #ifndef POLARSSL_RSA_H
25 #define POLARSSL_RSA_H
27 #if !defined(POLARSSL_CONFIG_FILE)
30 #include POLARSSL_CONFIG_FILE
36 #if defined(POLARSSL_THREADING_C)
43 #define POLARSSL_ERR_RSA_BAD_INPUT_DATA -0x4080
44 #define POLARSSL_ERR_RSA_INVALID_PADDING -0x4100
45 #define POLARSSL_ERR_RSA_KEY_GEN_FAILED -0x4180
46 #define POLARSSL_ERR_RSA_KEY_CHECK_FAILED -0x4200
47 #define POLARSSL_ERR_RSA_PUBLIC_FAILED -0x4280
48 #define POLARSSL_ERR_RSA_PRIVATE_FAILED -0x4300
49 #define POLARSSL_ERR_RSA_VERIFY_FAILED -0x4380
50 #define POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
51 #define POLARSSL_ERR_RSA_RNG_FAILED -0x4480
59 #define RSA_PKCS_V15 0
60 #define RSA_PKCS_V21 1
65 #define RSA_SALT_LEN_ANY -1
71 #if defined(POLARSSL_RSA_C)
108 #if defined(POLARSSL_THREADING_C)
109 threading_mutex_t mutex;
167 int (*f_rng)(
void *,
unsigned char *,
size_t),
169 unsigned int nbits,
int exponent );
217 const unsigned char *input,
218 unsigned char *output );
235 int (*f_rng)(
void *,
unsigned char *,
size_t),
237 const unsigned char *input,
238 unsigned char *output );
260 int (*f_rng)(
void *,
unsigned char *,
size_t),
262 int mode,
size_t ilen,
263 const unsigned char *input,
264 unsigned char *output );
283 int (*f_rng)(
void *,
unsigned char *,
size_t),
285 int mode,
size_t ilen,
286 const unsigned char *input,
287 unsigned char *output );
309 int (*f_rng)(
void *,
unsigned char *,
size_t),
312 const unsigned char *label,
size_t label_len,
314 const unsigned char *input,
315 unsigned char *output );
338 int (*f_rng)(
void *,
unsigned char *,
size_t),
340 int mode,
size_t *olen,
341 const unsigned char *input,
342 unsigned char *output,
343 size_t output_max_len );
364 int (*f_rng)(
void *,
unsigned char *,
size_t),
366 int mode,
size_t *olen,
367 const unsigned char *input,
368 unsigned char *output,
369 size_t output_max_len );
392 int (*f_rng)(
void *,
unsigned char *,
size_t),
395 const unsigned char *label,
size_t label_len,
397 const unsigned char *input,
398 unsigned char *output,
399 size_t output_max_len );
426 int (*f_rng)(
void *,
unsigned char *,
size_t),
430 unsigned int hashlen,
431 const unsigned char *hash,
432 unsigned char *sig );
453 int (*f_rng)(
void *,
unsigned char *,
size_t),
457 unsigned int hashlen,
458 const unsigned char *hash,
459 unsigned char *sig );
486 int (*f_rng)(
void *,
unsigned char *,
size_t),
490 unsigned int hashlen,
491 const unsigned char *hash,
492 unsigned char *sig );
518 int (*f_rng)(
void *,
unsigned char *,
size_t),
522 unsigned int hashlen,
523 const unsigned char *hash,
524 const unsigned char *sig );
545 int (*f_rng)(
void *,
unsigned char *,
size_t),
549 unsigned int hashlen,
550 const unsigned char *hash,
551 const unsigned char *sig );
579 int (*f_rng)(
void *,
unsigned char *,
size_t),
583 unsigned int hashlen,
584 const unsigned char *hash,
585 const unsigned char *sig );
612 int (*f_rng)(
void *,
unsigned char *,
size_t),
616 unsigned int hashlen,
617 const unsigned char *hash,
619 int expected_salt_len,
620 const unsigned char *sig );
int rsa_self_test(int verbose)
Checkup routine.
int rsa_copy(rsa_context *dst, const rsa_context *src)
Copy the components of an RSA context.
int rsa_rsaes_oaep_encrypt(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)
Perform a PKCS#1 v2.1 OAEP encryption (RSAES-OAEP-ENCRYPT)
int rsa_check_privkey(const rsa_context *ctx)
Check a private RSA key.
int rsa_rsassa_pkcs1_v15_verify(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, const unsigned char *sig)
Perform a PKCS#1 v1.5 verification (RSASSA-PKCS1-v1_5-VERIFY)
int rsa_rsaes_pkcs1_v15_encrypt(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)
Perform a PKCS#1 v1.5 encryption (RSAES-PKCS1-v1_5-ENCRYPT)
int rsa_rsaes_oaep_decrypt(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)
Perform a PKCS#1 v2.1 OAEP decryption (RSAES-OAEP-DECRYPT)
Configuration options (set of defines)
int rsa_check_pubkey(const rsa_context *ctx)
Check a public RSA key.
int rsa_rsassa_pss_verify(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, const unsigned char *sig)
Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY) (This is the "simple" version.)
int rsa_pkcs1_decrypt(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)
Generic wrapper to perform a PKCS#1 decryption using the mode from the context.
Multi-precision integer library.
int rsa_check_pub_priv(const rsa_context *pub, const rsa_context *prv)
Check a public-private RSA key pair.
int rsa_rsaes_pkcs1_v15_decrypt(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)
Perform a PKCS#1 v1.5 decryption (RSAES-PKCS1-v1_5-DECRYPT)
int rsa_rsassa_pss_verify_ext(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, md_type_t mgf1_hash_id, int expected_salt_len, const unsigned char *sig)
Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY) (This is the version with "full" options...
void rsa_free(rsa_context *ctx)
Free the components of an RSA key.
int rsa_private(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, const unsigned char *input, unsigned char *output)
Do an RSA private key operation.
int rsa_pkcs1_encrypt(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)
Generic wrapper to perform a PKCS#1 encryption using the mode from the context.
Threading abstraction layer.
int rsa_rsassa_pss_sign(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Perform a PKCS#1 v2.1 PSS signature (RSASSA-PSS-SIGN)
int rsa_pkcs1_verify(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, const unsigned char *sig)
Generic wrapper to perform a PKCS#1 verification using the mode from the context. ...
int rsa_pkcs1_sign(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Generic wrapper to perform a PKCS#1 signature using the mode from the context.
int rsa_rsassa_pkcs1_v15_sign(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Perform a PKCS#1 v1.5 signature (RSASSA-PKCS1-v1_5-SIGN)
Generic message digest wrapper.
void rsa_set_padding(rsa_context *ctx, int padding, int hash_id)
Set padding for an already initialized RSA context See rsa_init() for details.
int rsa_gen_key(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, unsigned int nbits, int exponent)
Generate an RSA keypair.
void rsa_init(rsa_context *ctx, int padding, int hash_id)
Initialize an RSA context.
int rsa_public(rsa_context *ctx, const unsigned char *input, unsigned char *output)
Do an RSA public key operation.