Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorあく <alleteam@gmail.com>2021-11-01 16:11:25 +0300
committerGitHub <noreply@github.com>2021-11-01 16:11:25 +0300
commit22a4bac44881dab3d290c487df403c12bd7f7660 (patch)
tree10ac035d989d9882b344768df6130dbda27b0e3e /firmware
parent3f93a0ae46048fc90c447a0f49f038acd1eddf77 (diff)
[FL-1934] Core: wipe memory after free. SubGhz: key encryption tool. (#797)
* Core: wipe memory after free. RFID,iButton: fix iterator use after invalidation. * Debug: support unix wildcards for register matching in svd, update MCU description file and minify it. * Toolbox: getter for File in FlipperFile. * Makefile: conditional flashing * SubGhz: keeloq_mfcodes encryption tool. * FuriHal: proper IV handling on CBC in crypto. SubGhz: add support for encrypted keeloq keys. Makefile: move formatting to top Makefile. * SubGhz: rename some function names to match naming scheme. * SubGhz: encryption tool, fix windows line endings Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
Diffstat (limited to 'firmware')
-rw-r--r--firmware/targets/f6/furi-hal/furi-hal-crypto.c21
-rw-r--r--firmware/targets/f7/furi-hal/furi-hal-crypto.c21
-rw-r--r--firmware/targets/furi-hal-include/furi-hal-crypto.h7
3 files changed, 25 insertions, 24 deletions
diff --git a/firmware/targets/f6/furi-hal/furi-hal-crypto.c b/firmware/targets/f6/furi-hal/furi-hal-crypto.c
index 3e4ec98f..62f569f7 100644
--- a/firmware/targets/f6/furi-hal/furi-hal-crypto.c
+++ b/firmware/targets/f6/furi-hal/furi-hal-crypto.c
@@ -15,21 +15,21 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t pParam;
size_t key_data_size = 0;
- if (key->type == FuriHalCryptoKeyTypeMaster) {
+ if(key->type == FuriHalCryptoKeyTypeMaster) {
pParam.KeyType = KEYTYPE_MASTER;
- } else if (key->type == FuriHalCryptoKeyTypeSimple) {
+ } else if(key->type == FuriHalCryptoKeyTypeSimple) {
pParam.KeyType = KEYTYPE_SIMPLE;
- } else if (key->type == FuriHalCryptoKeyTypeEncrypted) {
+ } else if(key->type == FuriHalCryptoKeyTypeEncrypted) {
pParam.KeyType = KEYTYPE_ENCRYPTED;
key_data_size += 12;
} else {
furi_crash("Incorrect key type");
}
- if (key->size == FuriHalCryptoKeySize128) {
+ if(key->size == FuriHalCryptoKeySize128) {
pParam.KeySize = KEYSIZE_16;
key_data_size += 16;
- } else if (key->size == FuriHalCryptoKeySize256) {
+ } else if(key->size == FuriHalCryptoKeySize256) {
pParam.KeySize = KEYSIZE_32;
key_data_size += 32;
} else {
@@ -49,11 +49,12 @@ bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
crypt.Init.KeySize = CRYP_KEYSIZE_256B;
crypt.Init.Algorithm = CRYP_AES_CBC;
crypt.Init.pInitVect = (uint32_t*)iv;
+ crypt.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ONCE;
crypt.Init.pKey = NULL;
furi_check(HAL_CRYP_Init(&crypt) == HAL_OK);
- if (SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
+ if(SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
return true;
} else {
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
@@ -66,10 +67,10 @@ bool furi_hal_crypto_store_unload_key(uint8_t slot) {
return SHCI_C2_FUS_UnloadUsrKey(slot) == SHCI_Success;
}
-bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size) {
- return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
+bool furi_hal_crypto_encrypt(const uint8_t* input, uint8_t* output, size_t size) {
+ return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size / 4, (uint32_t*)output, 1000) == HAL_OK;
}
-bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size) {
- return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
+bool furi_hal_crypto_decrypt(const uint8_t* input, uint8_t* output, size_t size) {
+ return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size / 4, (uint32_t*)output, 1000) == HAL_OK;
}
diff --git a/firmware/targets/f7/furi-hal/furi-hal-crypto.c b/firmware/targets/f7/furi-hal/furi-hal-crypto.c
index 3e4ec98f..62f569f7 100644
--- a/firmware/targets/f7/furi-hal/furi-hal-crypto.c
+++ b/firmware/targets/f7/furi-hal/furi-hal-crypto.c
@@ -15,21 +15,21 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t pParam;
size_t key_data_size = 0;
- if (key->type == FuriHalCryptoKeyTypeMaster) {
+ if(key->type == FuriHalCryptoKeyTypeMaster) {
pParam.KeyType = KEYTYPE_MASTER;
- } else if (key->type == FuriHalCryptoKeyTypeSimple) {
+ } else if(key->type == FuriHalCryptoKeyTypeSimple) {
pParam.KeyType = KEYTYPE_SIMPLE;
- } else if (key->type == FuriHalCryptoKeyTypeEncrypted) {
+ } else if(key->type == FuriHalCryptoKeyTypeEncrypted) {
pParam.KeyType = KEYTYPE_ENCRYPTED;
key_data_size += 12;
} else {
furi_crash("Incorrect key type");
}
- if (key->size == FuriHalCryptoKeySize128) {
+ if(key->size == FuriHalCryptoKeySize128) {
pParam.KeySize = KEYSIZE_16;
key_data_size += 16;
- } else if (key->size == FuriHalCryptoKeySize256) {
+ } else if(key->size == FuriHalCryptoKeySize256) {
pParam.KeySize = KEYSIZE_32;
key_data_size += 32;
} else {
@@ -49,11 +49,12 @@ bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
crypt.Init.KeySize = CRYP_KEYSIZE_256B;
crypt.Init.Algorithm = CRYP_AES_CBC;
crypt.Init.pInitVect = (uint32_t*)iv;
+ crypt.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ONCE;
crypt.Init.pKey = NULL;
furi_check(HAL_CRYP_Init(&crypt) == HAL_OK);
- if (SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
+ if(SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
return true;
} else {
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
@@ -66,10 +67,10 @@ bool furi_hal_crypto_store_unload_key(uint8_t slot) {
return SHCI_C2_FUS_UnloadUsrKey(slot) == SHCI_Success;
}
-bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size) {
- return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
+bool furi_hal_crypto_encrypt(const uint8_t* input, uint8_t* output, size_t size) {
+ return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size / 4, (uint32_t*)output, 1000) == HAL_OK;
}
-bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size) {
- return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size/4, (uint32_t*)output, 1000) == HAL_OK;
+bool furi_hal_crypto_decrypt(const uint8_t* input, uint8_t* output, size_t size) {
+ return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size / 4, (uint32_t*)output, 1000) == HAL_OK;
}
diff --git a/firmware/targets/furi-hal-include/furi-hal-crypto.h b/firmware/targets/furi-hal-include/furi-hal-crypto.h
index 0428f781..482b3d7a 100644
--- a/firmware/targets/furi-hal-include/furi-hal-crypto.h
+++ b/firmware/targets/furi-hal-include/furi-hal-crypto.h
@@ -11,7 +11,7 @@
/** FuriHalCryptoKey Type */
typedef enum {
FuriHalCryptoKeyTypeMaster, /**< Master key */
- FuriHalCryptoKeyTypeSimple, /**< Simple enencrypted key */
+ FuriHalCryptoKeyTypeSimple, /**< Simple enencrypted key */
FuriHalCryptoKeyTypeEncrypted, /**< Encrypted with Master key */
} FuriHalCryptoKeyType;
@@ -59,7 +59,6 @@ bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv);
*/
bool furi_hal_crypto_store_unload_key(uint8_t slot);
-
/** Encrypt data
*
* @param input pointer to input data
@@ -68,7 +67,7 @@ bool furi_hal_crypto_store_unload_key(uint8_t slot);
*
* @return true on success
*/
-bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size);
+bool furi_hal_crypto_encrypt(const uint8_t* input, uint8_t* output, size_t size);
/** Decrypt data
*
@@ -78,4 +77,4 @@ bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size)
*
* @return true on success
*/
-bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size);
+bool furi_hal_crypto_decrypt(const uint8_t* input, uint8_t* output, size_t size);