Skip to content

Commit 16003b6

Browse files
committed
WIP: Address review comments - 1
In a separate commit for better visibility. Removed addressed TODOs, reworded those that should stay for later (magic numbers), rebased to the latest "main". Signed-off-by: alt3r 3go <[email protected]>
1 parent c360dce commit 16003b6

File tree

8 files changed

+21
-288
lines changed

8 files changed

+21
-288
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ default-mechanisms = [
9191
"tdes",
9292
"totp",
9393
"trng",
94-
"rsa2k-pkcs",
95-
"rsa3k",
96-
"rsa4k"
94+
"rsa2k"
9795
]
9896
aes256-cbc = []
9997
chacha8-poly1305 = []
@@ -108,7 +106,7 @@ sha256 = []
108106
tdes = ["des"]
109107
totp = ["sha-1"]
110108
trng = ["sha-1"]
111-
rsa2k-pkcs = ["rsa"]
109+
rsa2k = ["rsa"]
112110
rsa3k = ["rsa"]
113111
rsa4k = ["rsa"]
114112

src/client/mechanisms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub trait P256: CryptoClient {
245245
}
246246
}
247247

248-
#[cfg(feature = "rsa2k-pkcs")]
248+
#[cfg(feature = "rsa2k")]
249249
impl<S: Syscall> Rsa2kPkcs for ClientImplementation<S> {}
250250

