27 #ifndef POLARSSL_RSA_H
28 #define POLARSSL_RSA_H
35 #define POLARSSL_ERR_RSA_BAD_INPUT_DATA -0x4080
36 #define POLARSSL_ERR_RSA_INVALID_PADDING -0x4100
37 #define POLARSSL_ERR_RSA_KEY_GEN_FAILED -0x4180
38 #define POLARSSL_ERR_RSA_KEY_CHECK_FAILED -0x4200
39 #define POLARSSL_ERR_RSA_PUBLIC_FAILED -0x4280
40 #define POLARSSL_ERR_RSA_PRIVATE_FAILED -0x4300
41 #define POLARSSL_ERR_RSA_VERIFY_FAILED -0x4380
42 #define POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
43 #define POLARSSL_ERR_RSA_RNG_FAILED -0x4480
52 #define SIG_RSA_SHA1 5
53 #define SIG_RSA_SHA224 14
54 #define SIG_RSA_SHA256 11
55 #define SIG_RSA_SHA384 12
56 #define SIG_RSA_SHA512 13
61 #define RSA_PKCS_V15 0
62 #define RSA_PKCS_V21 1
67 #define ASN1_STR_CONSTRUCTED_SEQUENCE "\x30"
68 #define ASN1_STR_NULL "\x05"
69 #define ASN1_STR_OID "\x06"
70 #define ASN1_STR_OCTET_STRING "\x04"
72 #define OID_DIGEST_ALG_MDX "\x2A\x86\x48\x86\xF7\x0D\x02\x00"
73 #define OID_HASH_ALG_SHA1 "\x2b\x0e\x03\x02\x1a"
74 #define OID_HASH_ALG_SHA2X "\x60\x86\x48\x01\x65\x03\x04\x02\x00"
76 #define OID_ISO_MEMBER_BODIES "\x2a"
77 #define OID_ISO_IDENTIFIED_ORG "\x2b"
82 #define OID_COUNTRY_US "\x86\x48"
83 #define OID_RSA_DATA_SECURITY "\x86\xf7\x0d"
88 #define OID_OIW_SECSIG_SHA1 "\x0e\x03\x02\x1a"
99 #define ASN1_HASH_MDX \
101 ASN1_STR_CONSTRUCTED_SEQUENCE "\x20" \
102 ASN1_STR_CONSTRUCTED_SEQUENCE "\x0C" \
103 ASN1_STR_OID "\x08" \
105 ASN1_STR_NULL "\x00" \
106 ASN1_STR_OCTET_STRING "\x10" \
109 #define ASN1_HASH_SHA1 \
110 ASN1_STR_CONSTRUCTED_SEQUENCE "\x21" \
111 ASN1_STR_CONSTRUCTED_SEQUENCE "\x09" \
112 ASN1_STR_OID "\x05" \
114 ASN1_STR_NULL "\x00" \
115 ASN1_STR_OCTET_STRING "\x14"
117 #define ASN1_HASH_SHA1_ALT \
118 ASN1_STR_CONSTRUCTED_SEQUENCE "\x1F" \
119 ASN1_STR_CONSTRUCTED_SEQUENCE "\x07" \
120 ASN1_STR_OID "\x05" \
122 ASN1_STR_OCTET_STRING "\x14"
124 #define ASN1_HASH_SHA2X \
125 ASN1_STR_CONSTRUCTED_SEQUENCE "\x11" \
126 ASN1_STR_CONSTRUCTED_SEQUENCE "\x0d" \
127 ASN1_STR_OID "\x09" \
129 ASN1_STR_NULL "\x00" \
130 ASN1_STR_OCTET_STRING "\x00"
199 int (*f_rng)(
void *,
unsigned char *,
size_t),
201 unsigned int nbits,
int exponent );
238 const unsigned char *input,
239 unsigned char *output );
256 int (*f_rng)(
void *,
unsigned char *,
size_t),
258 const unsigned char *input,
259 unsigned char *output );
281 int (*f_rng)(
void *,
unsigned char *,
size_t),
283 int mode,
size_t ilen,
284 const unsigned char *input,
285 unsigned char *output );
304 int (*f_rng)(
void *,
unsigned char *,
size_t),
306 int mode,
size_t ilen,
307 const unsigned char *input,
308 unsigned char *output );
330 int (*f_rng)(
void *,
unsigned char *,
size_t),
333 const unsigned char *label,
size_t label_len,
335 const unsigned char *input,
336 unsigned char *output );
359 int (*f_rng)(
void *,
unsigned char *,
size_t),
361 int mode,
size_t *olen,
362 const unsigned char *input,
363 unsigned char *output,
364 size_t output_max_len );
385 int (*f_rng)(
void *,
unsigned char *,
size_t),
387 int mode,
size_t *olen,
388 const unsigned char *input,
389 unsigned char *output,
390 size_t output_max_len );
413 int (*f_rng)(
void *,
unsigned char *,
size_t),
416 const unsigned char *label,
size_t label_len,
418 const unsigned char *input,
419 unsigned char *output,
420 size_t output_max_len );
450 int (*f_rng)(
void *,
unsigned char *,
size_t),
454 unsigned int hashlen,
455 const unsigned char *hash,
456 unsigned char *sig );
477 int (*f_rng)(
void *,
unsigned char *,
size_t),
481 unsigned int hashlen,
482 const unsigned char *hash,
483 unsigned char *sig );
511 int (*f_rng)(
void *,
unsigned char *,
size_t),
515 unsigned int hashlen,
516 const unsigned char *hash,
517 unsigned char *sig );
546 int (*f_rng)(
void *,
unsigned char *,
size_t),
550 unsigned int hashlen,
551 const unsigned char *hash,
552 unsigned char *sig );
573 int (*f_rng)(
void *,
unsigned char *,
size_t),
577 unsigned int hashlen,
578 const unsigned char *hash,
579 unsigned char *sig );
607 int (*f_rng)(
void *,
unsigned char *,
size_t),
611 unsigned int hashlen,
612 const unsigned char *hash,
613 unsigned char *sig );
int rsa_self_test(int verbose)
Checkup routine.
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_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)
int rsa_pkcs1_sign(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, int hash_id, 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, int hash_id, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Perform a PKCS#1 v1.5 signature (RSASSA-PKCS1-v1_5-SIGN)
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, int hash_id, unsigned int hashlen, const unsigned char *hash, 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.
int rsa_rsassa_pkcs1_v15_verify(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, int hash_id, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Perform a PKCS#1 v1.5 verification (RSASSA-PKCS1-v1_5-VERIFY)
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_rsassa_pss_sign(rsa_context *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, int hash_id, 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, int hash_id, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Generic wrapper to perform a PKCS#1 verification using the mode from the context. ...
int rsa_public(rsa_context *ctx, const unsigned char *input, unsigned char *output)
Do an RSA public key operation.