Document the RSA library.
[openssl.git] / doc / crypto / rsa.pod
1 =pod
2
3 =head1 NAME
4
5 rsa - RSA public key cryptosystem
6
7 =head1 SYNOPSIS
8
9  #include <openssl/rsa.h>
10
11  RSA * RSA_new(void);
12
13  void RSA_free(RSA *rsa);
14
15  int RSA_public_encrypt(int flen, unsigned char *from,
16     unsigned char *to, RSA *rsa, int padding);
17
18  int RSA_private_decrypt(int flen, unsigned char *from,
19     unsigned char *to, RSA *rsa, int padding);
20
21  int RSA_sign(int type, unsigned char *m, unsigned int m_len,
22     unsigned char *sigret, unsigned int *siglen, RSA *rsa);
23
24  int RSA_verify(int type, unsigned char *m, unsigned int m_len,
25     unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
26
27  int RSA_size(RSA *rsa);
28
29  RSA *RSA_generate_key(int num, unsigned long e,
30     void (*callback)(int,int,void *), void *cb_arg);
31
32  int RSA_check_key(RSA *rsa);
33
34  int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
35
36  void RSA_blinding_off(RSA *rsa);
37
38  void RSA_set_default_method(RSA_METHOD *meth);
39
40  RSA_METHOD *RSA_get_default_method(void);
41
42  RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
43
44  RSA_METHOD *RSA_get_method(RSA *rsa);
45
46  RSA_METHOD *RSA_PKCS1_SSLeay(void);
47
48  RSA_METHOD *RSA_PKCS1_RSAref(void);
49
50  RSA_METHOD *RSA_null_method(void);
51
52  int RSA_flags(RSA *rsa);
53
54  RSA *RSA_new_method(RSA_METHOD *method);
55
56  int RSA_print(BIO *bp, RSA *x, int offset);
57
58  int RSA_print_fp(FILE *fp, RSA *x, int offset);
59
60  int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
61     int (*dup_func)(), void (*free_func)());
62
63  int RSA_set_ex_data(RSA *r,int idx,char *arg);
64
65  char *RSA_get_ex_data(RSA *r, int idx);
66
67  int RSA_private_encrypt(int flen, unsigned char *from,
68     unsigned char *to, RSA *rsa,int padding);
69
70  int RSA_public_decrypt(int flen, unsigned char *from, 
71     unsigned char *to, RSA *rsa,int padding);
72
73  int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
74     unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
75     RSA *rsa);
76
77  int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
78     unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
79     RSA *rsa);
80
81  int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
82     unsigned char *f, int fl);
83
84  int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
85     unsigned char *f, int fl, int rsa_len);
86
87  int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
88     unsigned char *f, int fl);
89
90  int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
91     unsigned char *f, int fl, int rsa_len);
92
93  int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
94     unsigned char *f, int fl, unsigned char *p, int pl);
95
96  int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
97     unsigned char *f, int fl, int rsa_len, unsigned char *p, int pl);
98
99  int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
100     unsigned char *f, int fl);
101
102  int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
103     unsigned char *f, int fl, int rsa_len);
104
105  int RSA_padding_add_none(unsigned char *to, int tlen,
106     unsigned char *f, int fl);
107
108  int RSA_padding_check_none(unsigned char *to, int tlen,
109     unsigned char *f, int fl, int rsa_len);
110
111
112 =head1 DESCRIPTION
113
114 These functions implement RSA public key encryption and signatures
115 as defined in PKCS #1 v2.0 [RFC 2437].
116
117 The B<RSA> structure consists of several BIGNUM components. It can
118 contain public as well as private RSA keys:
119
120  struct
121         {
122         BIGNUM *n;              // public modulus
123         BIGNUM *e;              // public exponent
124         BIGNUM *d;              // private exponent
125         BIGNUM *p;              // secret prime factor
126         BIGNUM *q;              // secret prime factor
127         BIGNUM *dmp1;           // d mod (p-1)
128         BIGNUM *dmq1;           // d mod (q-1)
129         BIGNUM *iqmp;           // q^-1 mod p
130         // ...
131         };
132  RSA
133
134 In public keys, the private exponent and the related secret values are
135 B<NULL>.
136
137 B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private keys, but the
138 RSA operations are much faster when these values are available.
139
140 =head1 PATENTS
141
142 RSA is covered by a US patent which expires in September 2000.
143
144 =head1 SEE ALSO
145
146 rsa(1), bn(3), dsa(3), dh(3), rand(3), RSA_new(3),
147 RSA_public_encrypt(3), RSA_sign(3), RSA_size(3), RSA_generate_key(3),
148 RSA_check_key(3), RSA_blinding_on(3), RSA_set_method(3), RSA_print(3),
149 RSA_get_ex_new_index(3), RSA_private_encrypt(3),
150 RSA_sign_ASN_OCTET_STRING(3), RSA_padding_add_PKCS1_type_1(3)
151
152 =cut