Skip to content

Commit 8063d82

Browse files
committed
Trial miracl-trussed wrapping
1 parent 817a9e7 commit 8063d82

File tree

10 files changed

+452
-7
lines changed

10 files changed

+452
-7
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ hmac = "0.11"
3838
sha-1 = { version = "0.9", default-features = false, optional = true }
3939
sha2 = { version = "0.9", default-features = false }
4040

41+
# miracl
42+
miracl32 = { version = "0.1.0-alpha.0", optional = true }
43+
4144
# ours
4245
cosey = "0.3"
4346
delog = "0.1.0"
@@ -95,6 +98,13 @@ aes256-cbc = []
9598
chacha8-poly1305 = []
9699
ed255 = []
97100
x255 = []
101+
ed448 = ["miracl32"]
102+
x448 = ["miracl32"]
103+
rsa2k = ["miracl32"]
104+
rsa3k = ["miracl32"]
105+
rsa4k = ["miracl32"]
106+
p384 = ["miracl32"]
107+
p521 = ["miracl32"]
98108
hmac-blake2s = ["blake2"]
99109
hmac-sha1 = []
100110
hmac-sha256 = []

bacon.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ default_job = "check"
1111
command = ["cargo", "check", "--color", "always"]
1212
need_stdout = false
1313

14+
[jobs.check-miracl]
15+
# command = ["cargo", "check", "--color", "always", "--features", "clients-1"]
16+
command = ["cargo", "check", "--color", "always", "--features", "ed448,x448,rsa2k,rsa3k,rsa4k,p384,p521"]
17+
need_stdout = false
18+
1419
[jobs.check-cortex-m4]
1520
# command = ["cargo", "check", "--color", "always", "--features", "clients-1"]
1621
command = ["cargo", "check", "--color", "always", "--target", "thumbv7em-none-eabi"]

src/client/mechanisms.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,58 @@ pub trait P256: CryptoClient {
245245
}
246246
}
247247

248+
#[cfg(feature = "p384")]
249+
impl<S: Syscall> P384 for ClientImplementation<S> {}
250+
251+
pub trait P384: CryptoClient {
252+
fn generate_p384_private_key(&mut self, persistence: Location)
253+
-> ClientResult<'_, reply::GenerateKey, Self>
254+
{
255+
self.generate_key(Mechanism::P384, StorageAttributes::new().set_persistence(persistence))
256+
}
257+
258+
fn derive_p384_public_key(&mut self, private_key: KeyId, persistence: Location)
259+
-> ClientResult<'_, reply::DeriveKey, Self>
260+
{
261+
self.derive_key(Mechanism::P384, private_key, None, StorageAttributes::new().set_persistence(persistence))
262+
}
263+
264+
fn deserialize_p384_key<'c>(&'c mut self, serialized_key: &[u8], format: KeySerialization, attributes: StorageAttributes)
265+
-> ClientResult<'c, reply::DeserializeKey, Self>
266+
{
267+
self.deserialize_key(Mechanism::P384, serialized_key, format, attributes)
268+
}
269+
270+
fn serialize_p384_key(&mut self, key: KeyId, format: KeySerialization)
271+
-> ClientResult<'_, reply::SerializeKey, Self>
272+
{
273+
self.serialize_key(Mechanism::P384, key, format)
274+
}
275+
276+
fn sign_p384<'c>(&'c mut self, key: KeyId, message: &[u8], format: SignatureSerialization)
277+
-> ClientResult<'c, reply::Sign, Self>
278+
{
279+
self.sign(Mechanism::P384, key, message, format)
280+
}
281+
282+
fn verify_p384<'c>(&'c mut self, key: KeyId, message: &[u8], signature: &[u8])
283+
-> ClientResult<'c, reply::Verify, Self>
284+
{
285+
self.verify(Mechanism::P384, key, message, signature, SignatureSerialization::Raw)
286+
}
287+
288+
fn agree_p384(&mut self, private_key: KeyId, public_key: KeyId, persistence: Location)
289+
-> ClientResult<'_, reply::Agree, Self>
290+
{
291+
self.agree(
292+
Mechanism::P384,
293+
private_key,
294+
public_key,
295+
StorageAttributes::new().set_persistence(persistence),
296+
)
297+
}
298+
}
299+
248300
#[cfg(feature = "sha256")]
249301
impl<S: Syscall> Sha256 for ClientImplementation<S> {}
250302

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pub const MAX_KEY_MATERIAL_LENGTH: usize = 128;
1818
pub const MAX_SERIALIZED_KEY_LENGTH: usize = 132;
1919
pub type MAX_SERVICE_CLIENTS = consts::U5;
2020
pub const MAX_SHORT_DATA_LENGTH: usize = 128;
21-
pub const MAX_SIGNATURE_LENGTH: usize = 72;
21+
// 72 was for P256, raw P384 is 96
22+
pub const MAX_SIGNATURE_LENGTH: usize = 96;
2223
pub const MAX_USER_ATTRIBUTE_LENGTH: usize = 256;
2324

2425
pub const USER_ATTRIBUTE_NUMBER: u8 = 37;

src/key.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ pub enum Kind {
6363
Ed255,
6464
P256,
6565
X255,
66+
P384,
67+
P521,
68+
Rsa2k,
69+
Rsa3k,
70+
Rsa4k,
71+
Ed448,
72+
X448,
6673
}
6774

6875
bitflags::bitflags! {
@@ -136,17 +143,35 @@ impl Kind {
136143
Kind::Ed255 => 4,
137144
Kind::P256 => 5,
138145
Kind::X255 => 6,
146+
// following PIV and our extensions
147+
Kind::P384 => 0x14,
148+
Kind::P521 => 0x15,
149+
Kind::Rsa2k => 0x7,
150+
Kind::Rsa3k => 0xE0,
151+
Kind::Rsa4k => 0xE1,
152+
Kind::Ed448 => 0xE4,
153+
Kind::X448 => 0xE5,
139154
}
140155
}
141156

142157
pub fn try_from(code: u16, length: usize) -> Result<Self, Error> {
158+
use Kind::*;
143159
Ok(match code {
144-
1 => Self::Shared(length),
145-
2 => Self::Symmetric(length),
146-
3 => Self::Symmetric32Nonce(length - 32),
147-
4 => Self::Ed255,
148-
5 => Self::P256,
149-
6 => Self::X255,
160+
1 => Shared(length),
161+
2 => Symmetric(length),
162+
3 => Symmetric32Nonce(length - 32),
163+
4 => Ed255,
164+
5 => P256,
165+
6 => X255,
166+
167+
0x14 => P384,
168+
0x15 => P521,
169+
0x7 => Rsa2k,
170+
0xE0 => Rsa3k,
171+
0xE1 => Rsa4k,
172+
0xE4 => Ed448,
173+
0xE5 => X448,
174+
150175
_ => return Err(Error::InvalidSerializedKey),
151176
})
152177
}

src/mechanisms.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ impl crate::service::DeriveKey for HmacSha512 {}
4242
#[cfg(not(feature = "hmac-sha512"))]
4343
impl crate::service::Sign for HmacSha512 {}
4444

45+
pub struct P384 {}
46+
#[cfg(feature = "p384")]
47+
mod p384;
48+
49+
pub struct Rsa2k {}
50+
#[cfg(feature = "rsa2k")]
51+
mod rsa2k;
52+
4553
pub struct P256 {}
4654
pub struct P256Prehashed {}
4755
mod p256;

0 commit comments

Comments
 (0)