1 use libc::*;
2 use std::ptr;
3 
4 use *;
5 
6 pub const RSA_F4: c_long = 0x10001;
7 
8 cfg_if! {
9     if #[cfg(ossl300)] {
10         extern "C" {
11             pub fn EVP_PKEY_CTX_set_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad_mode: c_int) -> c_int;
12             pub fn EVP_PKEY_CTX_get_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad_mode: *mut c_int) -> c_int;
13 
14             pub fn EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx: *mut EVP_PKEY_CTX, len: c_int) -> c_int;
15             pub fn EVP_PKEY_CTX_set_rsa_mgf1_md(ctx: *mut EVP_PKEY_CTX, md: *const EVP_MD) -> c_int;
16         }
17     } else {
18         pub unsafe fn EVP_PKEY_CTX_set_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad: c_int) -> c_int {
19             EVP_PKEY_CTX_ctrl(
20                 ctx,
21                 EVP_PKEY_RSA,
22                 -1,
23                 EVP_PKEY_CTRL_RSA_PADDING,
24                 pad,
25                 ptr::null_mut(),
26             )
27         }
28         pub unsafe fn EVP_PKEY_CTX_get_rsa_padding(ctx: *mut EVP_PKEY_CTX, ppad: *mut c_int) -> c_int {
29             EVP_PKEY_CTX_ctrl(
30                 ctx,
31                 EVP_PKEY_RSA,
32                 -1,
33                 EVP_PKEY_CTRL_GET_RSA_PADDING,
34                 0,
35                 ppad as *mut c_void,
36             )
37         }
38 
39         pub unsafe fn EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx: *mut EVP_PKEY_CTX, len: c_int) -> c_int {
40             EVP_PKEY_CTX_ctrl(
41                 ctx,
42                 EVP_PKEY_RSA,
43                 EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY,
44                 EVP_PKEY_CTRL_RSA_PSS_SALTLEN,
45                 len,
46                 ptr::null_mut(),
47             )
48         }
49 
50         pub unsafe fn EVP_PKEY_CTX_set_rsa_mgf1_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
51             EVP_PKEY_CTX_ctrl(
52                 ctx,
53                 EVP_PKEY_RSA,
54                 EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT,
55                 EVP_PKEY_CTRL_RSA_MGF1_MD,
56                 0,
57                 md as *mut c_void,
58             )
59         }
60     }
61 }
62 
63 #[cfg(any(ossl102, libressl310))]
EVP_PKEY_CTX_set_rsa_oaep_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int64 pub unsafe fn EVP_PKEY_CTX_set_rsa_oaep_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
65     EVP_PKEY_CTX_ctrl(
66         ctx,
67         EVP_PKEY_RSA,
68         EVP_PKEY_OP_TYPE_CRYPT,
69         EVP_PKEY_CTRL_RSA_OAEP_MD,
70         0,
71         md as *mut c_void,
72     )
73 }
74 
75 #[cfg(any(ossl102, libressl310))]
EVP_PKEY_CTX_set0_rsa_oaep_label( ctx: *mut EVP_PKEY_CTX, label: *mut c_void, len: c_int, ) -> c_int76 pub unsafe fn EVP_PKEY_CTX_set0_rsa_oaep_label(
77     ctx: *mut EVP_PKEY_CTX,
78     label: *mut c_void,
79     len: c_int,
80 ) -> c_int {
81     EVP_PKEY_CTX_ctrl(
82         ctx,
83         EVP_PKEY_RSA,
84         EVP_PKEY_OP_TYPE_CRYPT,
85         EVP_PKEY_CTRL_RSA_OAEP_LABEL,
86         len,
87         label as *mut c_void,
88     )
89 }
90 
91 pub const EVP_PKEY_CTRL_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 1;
92 pub const EVP_PKEY_CTRL_RSA_PSS_SALTLEN: c_int = EVP_PKEY_ALG_CTRL + 2;
93 
94 pub const EVP_PKEY_CTRL_RSA_MGF1_MD: c_int = EVP_PKEY_ALG_CTRL + 5;
95 
96 pub const EVP_PKEY_CTRL_GET_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 6;
97 
98 #[cfg(any(ossl102, libressl310))]
99 pub const EVP_PKEY_CTRL_RSA_OAEP_MD: c_int = EVP_PKEY_ALG_CTRL + 9;
100 #[cfg(any(ossl102, libressl310))]
101 pub const EVP_PKEY_CTRL_RSA_OAEP_LABEL: c_int = EVP_PKEY_ALG_CTRL + 10;
102 
103 pub const RSA_PKCS1_PADDING: c_int = 1;
104 #[cfg(not(ossl300))]
105 pub const RSA_SSLV23_PADDING: c_int = 2;
106 pub const RSA_NO_PADDING: c_int = 3;
107 pub const RSA_PKCS1_OAEP_PADDING: c_int = 4;
108 pub const RSA_X931_PADDING: c_int = 5;
109 pub const RSA_PKCS1_PSS_PADDING: c_int = 6;
110 
111 extern "C" {
RSA_new() -> *mut RSA112     pub fn RSA_new() -> *mut RSA;
RSA_size(k: *const RSA) -> c_int113     pub fn RSA_size(k: *const RSA) -> c_int;
114 
115     #[cfg(any(ossl110, libressl273))]
RSA_set0_key( r: *mut ::RSA, n: *mut ::BIGNUM, e: *mut ::BIGNUM, d: *mut ::BIGNUM, ) -> c_int116     pub fn RSA_set0_key(
117         r: *mut ::RSA,
118         n: *mut ::BIGNUM,
119         e: *mut ::BIGNUM,
120         d: *mut ::BIGNUM,
121     ) -> c_int;
122     #[cfg(any(ossl110, libressl273))]
RSA_set0_factors(r: *mut ::RSA, p: *mut ::BIGNUM, q: *mut ::BIGNUM) -> c_int123     pub fn RSA_set0_factors(r: *mut ::RSA, p: *mut ::BIGNUM, q: *mut ::BIGNUM) -> c_int;
124     #[cfg(any(ossl110, libressl273))]
RSA_set0_crt_params( r: *mut ::RSA, dmp1: *mut ::BIGNUM, dmq1: *mut ::BIGNUM, iqmp: *mut ::BIGNUM, ) -> c_int125     pub fn RSA_set0_crt_params(
126         r: *mut ::RSA,
127         dmp1: *mut ::BIGNUM,
128         dmq1: *mut ::BIGNUM,
129         iqmp: *mut ::BIGNUM,
130     ) -> c_int;
131     #[cfg(any(ossl110, libressl273))]
RSA_get0_key( r: *const ::RSA, n: *mut *const ::BIGNUM, e: *mut *const ::BIGNUM, d: *mut *const ::BIGNUM, )132     pub fn RSA_get0_key(
133         r: *const ::RSA,
134         n: *mut *const ::BIGNUM,
135         e: *mut *const ::BIGNUM,
136         d: *mut *const ::BIGNUM,
137     );
138     #[cfg(any(ossl110, libressl273))]
RSA_get0_factors(r: *const ::RSA, p: *mut *const ::BIGNUM, q: *mut *const ::BIGNUM)139     pub fn RSA_get0_factors(r: *const ::RSA, p: *mut *const ::BIGNUM, q: *mut *const ::BIGNUM);
140     #[cfg(any(ossl110, libressl273))]
RSA_get0_crt_params( r: *const ::RSA, dmp1: *mut *const ::BIGNUM, dmq1: *mut *const ::BIGNUM, iqmp: *mut *const ::BIGNUM, )141     pub fn RSA_get0_crt_params(
142         r: *const ::RSA,
143         dmp1: *mut *const ::BIGNUM,
144         dmq1: *mut *const ::BIGNUM,
145         iqmp: *mut *const ::BIGNUM,
146     );
147 
148     #[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 RSA149     pub fn RSA_generate_key(
150         modsz: c_int,
151         e: c_ulong,
152         cb: Option<extern "C" fn(c_int, c_int, *mut c_void)>,
153         cbarg: *mut c_void,
154     ) -> *mut RSA;
155 
RSA_generate_key_ex( rsa: *mut RSA, bits: c_int, e: *mut BIGNUM, cb: *mut BN_GENCB, ) -> c_int156     pub fn RSA_generate_key_ex(
157         rsa: *mut RSA,
158         bits: c_int,
159         e: *mut BIGNUM,
160         cb: *mut BN_GENCB,
161     ) -> c_int;
162 
RSA_public_encrypt( flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int, ) -> c_int163     pub fn RSA_public_encrypt(
164         flen: c_int,
165         from: *const u8,
166         to: *mut u8,
167         k: *mut RSA,
168         pad: c_int,
169     ) -> c_int;
RSA_private_encrypt( flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int, ) -> c_int170     pub fn RSA_private_encrypt(
171         flen: c_int,
172         from: *const u8,
173         to: *mut u8,
174         k: *mut RSA,
175         pad: c_int,
176     ) -> c_int;
RSA_public_decrypt( flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int, ) -> c_int177     pub fn RSA_public_decrypt(
178         flen: c_int,
179         from: *const u8,
180         to: *mut u8,
181         k: *mut RSA,
182         pad: c_int,
183     ) -> c_int;
RSA_private_decrypt( flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int, ) -> c_int184     pub fn RSA_private_decrypt(
185         flen: c_int,
186         from: *const u8,
187         to: *mut u8,
188         k: *mut RSA,
189         pad: c_int,
190     ) -> c_int;
RSA_check_key(r: *const ::RSA) -> c_int191     pub fn RSA_check_key(r: *const ::RSA) -> c_int;
RSA_free(rsa: *mut RSA)192     pub fn RSA_free(rsa: *mut RSA);
RSA_up_ref(rsa: *mut RSA) -> c_int193     pub fn RSA_up_ref(rsa: *mut RSA) -> c_int;
194 
i2d_RSAPublicKey(k: *const RSA, buf: *mut *mut u8) -> c_int195     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 RSA196     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_int197     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 RSA198     pub fn d2i_RSAPrivateKey(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;
199 
RSA_sign( t: c_int, m: *const u8, mlen: c_uint, sig: *mut u8, siglen: *mut c_uint, k: *mut RSA, ) -> c_int200     pub fn RSA_sign(
201         t: c_int,
202         m: *const u8,
203         mlen: c_uint,
204         sig: *mut u8,
205         siglen: *mut c_uint,
206         k: *mut RSA,
207     ) -> c_int;
RSA_verify( t: c_int, m: *const u8, mlen: c_uint, sig: *const u8, siglen: c_uint, k: *mut RSA, ) -> c_int208     pub fn RSA_verify(
209         t: c_int,
210         m: *const u8,
211         mlen: c_uint,
212         sig: *const u8,
213         siglen: c_uint,
214         k: *mut RSA,
215     ) -> c_int;
216 
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_int217     pub fn RSA_padding_check_PKCS1_type_2(
218         to: *mut c_uchar,
219         tlen: c_int,
220         f: *const c_uchar,
221         fl: c_int,
222         rsa_len: c_int,
223     ) -> c_int;
224 }
225