1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-12 04:41:26 +04:00

Expose additional functions of the crypto engine to user (#2923)

* Allow loading user supplied keys and add CTR mode
* Add GCM mode to furi_hal_crypto
* Split up CTR and GCM code, add flag for adv crypto
* Add convenience functions for GCM crypto
* Run fbt format
* Update GCM to support additional auth data
* Update APIs
* FuriHal: update crypto documentation, method names and usage
* Clean up code for key (un)loading, GCM and CTR
  - get rid of goto
  - do not use furi_hal_bt_is_alive() when not using secure enclave
  - give defines a type and wrap in ()
* Add unit test for CTR and GCM crypto
* FuriHal: const in crypto unit tests, cortex timer for crypto operations timeouts
* FuriHal: update crypto docs

Co-authored-by: twisted_pear <twstd@posteo.net>
Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
twisted-pear
2023-08-10 10:44:46 +02:00
committed by GitHub
parent fb63e53d9a
commit c976ff11bf
10 changed files with 1301 additions and 92 deletions

View File

@@ -33,7 +33,7 @@ void crypto_cli_encrypt(Cli* cli, FuriString* args) {
break;
}
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
if(!furi_hal_crypto_enclave_load_key(key_slot, iv)) {
printf("Unable to load key from slot %d", key_slot);
break;
}
@@ -88,7 +88,7 @@ void crypto_cli_encrypt(Cli* cli, FuriString* args) {
} while(0);
if(key_loaded) {
furi_hal_crypto_store_unload_key(key_slot);
furi_hal_crypto_enclave_unload_key(key_slot);
}
}
@@ -108,7 +108,7 @@ void crypto_cli_decrypt(Cli* cli, FuriString* args) {
break;
}
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
if(!furi_hal_crypto_enclave_load_key(key_slot, iv)) {
printf("Unable to load key from slot %d", key_slot);
break;
}
@@ -160,7 +160,7 @@ void crypto_cli_decrypt(Cli* cli, FuriString* args) {
} while(0);
if(key_loaded) {
furi_hal_crypto_store_unload_key(key_slot);
furi_hal_crypto_enclave_unload_key(key_slot);
}
}
@@ -175,14 +175,14 @@ void crypto_cli_has_key(Cli* cli, FuriString* args) {
break;
}
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
if(!furi_hal_crypto_enclave_load_key(key_slot, iv)) {
printf("Unable to load key from slot %d", key_slot);
break;
}
printf("Successfully loaded key from slot %d", key_slot);
furi_hal_crypto_store_unload_key(key_slot);
furi_hal_crypto_enclave_unload_key(key_slot);
} while(0);
}
@@ -251,25 +251,25 @@ void crypto_cli_store_key(Cli* cli, FuriString* args) {
if(key_slot > 0) {
uint8_t iv[16] = {0};
if(key_slot > 1) {
if(!furi_hal_crypto_store_load_key(key_slot - 1, iv)) {
if(!furi_hal_crypto_enclave_load_key(key_slot - 1, iv)) {
printf(
"Slot %d before %d is empty, which is not allowed",
key_slot - 1,
key_slot);
break;
}
furi_hal_crypto_store_unload_key(key_slot - 1);
furi_hal_crypto_enclave_unload_key(key_slot - 1);
}
if(furi_hal_crypto_store_load_key(key_slot, iv)) {
furi_hal_crypto_store_unload_key(key_slot);
if(furi_hal_crypto_enclave_load_key(key_slot, iv)) {
furi_hal_crypto_enclave_unload_key(key_slot);
printf("Key slot %d is already used", key_slot);
break;
}
}
uint8_t slot;
if(furi_hal_crypto_store_add_key(&key, &slot)) {
if(furi_hal_crypto_enclave_store_key(&key, &slot)) {
printf("Success. Stored to slot: %d", slot);
} else {
printf("Failure");