1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use super::*;
use libc::*;
use std::ptr;

#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
pub const SHA_LBLOCK: c_int = 16;

#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
pub type SHA_LONG = c_uint;

cfg_if! {
    if #[cfg(ossl300)] {
        #[cfg(ossl300)]
        // Ideally we'd macro define these, but that crashes ctest :(
        pub unsafe fn SHA1(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
            if EVP_Q_digest(
                ptr::null_mut(),
                "SHA1\0".as_ptr() as *const c_char,
                ptr::null(),
                d as *const c_void,
                n,
                md,
                ptr::null_mut(),
            ) != 0
            {
                md
            } else {
                ptr::null_mut()
            }
        }

        pub unsafe fn SHA224(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
            if EVP_Q_digest(
                ptr::null_mut(),
                "SHA224\0".as_ptr() as *const c_char,
                ptr::null(),
                d as *const c_void,
                n,
                md,
                ptr::null_mut(),
            ) != 0 {
                md
            } else {
                ptr::null_mut()
            }
        }

        pub unsafe fn SHA256(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
            if EVP_Q_digest(
                ptr::null_mut(),
                "SHA256\0".as_ptr() as *const c_char,
                ptr::null(),
                d as *const c_void,
                n,
                md,
                ptr::null_mut(),
            ) != 0 {
                md
            } else {
                ptr::null_mut()
            }
        }
    }
}

#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
pub type SHA_LONG64 = u64;

cfg_if! {
    if #[cfg(ossl300)] {
        pub unsafe fn SHA384(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
            if EVP_Q_digest(
                ptr::null_mut(),
                "SHA384\0".as_ptr() as *const c_char,
                ptr::null(),
                d as *const c_void,
                n,
                md,
                ptr::null_mut(),
            ) != 0 {
                md
            } else {
                ptr::null_mut()
            }
        }

        pub unsafe fn SHA512(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
            if EVP_Q_digest(
                ptr::null_mut(),
                "SHA512\0".as_ptr() as *const c_char,
                ptr::null(),
                d as *const c_void,
                n,
                md,
                ptr::null_mut(),
            ) != 0 {
                md
            } else {
                ptr::null_mut()
            }
        }
    }
}