dcrypt_api/traits/mod.rs
1//! Trait definitions for cryptographic operations in dcrypt
2//!
3//! This module provides core traits that define the interfaces for various
4//! cryptographic operations, along with marker traits that define algorithm
5//! properties.
6
7#[cfg(not(feature = "std"))]
8use alloc::string::{String, ToString};
9#[cfg(feature = "std")]
10use std::string::{String, ToString};
11
12// Original trait modules
13pub mod kem;
14pub mod pke;
15pub mod serialize;
16pub mod signature;
17pub mod symmetric;
18
19// Original trait re-exports
20pub use kem::Kem;
21pub use pke::Pke;
22pub use serialize::{Serialize, SerializeSecret};
23pub use signature::Signature;
24pub use symmetric::SymmetricCipher;
25
26/// Marker trait for block cipher algorithms
27pub trait BlockCipher {
28 /// Block size in bytes
29 const BLOCK_SIZE: usize;
30
31 /// Static algorithm identifier for compile-time checking
32 const ALGORITHM_ID: &'static str;
33
34 /// Returns the block cipher algorithm name
35 fn name() -> String {
36 Self::ALGORITHM_ID.to_string()
37 }
38}
39
40/// Marker trait for stream cipher algorithms
41pub trait StreamCipher {
42 /// State size in bytes
43 const STATE_SIZE: usize;
44
45 /// Static algorithm identifier for compile-time checking
46 const ALGORITHM_ID: &'static str;
47
48 /// Returns the stream cipher algorithm name
49 fn name() -> String {
50 Self::ALGORITHM_ID.to_string()
51 }
52}
53
54/// Marker trait for authenticated encryption algorithms
55pub trait AuthenticatedCipher {
56 /// Authentication tag size in bytes
57 const TAG_SIZE: usize;
58
59 /// Static algorithm identifier for compile-time checking
60 const ALGORITHM_ID: &'static str;
61
62 /// Returns the authenticated cipher algorithm name
63 fn name() -> String {
64 Self::ALGORITHM_ID.to_string()
65 }
66}
67
68/// Marker trait for key derivation functions
69pub trait KeyDerivationFunction {
70 /// Minimum recommended salt size in bytes
71 const MIN_SALT_SIZE: usize;
72
73 /// Default output size in bytes
74 const DEFAULT_OUTPUT_SIZE: usize;
75
76 /// Static algorithm identifier for compile-time checking
77 const ALGORITHM_ID: &'static str;
78
79 /// Returns the KDF algorithm name
80 fn name() -> String {
81 Self::ALGORITHM_ID.to_string()
82 }
83}
84
85/// Marker trait for hash function algorithms
86pub trait HashAlgorithm {
87 /// Output digest size in bytes
88 const OUTPUT_SIZE: usize;
89
90 /// Block size used by the algorithm in bytes
91 const BLOCK_SIZE: usize;
92
93 /// Static algorithm identifier for compile-time checking
94 const ALGORITHM_ID: &'static str;
95
96 /// Returns the hash algorithm name
97 fn name() -> String {
98 Self::ALGORITHM_ID.to_string()
99 }
100}