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
72 #if defined(POLARSSL_RSA_C)
100 #if !defined(POLARSSL_RSA_NO_CRT)
111 #if defined(POLARSSL_THREADING_C)
112 threading_mutex_t mutex;
164 int (*f_rng)(
void *,
unsigned char *,
size_t),
166 unsigned int nbits,
int exponent );
203 const unsigned char *input,
204 unsigned char *output );
221 int (*f_rng)(
void *,
unsigned char *,
size_t),
223 const unsigned char *input,
224 unsigned char *output );
246 int (*f_rng)(
void *,
unsigned char *,
size_t),
248 int mode,
size_t ilen,
249 const unsigned char *input,
250 unsigned char *output );
269 int (*f_rng)(
void *,
unsigned char *,
size_t),
271 int mode,
size_t ilen,
272 const unsigned char *input,
273 unsigned char *output );
295 int (*f_rng)(
void *,
unsigned char *,
size_t),
298 const unsigned char *label,
size_t label_len,
300 const unsigned char *input,
301 unsigned char *output );
324 int (*f_rng)(
void *,
unsigned char *,
size_t),
326 int mode,
size_t *olen,
327 const unsigned char *input,
328 unsigned char *output,
329 size_t output_max_len );
350 int (*f_rng)(
void *,
unsigned char *,
size_t),
352 int mode,
size_t *olen,
353 const unsigned char *input,
354 unsigned char *output,
355 size_t output_max_len );
378 int (*f_rng)(
void *,
unsigned char *,
size_t),
381 const unsigned char *label,
size_t label_len,
383 const unsigned char *input,
384 unsigned char *output,
385 size_t output_max_len );
415 int (*f_rng)(
void *,
unsigned char *,
size_t),
419 unsigned int hashlen,
420 const unsigned char *hash,
421 unsigned char *sig );
442 int (*f_rng)(
void *,
unsigned char *,
size_t),
446 unsigned int hashlen,
447 const unsigned char *hash,
448 unsigned char *sig );
476 int (*f_rng)(
void *,
unsigned char *,
size_t),
480 unsigned int hashlen,
481 const unsigned char *hash,
482 unsigned char *sig );
511 int (*f_rng)(
void *,
unsigned char *,
size_t),
515 unsigned int hashlen,
516 const unsigned char *hash,
517 const unsigned char *sig );
538 int (*f_rng)(
void *,
unsigned char *,
size_t),
542 unsigned int hashlen,
543 const unsigned char *hash,
544 const unsigned char *sig );
571 int (*f_rng)(
void *,
unsigned char *,
size_t),
575 unsigned int hashlen,
576 const unsigned char *hash,
577 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)
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)
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.
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.