Skip to content

Commit 4607cc3

Browse files
authored
Merge pull request #45 from ionut-arm/valid-id
Keep key ID within bounds for Mbed provider
2 parents 3cad90c + e65cbc4 commit 4607cc3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/providers/mbed_provider/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub const PSA_ERROR_INVALID_PADDING: psa_status_t = -150;
3838
pub const PSA_ERROR_INSUFFICIENT_DATA: psa_status_t = -143;
3939
pub const PSA_ERROR_INVALID_HANDLE: psa_status_t = -136;
4040

41+
pub const PSA_MAX_PERSISTENT_KEY_IDENTIFIER: psa_key_id_t = 0xfffe_ffff;
4142
pub const PSA_KEY_SLOT_COUNT: isize = 32;
4243
pub const EMPTY_KEY_HANDLE: psa_key_handle_t = 0;
4344
pub const PSA_KEY_TYPE_NONE: psa_key_type_t = 0x0000_0000;

src/providers/mbed_provider/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ fn create_key_id(
107107
local_ids_handle: &mut LocalIdStore,
108108
) -> Result<psa_crypto_binding::psa_key_id_t> {
109109
let mut key_id = rand::random::<psa_crypto_binding::psa_key_id_t>();
110-
while local_ids_handle.contains(&key_id) {
110+
while local_ids_handle.contains(&key_id)
111+
&& key_id != 0
112+
&& key_id < constants::PSA_MAX_PERSISTENT_KEY_IDENTIFIER
113+
{
111114
key_id = rand::random::<psa_crypto_binding::psa_key_id_t>();
112115
}
113116
match store_handle.insert(key_triple.clone(), key_id.to_ne_bytes().to_vec()) {

0 commit comments

Comments
 (0)