mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 20:38:35 -07:00
crypto: Erase key from RAM after storing into enclave
When storing a new unique secret key in the secure enclave, it is temporarily stored in a stack buffer accessible by CPU1. Since it is a secret key, it should not be kept in memory as it could be leaked. This commit calls the explicit_bzero() function from the libc to ensure that the buffer containing the key is cleared. Unlike with bzero() and memset(), the compiler won't optimize away calls to explicit_bzero().
This commit is contained in:
committed by
Willy-JL
parent
512bba335b
commit
be8387afb5
@@ -276,6 +276,7 @@ void crypto_cli_store_key(Cli* cli, FuriString* args) {
|
||||
}
|
||||
} while(0);
|
||||
|
||||
explicit_bzero(data, sizeof(data));
|
||||
furi_string_free(key_type);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,9 +80,11 @@ static bool furi_hal_crypto_generate_unique_keys(uint8_t start_slot, uint8_t end
|
||||
key.data = key_data;
|
||||
furi_hal_random_fill_buf(key_data, 32);
|
||||
if(!furi_hal_crypto_store_add_key(&key, &slot)) {
|
||||
explicit_bzero(key_data, sizeof(key_data));
|
||||
FURI_LOG_E(TAG, "Error writing key to slot %u", slot);
|
||||
return false;
|
||||
}
|
||||
explicit_bzero(key_data, sizeof(key_data));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -176,6 +178,7 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
|
||||
memcpy(pParam.KeyData, key->data, key_data_size);
|
||||
|
||||
SHCI_CmdStatus_t shci_state = SHCI_C2_FUS_StoreUsrKey(&pParam, slot);
|
||||
explicit_bzero(&pParam, sizeof(pParam));
|
||||
furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk);
|
||||
return (shci_state == SHCI_Success);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user