-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathct_len.rs
44 lines (41 loc) · 1.63 KB
/
ct_len.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::kem::common::kem_type::KemType;
/// A trait to get the length of the ciphertext
pub trait CTLen {
fn get_ct_len(&self) -> Option<usize>;
}
impl CTLen for KemType {
/// Get the length of the ciphertext
///
/// # Returns
///
/// The length of the ciphertext in bytes
fn get_ct_len(&self) -> Option<usize> {
match self {
KemType::P256 => Some(65),
KemType::P384 => Some(97),
KemType::X25519 => Some(32),
KemType::BrainpoolP256r1 => Some(65),
KemType::BrainpoolP384r1 => Some(97),
KemType::X448 => Some(56),
// RSA is dependent on the key size
KemType::RsaOAEP2048 => Some(256),
KemType::RsaOAEP3072 => Some(384),
KemType::RsaOAEP4096 => Some(512),
// ML should be the following
KemType::MlKem512 => Some(768),
KemType::MlKem768 => Some(1088),
KemType::MlKem1024 => Some(1568),
// KEM CT + Trad CT + ASN.1 overhead
KemType::MlKem768BrainpoolP256r1 => Some(1088 + 65 + 10),
KemType::MlKem768X25519 => Some(1088 + 32 + 10),
KemType::MlKem1024P384 => Some(1568 + 97 + 10),
KemType::MlKem1024BrainpoolP384r1 => Some(1568 + 97 + 10),
KemType::MlKem1024X448 => Some(1568 + 56 + 10),
KemType::MlKem768Rsa2048 => Some(1088 + 256 + 12),
KemType::MlKem768Rsa3072 => Some(1088 + 384 + 12),
KemType::MlKem768Rsa4096 => Some(1088 + 512 + 12),
KemType::MlKem768P384 => Some(1088 + 97 + 10),
KemType::XWing => Some(1120),
}
}
}