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// Original trait modules
8pub mod kem;
9pub mod pke;
10pub mod serialize;
11pub mod signature;
12pub mod symmetric;
13
14// Original trait re-exports
15pub use kem::Kem;
16pub use pke::Pke;
17pub use serialize::{Serialize, SerializeSecret};
18pub use signature::Signature;
19pub use symmetric::SymmetricCipher;
20
21/// Marker trait for block cipher algorithms
22pub trait BlockCipher {
23 /// Block size in bytes
24 const BLOCK_SIZE: usize;
25
26 /// Static algorithm identifier for compile-time checking
27 const ALGORITHM_ID: &'static str;
28
29 /// Returns the block cipher algorithm name
30 fn name() -> String {
31 Self::ALGORITHM_ID.to_string()
32 }
33}
34
35/// Marker trait for stream cipher algorithms
36pub trait StreamCipher {
37 /// State size in bytes
38 const STATE_SIZE: usize;
39
40 /// Static algorithm identifier for compile-time checking
41 const ALGORITHM_ID: &'static str;
42
43 /// Returns the stream cipher algorithm name
44 fn name() -> String {
45 Self::ALGORITHM_ID.to_string()
46 }
47}
48
49/// Marker trait for authenticated encryption algorithms
50pub trait AuthenticatedCipher {
51 /// Authentication tag size in bytes
52 const TAG_SIZE: usize;
53
54 /// Static algorithm identifier for compile-time checking
55 const ALGORITHM_ID: &'static str;
56
57 /// Returns the authenticated cipher algorithm name
58 fn name() -> String {
59 Self::ALGORITHM_ID.to_string()
60 }
61}
62
63/// Marker trait for key derivation functions
64pub trait KeyDerivationFunction {
65 /// Minimum recommended salt size in bytes
66 const MIN_SALT_SIZE: usize;
67
68 /// Default output size in bytes
69 const DEFAULT_OUTPUT_SIZE: usize;
70
71 /// Static algorithm identifier for compile-time checking
72 const ALGORITHM_ID: &'static str;
73
74 /// Returns the KDF algorithm name
75 fn name() -> String {
76 Self::ALGORITHM_ID.to_string()
77 }
78}
79
80/// Marker trait for hash function algorithms
81pub trait HashAlgorithm {
82 /// Output digest size in bytes
83 const OUTPUT_SIZE: usize;
84
85 /// Block size used by the algorithm in bytes
86 const BLOCK_SIZE: usize;
87
88 /// Static algorithm identifier for compile-time checking
89 const ALGORITHM_ID: &'static str;
90
91 /// Returns the hash algorithm name
92 fn name() -> String {
93 Self::ALGORITHM_ID.to_string()
94 }
95}