27 #ifndef POLARSSL_RSA_H
28 #define POLARSSL_RSA_H
35 #if defined(POLARSSL_THREADING_C)
42 #define POLARSSL_ERR_RSA_BAD_INPUT_DATA -0x4080
43 #define POLARSSL_ERR_RSA_INVALID_PADDING -0x4100
44 #define POLARSSL_ERR_RSA_KEY_GEN_FAILED -0x4180
45 #define POLARSSL_ERR_RSA_KEY_CHECK_FAILED -0x4200
46 #define POLARSSL_ERR_RSA_PUBLIC_FAILED -0x4280
47 #define POLARSSL_ERR_RSA_PRIVATE_FAILED -0x4300
48 #define POLARSSL_ERR_RSA_VERIFY_FAILED -0x4380
49 #define POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
50 #define POLARSSL_ERR_RSA_RNG_FAILED -0x4480
58 #define RSA_PKCS_V15 0
59 #define RSA_PKCS_V21 1
68 #if defined(POLARSSL_RSA_C)
96 #if !defined(POLARSSL_RSA_NO_CRT)
107 #if defined(POLARSSL_THREADING_C)
108 threading_mutex_t mutex;
145 int (*f_rng)(
void *,
unsigned char *,
size_t),
147 unsigned int nbits,
int exponent );
184 const unsigned char *input,
185 unsigned char *output );
202 int (*f_rng)(
void *,
unsigned char *,
size_t),
204 const unsigned char *input,
205 unsigned char *output );
227 int (*f_rng)(
void *,
unsigned char *,
size_t),
229 int mode,
size_t ilen,
230 const unsigned char *input,
231 unsigned char *output );
250 int (*f_rng)(
void *,
unsigned char *,
size_t),
252 int mode,
size_t ilen,
253 const unsigned char *input,
254 unsigned char *output );
276 int (*f_rng)(
void *,
unsigned char *,
size_t),
279 const unsigned char *label,
size_t label_len,
281 const unsigned char *input,
282 unsigned char *output );
305 int (*f_rng)(
void *,
unsigned char *,
size_t),
307 int mode,
size_t *olen,
308 const unsigned char *input,
309 unsigned char *output,
310 size_t output_max_len );
331 int (*f_rng)(
void *,
unsigned char *,
size_t),
333 int mode,
size_t *olen,
334 const unsigned char *input,
335 unsigned char *output,
336 size_t output_max_len );
359 int (*f_rng)(
void *,
unsigned char *,
size_t),
362 const unsigned char *label,
size_t label_len,
364 const unsigned char *input,
365 unsigned char *output,
366 size_t output_max_len );
396 int (*f_rng)(
void *,
unsigned char *,
size_t),
400 unsigned int hashlen,
401 const unsigned char *hash,
402 unsigned char *sig );
423 int (*f_rng)(
void *,
unsigned char *,
size_t),
427 unsigned int hashlen,
428 const unsigned char *hash,
429 unsigned char *sig );
457 int (*f_rng)(
void *,
unsigned char *,
size_t),
461 unsigned int hashlen,
462 const unsigned char *hash,
463 unsigned char *sig );
492 int (*f_rng)(
void *,
unsigned char *,
size_t),
496 unsigned int hashlen,
497 const unsigned char *hash,
498 const unsigned char *sig );
519 int (*f_rng)(
void *,
unsigned char *,
size_t),
523 unsigned int hashlen,
524 const unsigned char *hash,
525 const unsigned char *sig );
553 int (*f_rng)(
void *,
unsigned char *,
size_t),
557 unsigned int hashlen,
558 const unsigned char *hash,
559 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.
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.