Skip to content

Commit f4bcd8e

Browse files
committed
### Hubris Integration Traits
- Add `HubrisDigestDevice` trait with concrete associated types - Implement `HubrisCryptoError` for IDL-compatible error handling - Support SHA-256/384/512 digest operations with move semantics - Add HMAC-SHA256/384/512 support with secure key management - Include one-shot operation convenience methods ### RustCrypto Controller Integration - Implement `HubrisDigestDevice` for `RustCryptoController` - Add `SecureOwnedKey` with stack-allocated 128-byte buffer - Fix unsafe indexing operations with bounds-checked alternatives - Suppress deprecation warnings for ecosystem compatibility
1 parent c300a0e commit f4bcd8e

File tree

12 files changed

+367
-27
lines changed

12 files changed

+367
-27
lines changed

Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77
"hal/blocking",
88
"hal/async",
99
"hal/nb",
10-
"platform/traits",
10+
"platform/traits/hubris",
1111
"platform/impls/baremetal/mock",
1212
"platform/impls/linux",
1313
"platform/impls/tock",

platform/impls/hubris/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Licensed under the Apache-2.0 license
22

33
[package]
4-
name = "openprot-platform-hubris"
4+
name = "openprot-platform-impl-hubris"
55
version = "0.1.0"
66
edition = "2021"
77
description = "Hubris OS platform implementation for OpenPRoT"
88
license = "Apache-2.0"
99

1010
[dependencies]
11-
openprot-platform-traits = { path = "../../traits" }
11+
openprot-platform-traits-hubris = { path = "../../traits/hubris" }

platform/impls/linux/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ description = "Linux platform implementation for OpenPRoT"
88
license = "Apache-2.0"
99

1010
[dependencies]
11-
openprot-platform-traits = { path = "../../traits" }

platform/impls/rustcrypto/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition.workspace = true
99

1010
[dependencies]
1111
openprot-hal-blocking = { path = "../../../hal/blocking" }
12+
openprot-platform-traits-hubris = { path = "../../traits/hubris" }
1213

1314
# RustCrypto ECDSA crates
1415
p256 = { version = "0.13", default-features = false, features = ["ecdsa", "arithmetic"] }

platform/impls/rustcrypto/src/cipher.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Licensed under the Apache-2.0 license
22

