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)
167 int (*f_rng)(
void *,
unsigned char *,
size_t),
169 unsigned int nbits,
int exponent );
218 const unsigned char *input,
219 unsigned char *output );
237 int (*f_rng)(
void *,
unsigned char *,
size_t),
239 const unsigned char *input,
240 unsigned char *output );
263 int (*f_rng)(
void *,
unsigned char *,
size_t),
265 int mode,
size_t ilen,
266 const unsigned char *input,
267 unsigned char *output );
287 int (*f_rng)(
void *,
unsigned char *,
size_t),
289 int mode,
size_t ilen,
290 const unsigned char *input,
291 unsigned char *output );
314 int (*f_rng)(
void *,
unsigned char *,
size_t),
317 const unsigned char *label,
size_t label_len,
319 const unsigned char *input,
320 unsigned char *output );
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 );
384 int (*f_rng)(
void *,
unsigned char *,
size_t),
386 int mode,
size_t *olen,
387 const unsigned char *input,
388 unsigned char *output,
389 size_t output_max_len );
420 int (*f_rng)(
void *,
unsigned char *,
size_t),
423 const unsigned char *label,
size_t label_len,
425 const unsigned char *input,
426 unsigned char *output,
427 size_t output_max_len );
455 int (*f_rng)(
void *,
unsigned char *,
size_t),
459 unsigned int hashlen,
460 const unsigned char *hash,
461 unsigned char *sig );
482 int (*f_rng)(
void *,
unsigned char *,
size_t),
486 unsigned int hashlen,
487 const unsigned char *hash,
488 unsigned char *sig );
516 int (*f_rng)(
void *,
unsigned char *,
size_t),
520 unsigned int hashlen,
521 const unsigned char *hash,
522 unsigned char *sig );
549 int (*f_rng)(
void *,
unsigned char *,
size_t),
553 unsigned int hashlen,
554 const unsigned char *hash,
555 const unsigned char *sig );
577 int (*f_rng)(
void *,
unsigned char *,
size_t),
581 unsigned int hashlen,
582 const unsigned char *hash,
583 const unsigned char *sig );
612 int (*f_rng)(
void *,
unsigned char *,
size_t),
616 unsigned int hashlen,
617 const unsigned char *hash,
618 const unsigned char *sig );
646 int (*f_rng)(
void *,
unsigned char *,
size_t),
650 unsigned int hashlen,
651 const unsigned char *hash,
653 int expected_salt_len,
654 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) (Thread-safe if POLARSSL_THREADING_C is en...
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) (Thread-safe if POLARSSL_THREADING_C is...
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) (Thread-safe if POLARSSL_THREADING_C is e...
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) (Thread-safe if POLARSSL_THREADING_C is en...
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.) (Thread-safe if POLARSSL_THREADING_C is enabled)
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) (Thread-safe if POLARSSL_THREADING_C is e...
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 (Thread-safe if POLARSSL_THREADING_C is enabled)
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) (Thread-safe if POLARSSL_THREADING_C is enabled...
pthread_mutex_t threading_mutex_t
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 (Thread-safe if POLARSSL_THREADING_C is enabled)