xref: /onnv-gate/usr/src/common/openssl/doc/crypto/rsa.pod (revision 2175:b0b2f052a486)
1*2175Sjp161948=pod
2*2175Sjp161948
3*2175Sjp161948=head1 NAME
4*2175Sjp161948
5*2175Sjp161948rsa - RSA public key cryptosystem
6*2175Sjp161948
7*2175Sjp161948=head1 SYNOPSIS
8*2175Sjp161948
9*2175Sjp161948 #include <openssl/rsa.h>
10*2175Sjp161948 #include <openssl/engine.h>
11*2175Sjp161948
12*2175Sjp161948 RSA * RSA_new(void);
13*2175Sjp161948 void RSA_free(RSA *rsa);
14*2175Sjp161948
15*2175Sjp161948 int RSA_public_encrypt(int flen, unsigned char *from,
16*2175Sjp161948    unsigned char *to, RSA *rsa, int padding);
17*2175Sjp161948 int RSA_private_decrypt(int flen, unsigned char *from,
18*2175Sjp161948    unsigned char *to, RSA *rsa, int padding);
19*2175Sjp161948 int RSA_private_encrypt(int flen, unsigned char *from,
20*2175Sjp161948    unsigned char *to, RSA *rsa,int padding);
21*2175Sjp161948 int RSA_public_decrypt(int flen, unsigned char *from,
22*2175Sjp161948    unsigned char *to, RSA *rsa,int padding);
23*2175Sjp161948
24*2175Sjp161948 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
25*2175Sjp161948    unsigned char *sigret, unsigned int *siglen, RSA *rsa);
26*2175Sjp161948 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
27*2175Sjp161948    unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
28*2175Sjp161948
29*2175Sjp161948 int RSA_size(const RSA *rsa);
30*2175Sjp161948
31*2175Sjp161948 RSA *RSA_generate_key(int num, unsigned long e,
32*2175Sjp161948    void (*callback)(int,int,void *), void *cb_arg);
33*2175Sjp161948
34*2175Sjp161948 int RSA_check_key(RSA *rsa);
35*2175Sjp161948
36*2175Sjp161948 int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
37*2175Sjp161948 void RSA_blinding_off(RSA *rsa);
38*2175Sjp161948
39*2175Sjp161948 void RSA_set_default_method(const RSA_METHOD *meth);
40*2175Sjp161948 const RSA_METHOD *RSA_get_default_method(void);
41*2175Sjp161948 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
42*2175Sjp161948 const RSA_METHOD *RSA_get_method(const RSA *rsa);
43*2175Sjp161948 RSA_METHOD *RSA_PKCS1_SSLeay(void);
44*2175Sjp161948 RSA_METHOD *RSA_null_method(void);
45*2175Sjp161948 int RSA_flags(const RSA *rsa);
46*2175Sjp161948 RSA *RSA_new_method(ENGINE *engine);
47*2175Sjp161948
48*2175Sjp161948 int RSA_print(BIO *bp, RSA *x, int offset);
49*2175Sjp161948 int RSA_print_fp(FILE *fp, RSA *x, int offset);
50*2175Sjp161948
51*2175Sjp161948 int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
52*2175Sjp161948    int (*dup_func)(), void (*free_func)());
53*2175Sjp161948 int RSA_set_ex_data(RSA *r,int idx,char *arg);
54*2175Sjp161948 char *RSA_get_ex_data(RSA *r, int idx);
55*2175Sjp161948
56*2175Sjp161948 int RSA_sign_ASN1_OCTET_STRING(int dummy, unsigned char *m,
57*2175Sjp161948    unsigned int m_len, unsigned char *sigret, unsigned int *siglen,
58*2175Sjp161948    RSA *rsa);
59*2175Sjp161948 int RSA_verify_ASN1_OCTET_STRING(int dummy, unsigned char *m,
60*2175Sjp161948    unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
61*2175Sjp161948    RSA *rsa);
62*2175Sjp161948
63*2175Sjp161948=head1 DESCRIPTION
64*2175Sjp161948
65*2175Sjp161948These functions implement RSA public key encryption and signatures
66*2175Sjp161948as defined in PKCS #1 v2.0 [RFC 2437].
67*2175Sjp161948
68*2175Sjp161948The B<RSA> structure consists of several BIGNUM components. It can
69*2175Sjp161948contain public as well as private RSA keys:
70*2175Sjp161948
71*2175Sjp161948 struct
72*2175Sjp161948        {
73*2175Sjp161948        BIGNUM *n;		// public modulus
74*2175Sjp161948        BIGNUM *e;		// public exponent
75*2175Sjp161948        BIGNUM *d;		// private exponent
76*2175Sjp161948        BIGNUM *p;		// secret prime factor
77*2175Sjp161948        BIGNUM *q;		// secret prime factor
78*2175Sjp161948        BIGNUM *dmp1;		// d mod (p-1)
79*2175Sjp161948        BIGNUM *dmq1;		// d mod (q-1)
80*2175Sjp161948        BIGNUM *iqmp;		// q^-1 mod p
81*2175Sjp161948	// ...
82*2175Sjp161948        };
83*2175Sjp161948 RSA
84*2175Sjp161948
85*2175Sjp161948In public keys, the private exponent and the related secret values are
86*2175Sjp161948B<NULL>.
87*2175Sjp161948
88*2175Sjp161948B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp> may be B<NULL> in private
89*2175Sjp161948keys, but the RSA operations are much faster when these values are
90*2175Sjp161948available.
91*2175Sjp161948
92*2175Sjp161948Note that RSA keys may use non-standard B<RSA_METHOD> implementations,
93*2175Sjp161948either directly or by the use of B<ENGINE> modules. In some cases (eg. an
94*2175Sjp161948ENGINE providing support for hardware-embedded keys), these BIGNUM values
95*2175Sjp161948will not be used by the implementation or may be used for alternative data
96*2175Sjp161948storage. For this reason, applications should generally avoid using RSA
97*2175Sjp161948structure elements directly and instead use API functions to query or
98*2175Sjp161948modify keys.
99*2175Sjp161948
100*2175Sjp161948=head1 CONFORMING TO
101*2175Sjp161948
102*2175Sjp161948SSL, PKCS #1 v2.0
103*2175Sjp161948
104*2175Sjp161948=head1 PATENTS
105*2175Sjp161948
106*2175Sjp161948RSA was covered by a US patent which expired in September 2000.
107*2175Sjp161948
108*2175Sjp161948=head1 SEE ALSO
109*2175Sjp161948
110*2175Sjp161948L<rsa(1)|rsa(1)>, L<bn(3)|bn(3)>, L<dsa(3)|dsa(3)>, L<dh(3)|dh(3)>,
111*2175Sjp161948L<rand(3)|rand(3)>, L<engine(3)|engine(3)>, L<RSA_new(3)|RSA_new(3)>,
112*2175Sjp161948L<RSA_public_encrypt(3)|RSA_public_encrypt(3)>,
113*2175Sjp161948L<RSA_sign(3)|RSA_sign(3)>, L<RSA_size(3)|RSA_size(3)>,
114*2175Sjp161948L<RSA_generate_key(3)|RSA_generate_key(3)>,
115*2175Sjp161948L<RSA_check_key(3)|RSA_check_key(3)>,
116*2175Sjp161948L<RSA_blinding_on(3)|RSA_blinding_on(3)>,
117*2175Sjp161948L<RSA_set_method(3)|RSA_set_method(3)>, L<RSA_print(3)|RSA_print(3)>,
118*2175Sjp161948L<RSA_get_ex_new_index(3)|RSA_get_ex_new_index(3)>,
119*2175Sjp161948L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>,
120*2175Sjp161948L<RSA_sign_ASN1_OCTET_STRING(3)|RSA_sign_ASN1_OCTET_STRING(3)>,
121*2175Sjp161948L<RSA_padding_add_PKCS1_type_1(3)|RSA_padding_add_PKCS1_type_1(3)>
122*2175Sjp161948
123*2175Sjp161948=cut
124