3+
#![allow(deprecated)] // Allow deprecated GenericArray from cipher crate for compatibility
4+
35
use openprot_hal_blocking::cipher::{
46
AeadCipherMode, BlockCipherMode, CipherInit, CipherMode, CipherOp, CipherStatus, Error,
57
ErrorKind, ErrorType, SymmetricCipher,

platform/impls/rustcrypto/src/controller.rs

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use openprot_hal_blocking::mac::{
1717
Error as MacError, ErrorKind as MacErrorKind, ErrorType as MacErrorType, KeyHandle,
1818
};
1919
use openprot_hal_blocking::mac::{HmacSha2_256, HmacSha2_384, HmacSha2_512};
20+
use openprot_platform_traits_hubris::{HubrisCryptoError, HubrisDigestDevice};
2021
use sha2::{Digest as Sha2Digest, Sha256, Sha384, Sha512};
2122

2223
/// A type implementing RustCrypto-based hash/digest owned traits.
@@ -114,7 +115,9 @@ impl SecureOwnedKey {
114115
}
115116

116117
let mut data = [0u8; 128];
117-
data[..bytes.len()].copy_from_slice(bytes);
118+
data.get_mut(..bytes.len())
119+
.ok_or(CryptoError::InvalidKeyLength)?
120+
.copy_from_slice(bytes);
118121

119122
Ok(Self {
120123
data,
@@ -129,14 +132,16 @@ impl SecureOwnedKey {
129132
}
130133

131134
let mut data = [0u8; 128];
132-
data[..N].copy_from_slice(&array);
135+
data.get_mut(..N)
136+
.ok_or(CryptoError::InvalidKeyLength)?
137+
.copy_from_slice(&array);
133138

134139
Ok(Self { data, len: N })
135140
}
136141

137142
/// Get the key bytes as a slice (only the valid portion)
138143
pub fn as_bytes(&self) -> &[u8] {
139-
&self.data[..self.len]
144+
self.data.get(..self.len).unwrap_or(&[])
140145
}
141146

142147
/// Get the key length
@@ -621,3 +626,55 @@ mod tests {
621626
assert_eq!(result.unwrap_err(), CryptoError::InvalidKeyLength);
622627
}
623628
}
629+
630+
/// Hardware capabilities for RustCrypto software implementation
631+
// TODO: Uncomment when DigestHardwareCapabilities is available
632+
// impl DigestHardwareCapabilities for RustCryptoController {
633+
// const MAX_CONCURRENT_SESSIONS: usize = 1; // Single-session software implementation
634+
// const HAS_HARDWARE_ACCELERATION: bool = false; // Software-only
635+
// const PLATFORM_NAME: &'static str = "RustCrypto Software";
636+
// }
637+
/// Hubris platform integration for RustCrypto controller
638+
impl HubrisDigestDevice for RustCryptoController {
639+
type DigestContext256 = DigestContext256;
640+
type DigestContext384 = DigestContext384;
641+
type DigestContext512 = DigestContext512;
642+
643+
type HmacKey = SecureOwnedKey;
644+
type HmacContext256 = MacContext256;
645+
type HmacContext384 = MacContext384;
646+
type HmacContext512 = MacContext512;
647+
648+
fn init_digest_sha256(self) -> Result<Self::DigestContext256, HubrisCryptoError> {
649+
DigestInit::init(self, Sha2_256).map_err(|_| HubrisCryptoError::HardwareFailure)
650+
}
651+
652+
fn init_digest_sha384(self) -> Result<Self::DigestContext384, HubrisCryptoError> {
653+
DigestInit::init(self, Sha2_384).map_err(|_| HubrisCryptoError::HardwareFailure)
654+
}
655+
656+
fn init_digest_sha512(self) -> Result<Self::DigestContext512, HubrisCryptoError> {
657+
DigestInit::init(self, Sha2_512).map_err(|_| HubrisCryptoError::HardwareFailure)
658+
}
659+
660+
fn init_hmac_sha256(
661+
self,
662+
key: Self::HmacKey,
663+
) -> Result<Self::HmacContext256, HubrisCryptoError> {
664+
MacInit::init(self, HmacSha2_256, key).map_err(|_| HubrisCryptoError::HardwareFailure)
665+
}
666+
667+
fn init_hmac_sha384(
668+
self,
669+
key: Self::HmacKey,
670+
) -> Result<Self::HmacContext384, HubrisCryptoError> {
671+
MacInit::init(self, HmacSha2_384, key).map_err(|_| HubrisCryptoError::HardwareFailure)
672+
}
673+
674+
fn init_hmac_sha512(
675+
self,
676+
key: Self::HmacKey,
677+
) -> Result<Self::HmacContext512, HubrisCryptoError> {
678+
MacInit::init(self, HmacSha2_512, key).map_err(|_| HubrisCryptoError::HardwareFailure)
679+
}
680+
}

platform/impls/tock/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ description = "Tock OS platform implementation for OpenPRoT"
88
license = "Apache-2.0"
99

1010
[dependencies]
11-
openprot-platform-traits = { path = "../../traits" }

platform/traits/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
name = "openprot-platform-traits"
55
version = "0.1.0"
66
edition = "2021"
7-
description = "OS abstraction traits for OpenPRoT"
7+
description = "Platform integration traits for OpenPRoT"
88
license = "Apache-2.0"
99

10-
[dependencies]
10+
[dependencies]
11+
openprot-platform-traits-hubris = { path = "../traits-hubris" }
12+
openprot-platform-traits-tock = { path = "../traits-tock" }
13+
openprot-platform-traits-linux = { path = "../traits-linux" }

platform/traits/hubris/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Licensed under the Apache-2.0 license
2+
3+
[package]
4+
name = "openprot-platform-traits-hubris"
5+
version = "0.1.0"
6+
edition = "2021"
7+
description = "Platform integration traits for OpenPRoT on Hubris"
8+
license = "Apache-2.0"
9+
10+
[dependencies]
11+
openprot-hal-async = { path = "../../../hal/async" }
12+
openprot-hal-blocking = { path = "../../../hal/blocking" }
13+
openprot-hal-nb = { path = "../../../hal/nb" }

0 commit comments

Comments
 (0)