openssl_sys/
rsa.rs

1use libc::*;
2use std::ptr;
3
4use super::super::*;
5
6pub const RSA_F4: c_long = 0x10001;
7
8cfg_if! {
9    if #[cfg(not(ossl300))] {
10        pub unsafe fn EVP_PKEY_CTX_set_rsa_keygen_bits(ctx: *mut EVP_PKEY_CTX, bits: c_int) -> c_int {
11            EVP_PKEY_CTX_ctrl(
12                ctx,
13                EVP_PKEY_RSA,
14                EVP_PKEY_OP_KEYGEN,
15                EVP_PKEY_CTRL_RSA_KEYGEN_BITS,
16                bits,
17                ptr::null_mut(),
18            )
19        }
20        pub unsafe fn EVP_PKEY_CTX_set_rsa_keygen_pubexp(ctx: *mut EVP_PKEY_CTX, pubexp: *mut BIGNUM) -> c_int {
21            EVP_PKEY_CTX_ctrl(
22                ctx,
23                EVP_PKEY_RSA,
24                EVP_PKEY_OP_KEYGEN,
25                EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP,
26                0,
27                pubexp as *mut _,
28            )
29        }
30        pub unsafe fn EVP_PKEY_CTX_set_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad: c_int) -> c_int {
31            EVP_PKEY_CTX_ctrl(
32                ctx,
33                EVP_PKEY_RSA,
34                -1,
35                EVP_PKEY_CTRL_RSA_PADDING,
36                pad,
37                ptr::null_mut(),
38            )
39        }
40        pub unsafe fn EVP_PKEY_CTX_get_rsa_padding(ctx: *mut EVP_PKEY_CTX, ppad: *mut c_int) -> c_int {
41            EVP_PKEY_CTX_ctrl(
42                ctx,
43                EVP_PKEY_RSA,
44                -1,
45                EVP_PKEY_CTRL_GET_RSA_PADDING,
46                0,
47                ppad as *mut c_void,
48            )
49        }
50
51        pub unsafe fn EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx: *mut EVP_PKEY_CTX, len: c_int) -> c_int {
52            EVP_PKEY_CTX_ctrl(
53                ctx,
54                EVP_PKEY_RSA,
55                EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY,
56                EVP_PKEY_CTRL_RSA_PSS_SALTLEN,
57                len,
58                ptr::null_mut(),
59            )
60        }
61
62        pub unsafe fn EVP_PKEY_CTX_set_rsa_mgf1_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
63            EVP_PKEY_CTX_ctrl(
64                ctx,
65                EVP_PKEY_RSA,
66                EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT,
67                EVP_PKEY_CTRL_RSA_MGF1_MD,
68                0,
69                md as *mut c_void,
70            )
71        }
72    }
73}
74
75pub unsafe fn EVP_PKEY_CTX_set_rsa_oaep_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
76    EVP_PKEY_CTX_ctrl(
77        ctx,
78        EVP_PKEY_RSA,
79        EVP_PKEY_OP_TYPE_CRYPT,
80        EVP_PKEY_CTRL_RSA_OAEP_MD,
81        0,
82        md as *mut c_void,
83    )
84}
85
86pub unsafe fn EVP_PKEY_CTX_set0_rsa_oaep_label(
87    ctx: *mut EVP_PKEY_CTX,
88    label: *mut c_void,
89    len: c_int,
90) -> c_int {
91    EVP_PKEY_CTX_ctrl(
92        ctx,
93        EVP_PKEY_RSA,
94        EVP_PKEY_OP_TYPE_CRYPT,
95        EVP_PKEY_CTRL_RSA_OAEP_LABEL,
96        len,
97        label,
98    )
99}
100
101pub const EVP_PKEY_CTRL_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 1;
102pub const EVP_PKEY_CTRL_RSA_PSS_SALTLEN: c_int = EVP_PKEY_ALG_CTRL + 2;
103pub const EVP_PKEY_CTRL_RSA_KEYGEN_BITS: c_int = EVP_PKEY_ALG_CTRL + 3;
104pub const EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP: c_int = EVP_PKEY_ALG_CTRL + 4;
105
106pub const EVP_PKEY_CTRL_RSA_MGF1_MD: c_int = EVP_PKEY_ALG_CTRL + 5;
107
108pub const EVP_PKEY_CTRL_GET_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 6;
109
110pub const EVP_PKEY_CTRL_RSA_OAEP_MD: c_int = EVP_PKEY_ALG_CTRL + 9;
111pub const EVP_PKEY_CTRL_RSA_OAEP_LABEL: c_int = EVP_PKEY_ALG_CTRL + 10;
112
113pub const RSA_PKCS1_PADDING: c_int = 1;
114#[cfg(not(ossl300))]
115pub const RSA_SSLV23_PADDING: c_int = 2;
116pub const RSA_NO_PADDING: c_int = 3;
117pub const RSA_PKCS1_OAEP_PADDING: c_int = 4;
118pub const RSA_X931_PADDING: c_int = 5;
119pub const RSA_PKCS1_PSS_PADDING: c_int = 6;