kipuka_hsm/providers/
kryoptic.rs1use crate::HsmProvider;
32use crate::providers::HsmProviderConfig;
33use cryptoki::mechanism::MechanismType;
34
35pub fn default_library_path() -> &'static str {
40 #[cfg(target_os = "linux")]
42 return "/usr/local/lib/libkryoptic.so";
43
44 #[cfg(target_os = "macos")]
45 return "/usr/local/lib/libkryoptic.dylib";
46
47 #[cfg(target_os = "windows")]
48 return "C:\\Program Files\\Kryoptic\\kryoptic.dll";
49
50 #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
51 return "/usr/local/lib/libkryoptic.so";
52}
53
54pub fn supported_mechanisms() -> Vec<MechanismType> {
58 vec![
59 MechanismType::RSA_PKCS,
61 MechanismType::RSA_PKCS_KEY_PAIR_GEN,
62 MechanismType::SHA256_RSA_PKCS,
63 MechanismType::SHA384_RSA_PKCS,
64 MechanismType::SHA512_RSA_PKCS,
65 MechanismType::RSA_PKCS_PSS,
66 MechanismType::SHA256_RSA_PKCS_PSS,
67 MechanismType::SHA384_RSA_PKCS_PSS,
68 MechanismType::SHA512_RSA_PKCS_PSS,
69 MechanismType::RSA_PKCS_OAEP,
70 MechanismType::ECDSA,
72 MechanismType::ECDSA_SHA256,
73 MechanismType::ECDSA_SHA384,
74 MechanismType::ECDSA_SHA512,
75 MechanismType::ECC_KEY_PAIR_GEN,
76 MechanismType::AES_KEY_GEN,
78 MechanismType::AES_ECB,
79 MechanismType::AES_CBC,
80 MechanismType::AES_GCM,
81 MechanismType::AES_KEY_WRAP,
82 MechanismType::AES_KEY_WRAP_PAD,
83 MechanismType::SHA256,
85 MechanismType::SHA384,
86 MechanismType::SHA512,
87 ]
88}
89
90pub fn provider_config() -> HsmProviderConfig {
92 HsmProviderConfig {
93 provider: HsmProvider::Kryoptic,
94 library_path: default_library_path().to_string(),
95 supported_mechanisms: supported_mechanisms(),
96 notes: vec![
97 "Software-only FIPS 140-3 module - NOT for production HSM requirements".to_string(),
98 "No hardware tamper protection or physical key storage".to_string(),
99 "Excellent for development and testing".to_string(),
100 "Set KRYOPTIC_PKCS11_MODULE environment variable to override library path".to_string(),
101 ],
102 }
103}
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108
109 #[test]
110 fn test_library_path_not_empty() {
111 assert!(!default_library_path().is_empty());
112 }
113
114 #[test]
115 fn test_mechanisms_supported() {
116 let mechanisms = supported_mechanisms();
117 assert!(mechanisms.contains(&MechanismType::RSA_PKCS));
118 assert!(mechanisms.contains(&MechanismType::ECDSA));
119 }
120}