mbedtls_platform_support/
self_test.rs1use mbedtls_sys::types::raw_types::{c_char, c_int};
22
23cfg_if::cfg_if! {
24 if #[cfg(feature = "std")] {
25 #[doc(hidden)]
27 #[no_mangle]
28 pub unsafe extern "C" fn mbedtls_log(msg: *const std::os::raw::c_char) {
29 print!("{}", std::ffi::CStr::from_ptr(msg).to_string_lossy());
30 }
31 } else {
32 #[allow(non_upper_case_globals)]
33 static mut log_f: Option<unsafe fn(*const c_char)> = None;
34
35 #[doc(hidden)]
37 #[no_mangle]
38 pub unsafe extern "C" fn mbedtls_log(msg: *const c_char) {
39 log_f.expect("Called self-test log without enabling self-test")(msg)
40 }
41 }
42}
43
44#[cfg(any(not(feature = "std"), target_env = "sgx"))]
45#[allow(non_upper_case_globals)]
46static mut rand_f: Option<fn() -> c_int> = None;
47
48#[cfg(all(any(not(feature = "std"), target_env = "sgx"), not(target_env = "msvc")))]
50#[doc(hidden)]
51#[no_mangle]
52pub unsafe extern "C" fn rand() -> c_int {
53 rand_f.expect("Called self-test rand without enabling self-test")()
54}
55
56#[allow(unused)]
68pub unsafe fn enable(rand: fn() -> c_int, log: Option<unsafe fn(*const c_char)>) {
69 #[cfg(any(not(feature = "std"), target_env = "sgx"))] {
70 rand_f = Some(rand);
71 }
72 #[cfg(not(feature = "std"))] {
73 log_f = log;
74 }
75}
76
77pub unsafe fn disable() {
82 #[cfg(any(not(feature = "std"), target_env = "sgx"))] {
83 rand_f = None;
84 }
85 #[cfg(not(feature = "std"))] {
86 log_f = None;
87 }
88}
89
90pub use mbedtls_sys::{
96 aes_self_test as aes, arc4_self_test as arc4, aria_self_test as aria, base64_self_test as base64,
97 camellia_self_test as camellia, ccm_self_test as ccm, ctr_drbg_self_test as ctr_drbg,
98 des_self_test as des, dhm_self_test as dhm, ecjpake_self_test as ecjpake, ecp_self_test as ecp,
99 entropy_self_test as entropy, gcm_self_test as gcm, hmac_drbg_self_test as hmac_drbg,
100 md2_self_test as md2, md4_self_test as md4, md5_self_test as md5, mpi_self_test as mpi,
101 pkcs5_self_test as pkcs5, ripemd160_self_test as ripemd160, rsa_self_test as rsa,
102 sha1_self_test as sha1, sha256_self_test as sha256, sha512_self_test as sha512,
103 x509_self_test as x509, xtea_self_test as xtea, nist_kw_self_test as nist_kw, cmac_self_test as cmac
104};