Skip to content

Commit f502bd6

Browse files
authored
Merge pull request #317 from RobertDrazkowskiGL/calib-psa-hash-compute
Added support for PsaHashCompute to CryptoAuthLib provider.
2 parents c913ae3 + 2e8e014 commit f502bd6

File tree

12 files changed

+296
-9
lines changed

12 files changed

+296
-9
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ libc = "0.2.77"
4646
anyhow = "1.0.32"
4747
# Using a fork until the JWT support is merged into the main rust-spiffe repository
4848
spiffe = { git = "https://github.com/hug-dev/rust-spiffe", branch = "refactor-jwt" }
49+
#rust-cryptoauthlib = { git = "https://github.com/RobertDrazkowskiGL/rust-cryptoauthlib.git", optional = true }
50+
rust-cryptoauthlib = { version = "0.1.0", optional = true }
4951

5052
[dev-dependencies]
5153
rand = { version = "0.8.2", features = ["small_rng"] }
@@ -58,5 +60,5 @@ default = []
5860
mbed-crypto-provider = ["psa-crypto"]
5961
pkcs11-provider = ["pkcs11", "picky-asn1-der", "picky-asn1", "picky-asn1-x509", "psa-crypto", "rand"]
6062
tpm-provider = ["tss-esapi", "picky-asn1-der", "picky-asn1", "picky-asn1-x509", "hex"]
61-
cryptoauthlib-provider = []
63+
cryptoauthlib-provider = ["rust-cryptoauthlib"]
6264
all-providers = ["tpm-provider", "pkcs11-provider", "mbed-crypto-provider", "cryptoauthlib-provider"]

config.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,24 @@ key_info_manager = "on-disk-manager"
143143
#owner_hierarchy_auth = "password"
144144

145145
# Example of a CryptoAuthLib provider configuration
146-
# All below parameters depend on what devices, interfaces or parameters are required or supported by
146+
# All below parameters depend on what devices, interfaces or parameters are required or supported by
147147
# "rust-cryptoauthlib" wrapper for cryptoauthlib and underlying hardware.
148148
#[[provider]]
149149
#provider_type = "CryptoAuthLib"
150150
#key_info_manager = "on-disk-manager"
151+
# (Required) ATCA device type.
152+
# Supported values: "atecc508a", "atecc608a"
153+
#device_type = "atecc508a"
154+
# (Required) Interface for ATCA device
155+
# Supported values: "i2c"
156+
#iface_type = "i2c"
157+
# (Required) Default wake delay for ATCA device
158+
#wake_delay = 1500
159+
# (Required) Default number of rx retries for ATCA device
160+
#rx_retries = 20
161+
# (Optional - required for i2c) i2c slave addres
162+
#slave_address = 0xc0
163+
# (Optional - required for i2c) i2c bus number
164+
#bus = 1
165+
# (Optional - required for i2c) i2c bus baud rate
166+
#baud = 400000

e2e_tests/provider_cfg/all/config.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@ user_pin = "123456"
4343
[[provider]]
4444
provider_type = "CryptoAuthLib"
4545
key_info_manager = "on-disk-manager"
46+
device_type = "atecc508a"
47+
iface_type = "i2c"
48+
wake_delay = 1500
49+
rx_retries = 20
50+
# i2c parameters for i2c-pseudo proxy
51+
slave_address = 0xc0
52+
bus = 1
53+
baud = 400000

e2e_tests/provider_cfg/cryptoauthlib/config.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ store_path = "./mappings"
2323
[[provider]]
2424
provider_type = "CryptoAuthLib"
2525
key_info_manager = "on-disk-manager"
26+
device_type = "atecc508a"
27+
iface_type = "i2c"
28+
wake_delay = 1500
29+
rx_retries = 20
30+
# i2c parameters for i2c-pseudo proxy
31+
slave_address = 0xc0
32+
bus = 1
33+
baud = 400000

e2e_tests/tests/all_providers/config/tomls/list_providers_1.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ user_pin = "123456"
3737
[[provider]]
3838
provider_type = "CryptoAuthLib"
3939
key_info_manager = "on-disk-manager"
40+
device_type = "atecc508a"
41+
iface_type = "i2c"
42+
wake_delay = 1500
43+
rx_retries = 20
44+
# i2c parameters for i2c-pseudo proxy
45+
slave_address = 0xc0
46+
bus = 1
47+
baud = 400000

e2e_tests/tests/all_providers/config/tomls/list_providers_2.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ owner_hierarchy_auth = "tpm_pass"
3737
[[provider]]
3838
provider_type = "CryptoAuthLib"
3939
key_info_manager = "on-disk-manager"
40+
device_type = "atecc508a"
41+
iface_type = "i2c"
42+
wake_delay = 1500
43+
rx_retries = 20
44+
# i2c parameters for i2c-pseudo proxy
45+
slave_address = 0xc0
46+
bus = 1
47+
baud = 400000

e2e_tests/tests/all_providers/normal.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn list_opcodes() {
4444
let mut client = TestClient::new();
4545
let mut crypto_providers_hsm = HashSet::new();
4646
let mut core_provider_opcodes = HashSet::new();
47+
let mut crypto_providers_cal = HashSet::new();
4748

4849
let _ = crypto_providers_hsm.insert(Opcode::PsaGenerateKey);
4950
let _ = crypto_providers_hsm.insert(Opcode::PsaDestroyKey);
@@ -71,6 +72,9 @@ fn list_opcodes() {
7172
let _ = core_provider_opcodes.insert(Opcode::ListOpcodes);
7273
let _ = core_provider_opcodes.insert(Opcode::ListKeys);
7374

75+
// Not that much to be tested ATM
76+
let _ = crypto_providers_cal.insert(Opcode::PsaHashCompute);
77+
7478
assert_eq!(
7579
client
7680
.list_opcodes(ProviderID::Core)
@@ -95,6 +99,12 @@ fn list_opcodes() {
9599
.expect("list providers failed"),
96100
crypto_providers_mbed_crypto
97101
);
102+
assert_eq!(
103+
client
104+
.list_opcodes(ProviderID::CryptoAuthLib)
105+
.expect("list providers failed"),
106+
crypto_providers_cal
107+
);
98108
}
99109

100110
#[cfg(feature = "testing")]

src/providers/cryptoauthlib/hash.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2021 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
use super::Provider;
4+
use parsec_interface::operations::psa_algorithm::Hash;
5+
use parsec_interface::operations::psa_hash_compute;
6+
use parsec_interface::requests::{ResponseStatus, Result};
7+
8+
impl Provider {
9+
pub(super) fn psa_hash_compute_internal(
10+
&self,
11+
op: psa_hash_compute::Operation,
12+
) -> Result<psa_hash_compute::Result> {
13+
let mut hash = vec![0u8; op.alg.hash_length()];
14+
match op.alg {
15+
Hash::Sha256 => {
16+
let message = op.input.to_vec();
17+
let err = rust_cryptoauthlib::atcab_sha(message, &mut hash);
18+
match err {
19+
rust_cryptoauthlib::AtcaStatus::AtcaSuccess => {
20+
Ok(psa_hash_compute::Result { hash: hash.into() })
21+
}
22+
_ => {
23+
let error = ResponseStatus::PsaErrorGenericError;
24+
format_error!("Hash computation failed ", err);
25+
Err(error)
26+
}
27+
}
28+
}
29+
_ => {
30+
let error = ResponseStatus::PsaErrorNotSupported;
31+
format_error!("Unsupported hash algorithm ", error);
32+
Err(error)
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)