27 #ifndef POLARSSL_RSA_H
28 #define POLARSSL_RSA_H
30 #if !defined(POLARSSL_CONFIG_FILE)
33 #include POLARSSL_CONFIG_FILE
39 #if defined(POLARSSL_THREADING_C)
46 #define POLARSSL_ERR_RSA_BAD_INPUT_DATA -0x4080
47 #define POLARSSL_ERR_RSA_INVALID_PADDING -0x4100
48 #define POLARSSL_ERR_RSA_KEY_GEN_FAILED -0x4180
49 #define POLARSSL_ERR_RSA_KEY_CHECK_FAILED -0x4200
50 #define POLARSSL_ERR_RSA_PUBLIC_FAILED -0x4280
51 #define POLARSSL_ERR_RSA_PRIVATE_FAILED -0x4300
52 #define POLARSSL_ERR_RSA_VERIFY_FAILED -0x4380
53 #define POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
54 #define POLARSSL_ERR_RSA_RNG_FAILED -0x4480
62 #define RSA_PKCS_V15 0
63 #define RSA_PKCS_V21 1
68 #define RSA_SALT_LEN_ANY -1
74 #if defined(POLARSSL_RSA_C)
102 #if !defined(POLARSSL_RSA_NO_CRT)
113 #if defined(POLARSSL_THREADING_C)
114 threading_mutex_t mutex;
172 int (*f_rng)(
void *,
unsigned char *,
size_t),
174 unsigned int nbits,
int exponent );
211 const unsigned char *input,
212 unsigned char *output );
229 int (*f_rng)(
void *,
unsigned char *,
size_t),
231 const unsigned char *input,
232 unsigned char *output );
254 int (*f_rng)(
void *,
unsigned char *,
size_t),
256 int mode,
size_t ilen,
257 const unsigned char *input,
258 unsigned char *output );
277 int (*f_rng)(
void *,
unsigned char *,
size_t),
279 int mode,
size_t ilen,
280 const unsigned char *input,
281 unsigned char *output );
303 int (*f_rng)(
void *,
unsigned char *,
size_t),
306 const unsigned char *label,
size_t label_len,
308 const unsigned char *input,
309 unsigned char *output );
332 int (*f_rng)(
void *,
unsigned char *,
size_t),
334 int mode,
size_t *olen,
335 const unsigned char *input,
336 unsigned char *output,
337 size_t output_max_len );
358 int (*f_rng)(
void *,
unsigned char *,
size_t),
360 int mode,
size_t *olen,
361 const unsigned char *input,
362 unsigned char *output,
363 size_t output_max_len );
386 int (*f_rng)(
void *,
unsigned char *,
size_t),
389 const unsigned char *label,
size_t label_len,
391 const unsigned char *input,
392 unsigned char *output,
393 size_t output_max_len );
420 int (*f_rng)(
void *,
unsigned char *,
size_t),
424 unsigned int hashlen,
425 const unsigned char *hash,
426 unsigned char *sig );
447 int (*f_rng)(
void *,
unsigned char *,
size_t),
451 unsigned int hashlen,
452 const unsigned char *hash,
453 unsigned char *sig );
480 int (*f_rng)(
void *,
unsigned char *,
size_t),
484 unsigned int hashlen,
485 const unsigned char *hash,
486 unsigned char *sig );
512 int (*f_rng)(
void *,
unsigned char *,
size_t),
516 unsigned int hashlen,
517 const unsigned char *hash,
518 const unsigned char *sig );
539 int (*f_rng)(
void *,
unsigned char *,
size_t),
543 unsigned int hashlen,
544 const unsigned char *hash,
545 const unsigned char *sig );
573 int (*f_rng)(
void *,
unsigned char *,
size_t),
577 unsigned int hashlen,
578 const unsigned char *hash,
579 const unsigned char *sig );
606 int (*f_rng)(
void *,
unsigned char *,
size_t),
610 unsigned int hashlen,
611 const unsigned char *hash,
613 int expected_salt_len,
614 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_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.