1 use libc::*;
2 use std::ptr;
3 
4 use *;
5 
6 pub const RSA_F4: c_long = 0x10001;
7 
EVP_PKEY_CTX_set_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad: c_int) -> c_int8 pub unsafe fn EVP_PKEY_CTX_set_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad: c_int) -> c_int {
9     EVP_PKEY_CTX_ctrl(
10         ctx,
11         EVP_PKEY_RSA,
12         -1,
13         EVP_PKEY_CTRL_RSA_PADDING,
14         pad,
15         ptr::null_mut(),
16     )
17 }
18 
EVP_PKEY_CTX_get_rsa_padding(ctx: *mut EVP_PKEY_CTX, ppad: *mut c_int) -> c_int19 pub unsafe fn EVP_PKEY_CTX_get_rsa_padding(ctx: *mut EVP_PKEY_CTX, ppad: *mut c_int) -> c_int {
20     EVP_PKEY_CTX_ctrl(
21         ctx,
22         EVP_PKEY_RSA,
23         -1,
24         EVP_PKEY_CTRL_GET_RSA_PADDING,
25         0,
26         ppad as *mut c_void,
27     )
28 }
29 
EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx: *mut EVP_PKEY_CTX, len: c_int) -> c_int30 pub unsafe fn EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx: *mut EVP_PKEY_CTX, len: c_int) -> c_int {
31     EVP_PKEY_CTX_ctrl(
32         ctx,
33         EVP_PKEY_RSA,
34         EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY,
35         EVP_PKEY_CTRL_RSA_PSS_SALTLEN,
36         len,
37         ptr::null_mut(),
38     )
39 }
40 
EVP_PKEY_CTX_set_rsa_mgf1_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int41 pub unsafe fn EVP_PKEY_CTX_set_rsa_mgf1_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
42     EVP_PKEY_CTX_ctrl(
43         ctx,
44         EVP_PKEY_RSA,
45         EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT,
46         EVP_PKEY_CTRL_RSA_MGF1_MD,
47         0,
48         md as *mut c_void,
49     )
50 }
51 
52 #[cfg(any(ossl102, libressl310))]
EVP_PKEY_CTX_set_rsa_oaep_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int53 pub unsafe fn EVP_PKEY_CTX_set_rsa_oaep_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
54     EVP_PKEY_CTX_ctrl(
55         ctx,
56         EVP_PKEY_RSA,
57         EVP_PKEY_OP_TYPE_CRYPT,
58         EVP_PKEY_CTRL_RSA_OAEP_MD,
59         0,
60         md as *mut c_void,
61     )
62 }
63 
64 pub const EVP_PKEY_CTRL_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 1;
65 pub const EVP_PKEY_CTRL_RSA_PSS_SALTLEN: c_int = EVP_PKEY_ALG_CTRL + 2;
66 
67 pub const EVP_PKEY_CTRL_RSA_MGF1_MD: c_int = EVP_PKEY_ALG_CTRL + 5;
68 
69 pub const EVP_PKEY_CTRL_GET_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 6;
70 
71 #[cfg(any(ossl102, libressl310))]
72 pub const EVP_PKEY_CTRL_RSA_OAEP_MD: c_int = EVP_PKEY_ALG_CTRL + 9;
73 
74 pub const RSA_PKCS1_PADDING: c_int = 1;
75 pub const RSA_SSLV23_PADDING: c_int = 2;
76 pub const RSA_NO_PADDING: c_int = 3;
77 pub const RSA_PKCS1_OAEP_PADDING: c_int = 4;
78 pub const RSA_X931_PADDING: c_int = 5;
79 pub const RSA_PKCS1_PSS_PADDING: c_int = 6;
80 
81 extern "C" {
RSA_new() -> *mut RSA82     pub fn RSA_new() -> *mut RSA;
RSA_size(k: *const RSA) -> c_int83     pub fn RSA_size(k: *const RSA) -> c_int;
84 
85     #[cfg(any(ossl110, libressl273))]
RSA_set0_key( r: *mut ::RSA, n: *mut ::BIGNUM, e: *mut ::BIGNUM, d: *mut ::BIGNUM, ) -> c_int86     pub fn RSA_set0_key(
87         r: *mut ::RSA,
88         n: *mut ::BIGNUM,
89         e: *mut ::BIGNUM,
90         d: *mut ::BIGNUM,
91     ) -> c_int;
92     #[cfg(any(ossl110, libressl273))]
RSA_set0_factors(r: *mut ::RSA, p: *mut ::BIGNUM, q: *mut ::BIGNUM) -> c_int93     pub fn RSA_set0_factors(r: *mut ::RSA, p: *mut ::BIGNUM, q: *mut ::BIGNUM) -> c_int;
94     #[cfg(any(ossl110, libressl273))]
RSA_set0_crt_params( r: *mut ::RSA, dmp1: *mut ::BIGNUM, dmq1: *mut ::BIGNUM, iqmp: *mut ::BIGNUM, ) -> c_int95     pub fn RSA_set0_crt_params(
96         r: *mut ::RSA,
97         dmp1: *mut ::BIGNUM,
98         dmq1: *mut ::BIGNUM,
99         iqmp: *mut ::BIGNUM,
100     ) -> c_int;
101     #[cfg(any(ossl110, libressl273))]
RSA_get0_key( r: *const ::RSA, n: *mut *const ::BIGNUM, e: *mut *const ::BIGNUM, d: *mut *const ::BIGNUM, )102     pub fn RSA_get0_key(
103         r: *const ::RSA,
104         n: *mut *const ::BIGNUM,
105         e: *mut *const ::BIGNUM,
106         d: *mut *const ::BIGNUM,
107     );
108     #[cfg(any(ossl110, libressl273))]
RSA_get0_factors(r: *const ::RSA, p: *mut *const ::BIGNUM, q: *mut *const ::BIGNUM)109     pub fn RSA_get0_factors(r: *const ::RSA, p: *mut *const ::BIGNUM, q: *mut *const ::BIGNUM);
110     #[cfg(any(ossl110, libressl273))]
RSA_get0_crt_params( r: *const ::RSA, dmp1: *mut *const ::BIGNUM, dmq1: *mut *const ::BIGNUM, iqmp: *mut *const ::BIGNUM, )111     pub fn RSA_get0_crt_params(
112         r: *const ::RSA,
113         dmp1: *mut *const ::BIGNUM,
114         dmq1: *mut *const ::BIGNUM,
115         iqmp: *mut *const ::BIGNUM,
116     );
117 
118     #[cfg(not(ossl110))]
RSA_generate_key( modsz: c_int, e: c_ulong, cb: Option<extern "C" fn(c_int, c_int, *mut c_void)>, cbarg: *mut c_void, ) -> *mut RSA119     pub fn RSA_generate_key(
120         modsz: c_int,
121         e: c_ulong,
122         cb: Option<extern "C" fn(c_int, c_int, *mut c_void)>,
123         cbarg: *mut c_void,
124     ) -> *mut RSA;
125 
RSA_generate_key_ex( rsa: *mut RSA, bits: c_int, e: *mut BIGNUM, cb: *mut BN_GENCB, ) -> c_int126     pub fn RSA_generate_key_ex(
127         rsa: *mut RSA,
128         bits: c_int,
129         e: *mut BIGNUM,
130         cb: *mut BN_GENCB,
131     ) -> c_int;
132 
RSA_public_encrypt( flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int, ) -> c_int133     pub fn RSA_public_encrypt(
134         flen: c_int,
135         from: *const u8,
136         to: *mut u8,
137         k: *mut RSA,
138         pad: c_int,
139     ) -> c_int;
RSA_private_encrypt( flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int, ) -> c_int140     pub fn RSA_private_encrypt(
141         flen: c_int,
142         from: *const u8,
143         to: *mut u8,
144         k: *mut RSA,
145         pad: c_int,
146     ) -> c_int;
RSA_public_decrypt( flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int, ) -> c_int147     pub fn RSA_public_decrypt(
148         flen: c_int,
149         from: *const u8,
150         to: *mut u8,
151         k: *mut RSA,
152         pad: c_int,
153     ) -> c_int;
RSA_private_decrypt( flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int, ) -> c_int154     pub fn RSA_private_decrypt(
155         flen: c_int,
156         from: *const u8,
157         to: *mut u8,
158         k: *mut RSA,
159         pad: c_int,
160     ) -> c_int;
RSA_check_key(r: *const ::RSA) -> c_int161     pub fn RSA_check_key(r: *const ::RSA) -> c_int;
RSA_free(rsa: *mut RSA)162     pub fn RSA_free(rsa: *mut RSA);
RSA_up_ref(rsa: *mut RSA) -> c_int163     pub fn RSA_up_ref(rsa: *mut RSA) -> c_int;
164 
i2d_RSAPublicKey(k: *const RSA, buf: *mut *mut u8) -> c_int165     pub fn i2d_RSAPublicKey(k: *const RSA, buf: *mut *mut u8) -> c_int;
d2i_RSAPublicKey(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA166     pub fn d2i_RSAPublicKey(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;
i2d_RSAPrivateKey(k: *const RSA, buf: *mut *mut u8) -> c_int167     pub fn i2d_RSAPrivateKey(k: *const RSA, buf: *mut *mut u8) -> c_int;
d2i_RSAPrivateKey(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA168     pub fn d2i_RSAPrivateKey(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;
169 
RSA_sign( t: c_int, m: *const u8, mlen: c_uint, sig: *mut u8, siglen: *mut c_uint, k: *mut RSA, ) -> c_int170     pub fn RSA_sign(
171         t: c_int,
172         m: *const u8,
173         mlen: c_uint,
174         sig: *mut u8,
175         siglen: *mut c_uint,
176         k: *mut RSA,
177     ) -> c_int;
RSA_verify( t: c_int, m: *const u8, mlen: c_uint, sig: *const u8, siglen: c_uint, k: *mut RSA, ) -> c_int178     pub fn RSA_verify(
179         t: c_int,
180         m: *const u8,
181         mlen: c_uint,
182         sig: *const u8,
183         siglen: c_uint,
184         k: *mut RSA,
185     ) -> c_int;
186 
RSA_padding_check_PKCS1_type_2( to: *mut c_uchar, tlen: c_int, f: *const c_uchar, fl: c_int, rsa_len: c_int, ) -> c_int187     pub fn RSA_padding_check_PKCS1_type_2(
188         to: *mut c_uchar,
189         tlen: c_int,
190         f: *const c_uchar,
191         fl: c_int,
192         rsa_len: c_int,
193     ) -> c_int;
194 }
195