Skip to content

Commit 2e8e014

Browse files
Fix scope of a message buffer to improve security.
Signed-off-by: Robert Drazkowski <[email protected]>
1 parent ce927da commit 2e8e014

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/providers/cryptoauthlib/hash.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Contributors to the Parsec project.
1+
// Copyright 2021 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
33
use super::Provider;
44
use parsec_interface::operations::psa_algorithm::Hash;
@@ -11,18 +11,21 @@ impl Provider {
1111
op: psa_hash_compute::Operation,
1212
) -> Result<psa_hash_compute::Result> {
1313
let mut hash = vec![0u8; op.alg.hash_length()];
14-
let message = op.input.to_vec();
1514
match op.alg {
16-
Hash::Sha256 => match rust_cryptoauthlib::atcab_sha(message, &mut hash) {
17-
rust_cryptoauthlib::AtcaStatus::AtcaSuccess => {
18-
Ok(psa_hash_compute::Result { hash: hash.into() })
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+
}
1927
}
20-
err => {
21-
let error = ResponseStatus::PsaErrorGenericError;
22-
format_error!("Hash computation failed ", err);
23-
Err(error)
24-
}
25-
},
28+
}
2629
_ => {
2730
let error = ResponseStatus::PsaErrorNotSupported;
2831
format_error!("Unsupported hash algorithm ", error);

0 commit comments

Comments
 (0)