251251
pub trait Rsa2kPkcs: CryptoClient {

src/config.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,21 @@ cfg_if::cfg_if! {
4444
}
4545
pub const MAX_SHORT_DATA_LENGTH: usize = 128;
4646

47-
// TODO:alt3r-3go: Do we want better keylength granularity here?
48-
#[cfg(any(feature = "rsa2k-pkcs", feature = "rsa3k", feature = "rsa4k"))]
47+
#[cfg(any(feature = "rsa2k", feature = "rsa3k", feature = "rsa4k"))]
4948
pub const MAX_SIGNATURE_LENGTH: usize = 512;
50-
#[cfg(any(feature = "rsa2k-pkcs", feature = "rsa3k", feature = "rsa4k"))]
51-
// TODO:alt3r-3go: We use PKCS#8 DER format, this value was found empirically for 2K keys. Need to generalize.
49+
#[cfg(any(feature = "rsa2k", feature = "rsa3k", feature = "rsa4k"))]
50+
// TODO: We use PKCS#8 DER format, this value was found empirically for 2K keys. Need to generalize.
5251
pub const MAX_KEY_MATERIAL_LENGTH: usize = 1217;
53-
#[cfg(any(feature = "rsa2k-pkcs", feature = "rsa3k", feature = "rsa4k"))]
54-
// TODO:alt3r-3go: This is due to the fact that KEY_MATERIAL_LENGTH is now bigger than MESSAGE_LENGTH.
55-
// Double-check this is okay.
52+
#[cfg(any(feature = "rsa2k", feature = "rsa3k", feature = "rsa4k"))]
53+
// This is due to the fact that KEY_MATERIAL_LENGTH is bigger than MESSAGE_LENGTH for RSA.
5654
pub const MAX_MESSAGE_LENGTH: usize = MAX_KEY_MATERIAL_LENGTH;
5755

5856

59-
#[cfg(not(any(feature = "rsa2k-pkcs", feature = "rsa3k", feature = "rsa4k")))]
57+
#[cfg(not(any(feature = "rsa2k", feature = "rsa3k", feature = "rsa4k")))]
6058
pub const MAX_SIGNATURE_LENGTH: usize = 72;
61-
#[cfg(not(any(feature = "rsa2k-pkcs", feature = "rsa3k", feature = "rsa4k")))]
59+
#[cfg(not(any(feature = "rsa2k", feature = "rsa3k", feature = "rsa4k")))]
6260
pub const MAX_KEY_MATERIAL_LENGTH: usize = 128;
63-
#[cfg(not(any(feature = "rsa2k-pkcs", feature = "rsa3k", feature = "rsa4k")))]
61+
#[cfg(not(any(feature = "rsa2k", feature = "rsa3k", feature = "rsa4k")))]
6462
pub const MAX_MESSAGE_LENGTH: usize = 1024;
6563

6664
// must be MAX_KEY_MATERIAL_LENGTH + 4

src/mechanisms.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ pub struct P256Prehashed {}
4747
mod p256;
4848

4949
pub struct Rsa2kPkcs {}
50-
mod rsa2kpkcs;
50+
// Later on we'll add: "pub struct Rsa2kPss {}" and so on
51+
mod rsa2k;
5152

5253
pub struct Sha256 {}
5354
mod sha256;

src/mechanisms/rsa2kpkcs.rs

Lines changed: 0 additions & 260 deletions
This file was deleted.

src/store/keystore.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,9 @@ impl<P: Platform> Keystore for ClientKeystore<P> {
147147

148148
let location = self.location(secrecy, id).ok_or(Error::NoSuchKey)?;
149149

150-
//TODO:alt3r-3go: This should better be defined in some way, instead of hardcoding.
151-
// I've tried referring to MAX_SERIALIZED_KEY_LENGTH, is this a good idea?
152-
#[cfg(not(feature = "rsa2k-pkcs"))]
150+
#[cfg(not(feature = "rsa2k"))]
153151
let bytes: Bytes<128> = store::read(self.store, location, &path)?;
154-
#[cfg(feature = "rsa2k-pkcs")]
152+
#[cfg(feature = "rsa2k")]
155153
let bytes: Bytes<MAX_SERIALIZED_KEY_LENGTH> = store::read(self.store, location, &path)?;
156154

157155
let key = key::Key::try_deserialize(&bytes)?;

src/types.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,11 @@ pub enum Mechanism {
509509
Trng,
510510
X255,
511511
Rsa2kPkcs,
512-
Rsa3k,
513-
Rsa4k,
512+
Rsa2kPss,
513+
Rsa3kPkcs,
514+
Rsa3kPss,
515+
Rsa4kPkcs,
516+
Rsa4kPss,
514517
}
515518

516519
pub type LongData = Bytes<MAX_LONG_DATA_LENGTH>;

tests/rsa2kpkcs.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ use trussed::types::KeySerialization;
99
use trussed::types::Location::*;
1010
use trussed::types::StorageAttributes;
1111

12-
// TODO:alt3r-3go: Looks like the test infra is not supposed to be used with several tests like below -
13-
// right now it randomly fails with SIGSERV on either of the two, when run together,
14-
// but never when run separately. Need to investigate and fix.
12+
// Tests below can be run on a PC using the "virt" feature
1513

1614
#[test]
1715
fn rsa2kpkcs_generate_key() {
1816
client::get(|client| {
1917
let sk = syscall!(client.generate_rsa2kpkcs_private_key(Internal)).key;
2018

2119
// This assumes we don't ever get a key with ID 0
22-
// TODO:alt3r-3go: make sure the above always holds or find a better way to check for success
2320
assert_ne!(sk, KeyId::from_special(0));
2421
})
2522
}
@@ -31,7 +28,6 @@ fn rsa2kpkcs_derive_key() {
3128
let pk = syscall!(client.derive_rsa2kpkcs_public_key(sk, Volatile)).key;
3229

3330
// This assumes we don't ever get a key with ID 0
34-
// TODO:alt3r-3go: make sure the above always holds or find a better way to check for success
3531
assert_ne!(pk, KeyId::from_special(0));
3632
})
3733
}
@@ -67,7 +63,6 @@ fn rsa2kpkcs_deserialize_key() {
6763
let deserialized_key_id = syscall!(client.deserialize_rsa2kpkcs_key(&serialized_key, KeySerialization::Raw, location)).key;
6864

6965
// This assumes we don't ever get a key with ID 0
70-
// TODO:alt3r-3go: make sure the above always holds or find a better way to check for success
7166
assert_ne!(deserialized_key_id, KeyId::from_special(0));
7267
})
7368
}

0 commit comments

Comments
 (0)