• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use super::*;
2 use libc::*;
3 use std::ptr;
4 
5 #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
6 pub const SHA_LBLOCK: c_int = 16;
7 
8 #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
9 pub type SHA_LONG = c_uint;
10 
11 cfg_if! {
12     if #[cfg(ossl300)] {
13         #[cfg(ossl300)]
14         // Ideally we'd macro define these, but that crashes ctest :(
15         pub unsafe fn SHA1(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
16             if EVP_Q_digest(
17                 ptr::null_mut(),
18                 "SHA1\0".as_ptr() as *const c_char,
19                 ptr::null(),
20                 d as *const c_void,
21                 n,
22                 md,
23                 ptr::null_mut(),
24             ) != 0
25             {
26                 md
27             } else {
28                 ptr::null_mut()
29             }
30         }
31 
32         pub unsafe fn SHA224(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
33             if EVP_Q_digest(
34                 ptr::null_mut(),
35                 "SHA224\0".as_ptr() as *const c_char,
36                 ptr::null(),
37                 d as *const c_void,
38                 n,
39                 md,
40                 ptr::null_mut(),
41             ) != 0 {
42                 md
43             } else {
44                 ptr::null_mut()
45             }
46         }
47 
48         pub unsafe fn SHA256(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
49             if EVP_Q_digest(
50                 ptr::null_mut(),
51                 "SHA256\0".as_ptr() as *const c_char,
52                 ptr::null(),
53                 d as *const c_void,
54                 n,
55                 md,
56                 ptr::null_mut(),
57             ) != 0 {
58                 md
59             } else {
60                 ptr::null_mut()
61             }
62         }
63     }
64 }
65 
66 #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
67 pub type SHA_LONG64 = u64;
68 
69 cfg_if! {
70     if #[cfg(ossl300)] {
71         pub unsafe fn SHA384(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
72             if EVP_Q_digest(
73                 ptr::null_mut(),
74                 "SHA384\0".as_ptr() as *const c_char,
75                 ptr::null(),
76                 d as *const c_void,
77                 n,
78                 md,
79                 ptr::null_mut(),
80             ) != 0 {
81                 md
82             } else {
83                 ptr::null_mut()
84             }
85         }
86 
87         pub unsafe fn SHA512(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar {
88             if EVP_Q_digest(
89                 ptr::null_mut(),
90                 "SHA512\0".as_ptr() as *const c_char,
91                 ptr::null(),
92                 d as *const c_void,
93                 n,
94                 md,
95                 ptr::null_mut(),
96             ) != 0 {
97                 md
98             } else {
99                 ptr::null_mut()
100             }
101         }
102     }
103 }
104