-
Notifications
You must be signed in to change notification settings - Fork 31
Post-Quantum Cryptography #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5c1ccde
e636dcf
2984834
1256243
3d2613c
ae56508
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
pub const MAX_MESSAGE_LENGTH: usize = 1024; | ||
pub const MAX_MEDIUM_DATA_LENGTH: usize = 256; | ||
pub const MAX_SHORT_DATA_LENGTH: usize = 128; | ||
pub const MAX_SIGNATURE_LENGTH: usize = 512 * 2; | ||
// FIXME: Value from https://stackoverflow.com/questions/5403808/private-key-length-bytes for Rsa2048 Private key | ||
pub const MAX_KEY_MATERIAL_LENGTH: usize = 1160 * 2 + 72; | ||
pub const MAX_USER_ATTRIBUTE_LENGTH: usize = 256; | ||
|
||
// request size is chosen to not exceed the largest standard syscall, Decrypt, so that the Request | ||
|
@@ -13,3 +9,54 @@ pub const SERDE_EXTENSION_REQUEST_LENGTH: usize = | |
// reply size is chosen to not exceed the largest standard syscall, Encrypt, so that the Reply enum | ||
// does not grow from this variant | ||
pub const SERDE_EXTENSION_REPLY_LENGTH: usize = MAX_MESSAGE_LENGTH + 2 * MAX_SHORT_DATA_LENGTH; | ||
|
||
// Must be MAX_KEY_MATERIAL_LENGTH + 4 | ||
// Note that this is not the serialized key material (e.g. serialized PKCS#8), but | ||
// the internal Trussed serialization that adds flags and such | ||
pub const MAX_SERIALIZED_KEY_LENGTH: usize = MAX_KEY_MATERIAL_LENGTH + 4; | ||
|
||
// For the PQC algorithms, public and private key are generated at the same time and stored together as | ||
// the private key. Then in the derive call, it just pulls the public key from the private key store | ||
// and re-saves it as a public-only key. Therefore, the max material length is both keys together, plus | ||
// the PKCS8 DER encoding overhead (31 bytes). | ||
|
||
pub const MAX_SIGNATURE_LENGTH: usize = if cfg!(feature = "mldsa87") { | ||
4627 | ||
} else if cfg!(feature = "mldsa65") { | ||
3309 | ||
} else if cfg!(feature = "mldsa44") { | ||
2420 | ||
} else { | ||
// Default from before addition of PQC | ||
512 * 2 | ||
}; | ||
|
||
pub const MAX_KEY_MATERIAL_LENGTH: usize = if cfg!(feature = "mldsa87") { | ||
2592 // Public key | ||
+ 4896 // Private key | ||
+ 31 | ||
} else if cfg!(feature = "mldsa65") { | ||
1952 // Public key | ||
+ 4032 // Private key | ||
+ 31 | ||
} else if cfg!(feature = "mldsa44") { | ||
1312 // Public key | ||
+ 2560 // Private key | ||
+ 31 | ||
} else { | ||
// FIXME: Value from https://stackoverflow.com/questions/5403808/private-key-length-bytes for Rsa2048 Private key | ||
1160 * 2 + 72 | ||
}; | ||
|
||
pub const MAX_FIDO_WRAPPED_KEY_LENGTH: usize = | ||
if cfg!(feature = "mldsa87") || cfg!(feature = "mldsa65") || cfg!(feature = "mldsa44") { | ||
MAX_SERIALIZED_KEY_LENGTH + 57 | ||
} else { | ||
// Default from before addition of PQC | ||
128 | ||
}; | ||
|
||
// 30 bytes are added by CBOR serialization of a FullCredential | ||
// TODO: This was calculated by debugging and finding each location where this variable needed to be larger for one reason or another. | ||
// Update this to use different consts for each area where this is needed, instead of one const used everywhere. | ||
pub const MAX_MESSAGE_LENGTH: usize = MAX_FIDO_WRAPPED_KEY_LENGTH + 30 + 2031 + 32 + 37; | ||
Comment on lines
+59
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is way too large. It needs to be at least feature flag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,12 @@ use serde::{de::Visitor, ser::SerializeMap, Deserialize, Serialize}; | |
use zeroize::Zeroize; | ||
|
||
pub use crate::Bytes; | ||
use crate::{ | ||
config::{MAX_KEY_MATERIAL_LENGTH, MAX_SERIALIZED_KEY_LENGTH}, | ||
Error, | ||
}; | ||
use crate::Error; | ||
use trussed_core::config::MAX_SERIALIZED_KEY_LENGTH; | ||
|
||
pub type Material = Vec<u8, { MAX_KEY_MATERIAL_LENGTH }>; | ||
// Keys are often stored in serialized format (e.g. PKCS#8 used by the RSA backend), | ||
// so material max length must be serialized max length. | ||
pub type Material = Vec<u8, { MAX_SERIALIZED_KEY_LENGTH }>; | ||
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be changed, max There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be an issue with the
Among others. I've tried to dig into this, but given that the mismatch for the last example is between 7519 bytes and 7523 bytes, which correspond to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that looks like the issue of using type aliases instead of newtypes, which means that there doesn't need to be explicit conversions between types. I'm looking into it. |
||
pub type SerializedKeyBytes = Vec<u8, { MAX_SERIALIZED_KEY_LENGTH }>; | ||
|
||
// We don't implement serde to make sure nobody inadvertently still uses it | ||
|
@@ -77,6 +77,13 @@ pub enum Kind { | |
BrainpoolP512R1, | ||
X255, | ||
Secp256k1, | ||
// Post-quantum cryptography algorithms | ||
#[cfg(feature = "mldsa44")] | ||
Mldsa44, | ||
#[cfg(feature = "mldsa65")] | ||
Mldsa65, | ||
#[cfg(feature = "mldsa87")] | ||
Mldsa87, | ||
} | ||
|
||
bitflags::bitflags! { | ||
|
@@ -223,6 +230,12 @@ impl Kind { | |
Kind::BrainpoolP384R1 => 13, | ||
Kind::BrainpoolP512R1 => 14, | ||
Kind::Secp256k1 => 15, | ||
#[cfg(feature = "mldsa44")] | ||
Kind::Mldsa44 => 16, | ||
#[cfg(feature = "mldsa65")] | ||
Kind::Mldsa65 => 17, | ||
#[cfg(feature = "mldsa87")] | ||
Kind::Mldsa87 => 18, | ||
} | ||
} | ||
|
||
|
@@ -243,6 +256,12 @@ impl Kind { | |
13 => Kind::BrainpoolP384R1, | ||
14 => Kind::BrainpoolP512R1, | ||
15 => Kind::Secp256k1, | ||
#[cfg(feature = "mldsa44")] | ||
16 => Kind::Mldsa44, | ||
#[cfg(feature = "mldsa65")] | ||
17 => Kind::Mldsa65, | ||
#[cfg(feature = "mldsa87")] | ||
18 => Kind::Mldsa87, | ||
_ => return Err(Error::InvalidSerializedKey), | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ use littlefs2_core::{path, PathBuf}; | |
use rand_chacha::ChaCha8Rng; | ||
|
||
use crate::{ | ||
config::MAX_KEY_MATERIAL_LENGTH, | ||
error::{Error, Result}, | ||
key, | ||
store::{self, Store}, | ||
types::{KeyId, Location}, | ||
Bytes, | ||
}; | ||
use trussed_core::config::MAX_SERIALIZED_KEY_LENGTH; | ||
|
||
pub type ClientId = PathBuf; | ||
|
||
|
@@ -181,7 +181,7 @@ impl<S: Store> Keystore for ClientKeystore<S> { | |
|
||
let location = self.location(secrecy, id).ok_or(Error::NoSuchKey)?; | ||
|
||
let bytes: Bytes<{ MAX_KEY_MATERIAL_LENGTH }> = store::read(&self.store, location, &path)?; | ||
let bytes: Bytes<{ MAX_SERIALIZED_KEY_LENGTH }> = store::read(&self.store, location, &path)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
let key = key::Key::try_deserialize(&bytes)?; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in FIDO itself not in trussed, or at the very least
#[doc(hidden)]
.