[FL-1490] FuriHal: crypto api. Crypto cli tool. (#702)
* FuriHal: crypto layer * Furi: add crash routine. * FuriHal: crypto api. Crypto: cli command to manipulate secure enclave and encrypt/decrypt plain text. * DeviceInfo: secure enclave verification. * Rename original to enclave_valid * Update expected enclave signature to match production keys * F7: remove unused files
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file aes.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the aes.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __AES_H__
|
||||
#define __AES_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern CRYP_HandleTypeDef hcryp1;
|
||||
extern CRYP_HandleTypeDef hcryp2;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_AES1_Init(void);
|
||||
void MX_AES2_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AES_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pka.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the pka.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __PKA_H__
|
||||
#define __PKA_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern PKA_HandleTypeDef hpka;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_PKA_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PKA_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -1,50 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rf.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rf.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RF_H__
|
||||
#define __RF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_RF_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RF_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rng.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rng.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RNG_H__
|
||||
#define __RNG_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern RNG_HandleTypeDef hrng;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_RNG_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RNG_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -1,127 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file aes.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the AES instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "aes.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
CRYP_HandleTypeDef hcryp1;
|
||||
__ALIGN_BEGIN static const uint32_t pKeyAES1[4] __ALIGN_END = {
|
||||
0x00000000,0x00000000,0x00000000,0x00000000};
|
||||
CRYP_HandleTypeDef hcryp2;
|
||||
__ALIGN_BEGIN static const uint32_t pKeyAES2[4] __ALIGN_END = {
|
||||
0x00000000,0x00000000,0x00000000,0x00000000};
|
||||
|
||||
/* AES1 init function */
|
||||
void MX_AES1_Init(void)
|
||||
{
|
||||
|
||||
hcryp1.Instance = AES1;
|
||||
hcryp1.Init.DataType = CRYP_DATATYPE_32B;
|
||||
hcryp1.Init.KeySize = CRYP_KEYSIZE_128B;
|
||||
hcryp1.Init.pKey = (uint32_t *)pKeyAES1;
|
||||
hcryp1.Init.Algorithm = CRYP_AES_ECB;
|
||||
hcryp1.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
|
||||
hcryp1.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
|
||||
if (HAL_CRYP_Init(&hcryp1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
/* AES2 init function */
|
||||
void MX_AES2_Init(void)
|
||||
{
|
||||
|
||||
hcryp2.Instance = AES2;
|
||||
hcryp2.Init.DataType = CRYP_DATATYPE_32B;
|
||||
hcryp2.Init.KeySize = CRYP_KEYSIZE_128B;
|
||||
hcryp2.Init.pKey = (uint32_t *)pKeyAES2;
|
||||
hcryp2.Init.Algorithm = CRYP_AES_ECB;
|
||||
hcryp2.Init.DataWidthUnit = CRYP_DATAWIDTHUNIT_WORD;
|
||||
hcryp2.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ALWAYS;
|
||||
if (HAL_CRYP_Init(&hcryp2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_CRYP_MspInit(CRYP_HandleTypeDef* crypHandle)
|
||||
{
|
||||
|
||||
if(crypHandle->Instance==AES1)
|
||||
{
|
||||
/* USER CODE BEGIN AES1_MspInit 0 */
|
||||
|
||||
/* USER CODE END AES1_MspInit 0 */
|
||||
/* AES1 clock enable */
|
||||
__HAL_RCC_AES1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN AES1_MspInit 1 */
|
||||
|
||||
/* USER CODE END AES1_MspInit 1 */
|
||||
}
|
||||
else if(crypHandle->Instance==AES2)
|
||||
{
|
||||
/* USER CODE BEGIN AES2_MspInit 0 */
|
||||
|
||||
/* USER CODE END AES2_MspInit 0 */
|
||||
/* AES2 clock enable */
|
||||
__HAL_RCC_AES2_CLK_ENABLE();
|
||||
/* USER CODE BEGIN AES2_MspInit 1 */
|
||||
|
||||
/* USER CODE END AES2_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CRYP_MspDeInit(CRYP_HandleTypeDef* crypHandle)
|
||||
{
|
||||
|
||||
if(crypHandle->Instance==AES1)
|
||||
{
|
||||
/* USER CODE BEGIN AES1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END AES1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_AES1_CLK_DISABLE();
|
||||
/* USER CODE BEGIN AES1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END AES1_MspDeInit 1 */
|
||||
}
|
||||
else if(crypHandle->Instance==AES2)
|
||||
{
|
||||
/* USER CODE BEGIN AES2_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END AES2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_AES2_CLK_DISABLE();
|
||||
/* USER CODE BEGIN AES2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END AES2_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file pka.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the PKA instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "pka.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
PKA_HandleTypeDef hpka;
|
||||
|
||||
/* PKA init function */
|
||||
void MX_PKA_Init(void)
|
||||
{
|
||||
|
||||
hpka.Instance = PKA;
|
||||
if (HAL_PKA_Init(&hpka) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_PKA_MspInit(PKA_HandleTypeDef* pkaHandle)
|
||||
{
|
||||
|
||||
if(pkaHandle->Instance==PKA)
|
||||
{
|
||||
/* USER CODE BEGIN PKA_MspInit 0 */
|
||||
|
||||
/* USER CODE END PKA_MspInit 0 */
|
||||
/* PKA clock enable */
|
||||
__HAL_RCC_PKA_CLK_ENABLE();
|
||||
/* USER CODE BEGIN PKA_MspInit 1 */
|
||||
|
||||
/* USER CODE END PKA_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_PKA_MspDeInit(PKA_HandleTypeDef* pkaHandle)
|
||||
{
|
||||
|
||||
if(pkaHandle->Instance==PKA)
|
||||
{
|
||||
/* USER CODE BEGIN PKA_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END PKA_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_PKA_CLK_DISABLE();
|
||||
/* USER CODE BEGIN PKA_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END PKA_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rf.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RF instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "rf.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* RF init function */
|
||||
void MX_RF_Init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rng.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RNG instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "rng.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
RNG_HandleTypeDef hrng;
|
||||
|
||||
/* RNG init function */
|
||||
void MX_RNG_Init(void)
|
||||
{
|
||||
|
||||
hrng.Instance = RNG;
|
||||
if (HAL_RNG_Init(&hrng) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_RNG_MspInit(RNG_HandleTypeDef* rngHandle)
|
||||
{
|
||||
|
||||
if(rngHandle->Instance==RNG)
|
||||
{
|
||||
/* USER CODE BEGIN RNG_MspInit 0 */
|
||||
|
||||
/* USER CODE END RNG_MspInit 0 */
|
||||
/* RNG clock enable */
|
||||
__HAL_RCC_RNG_CLK_ENABLE();
|
||||
/* USER CODE BEGIN RNG_MspInit 1 */
|
||||
|
||||
/* USER CODE END RNG_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_RNG_MspDeInit(RNG_HandleTypeDef* rngHandle)
|
||||
{
|
||||
|
||||
if(rngHandle->Instance==RNG)
|
||||
{
|
||||
/* USER CODE BEGIN RNG_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END RNG_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_RNG_CLK_DISABLE();
|
||||
/* USER CODE BEGIN RNG_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END RNG_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <furi-hal-clock.h>
|
||||
#include <furi.h>
|
||||
|
||||
#include <main.h>
|
||||
#include <stm32wbxx_ll_pwr.h>
|
||||
#include <stm32wbxx_ll_rcc.h>
|
||||
#include <stm32wbxx_ll_utils.h>
|
||||
@@ -107,6 +107,12 @@ void furi_hal_clock_init() {
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOE);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOH);
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_AES1);
|
||||
|
||||
// AHB3
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PKA);
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_RNG);
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_AES2);
|
||||
|
||||
// APB1
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);
|
||||
@@ -114,6 +120,8 @@ void furi_hal_clock_init() {
|
||||
|
||||
// APB2
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||
|
||||
FURI_LOG_I("FuriHalClock", "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_clock_switch_to_hsi() {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include <furi-hal-crypto.h>
|
||||
#include <furi.h>
|
||||
#include <shci.h>
|
||||
|
||||
CRYP_HandleTypeDef crypt;
|
||||
|
||||
void furi_hal_crypto_init() {
|
||||
FURI_LOG_I("FuriHalCrypto", "Init OK");
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
|
||||
furi_assert(key);
|
||||
furi_assert(slot);
|
||||
|
||||
SHCI_C2_FUS_StoreUsrKey_Cmd_Param_t pParam;
|
||||
|
||||
if (key->type == FuriHalCryptoKeyTypeMaster) {
|
||||
pParam.KeyType = KEYTYPE_MASTER;
|
||||
} else if (key->type == FuriHalCryptoKeyTypeSimple) {
|
||||
pParam.KeyType = KEYTYPE_SIMPLE;
|
||||
} else if (key->type == FuriHalCryptoKeyTypeEncrypted) {
|
||||
pParam.KeyType = KEYTYPE_ENCRYPTED;
|
||||
} else {
|
||||
furi_crash("Incorrect key type");
|
||||
}
|
||||
|
||||
if (key->size == FuriHalCryptoKeySize128) {
|
||||
pParam.KeySize = KEYSIZE_16;
|
||||
} else if (key->size == FuriHalCryptoKeySize256) {
|
||||
pParam.KeySize = KEYSIZE_32;
|
||||
} else {
|
||||
furi_crash("Incorrect key size");
|
||||
}
|
||||
|
||||
return SHCI_C2_FUS_StoreUsrKey(&pParam, slot) == SHCI_Success;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
|
||||
furi_assert(slot > 0 && slot <= 100);
|
||||
|
||||
crypt.Instance = AES1;
|
||||
crypt.Init.DataType = CRYP_DATATYPE_32B;
|
||||
crypt.Init.KeySize = CRYP_KEYSIZE_256B;
|
||||
crypt.Init.Algorithm = CRYP_AES_CBC;
|
||||
crypt.Init.pInitVect = (uint32_t*)iv;
|
||||
crypt.Init.pKey = NULL;
|
||||
|
||||
furi_check(HAL_CRYP_Init(&crypt) == HAL_OK);
|
||||
|
||||
if (SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
|
||||
return true;
|
||||
} else {
|
||||
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_unload_key(uint8_t slot) {
|
||||
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
|
||||
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_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;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR is
|
||||
}
|
||||
furi_hal_tim_tim1_isr = isr;
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ void furi_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel,
|
||||
} else if (dma == DMA2) {
|
||||
furi_hal_dma_channel_isr[1][channel] = isr;
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) {
|
||||
static void furi_hal_irda_tx_dma_polarity_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TE1(DMA1)) {
|
||||
LL_DMA_ClearFlag_TE1(DMA1);
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_TC1(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_1)) {
|
||||
LL_DMA_ClearFlag_TC1(DMA1);
|
||||
@@ -261,7 +261,7 @@ static void furi_hal_irda_tx_dma_polarity_isr() {
|
||||
static void furi_hal_irda_tx_dma_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TE2(DMA1)) {
|
||||
LL_DMA_ClearFlag_TE2(DMA1);
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) {
|
||||
LL_DMA_ClearFlag_HT2(DMA1);
|
||||
@@ -277,7 +277,7 @@ static void furi_hal_irda_tx_dma_isr() {
|
||||
} else if (furi_hal_irda_state == IrdaStateAsyncTxStopReq) {
|
||||
/* fallthrough */
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) {
|
||||
@@ -557,7 +557,7 @@ static void furi_hal_irda_async_tx_free_resources(void) {
|
||||
|
||||
void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
if ((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
|
||||
furi_assert(furi_hal_irda_state == IrdaStateIdle);
|
||||
|
||||
@@ -261,7 +261,7 @@ void furi_hal_rfid_set_emulate_pulse(uint32_t pulse) {
|
||||
LFRFID_EMULATE_TIM.Instance->CCR4 = pulse;
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -285,7 +285,7 @@ void furi_hal_rfid_set_read_pulse(uint32_t pulse) {
|
||||
LFRFID_TIM.Instance->CCR4 = pulse;
|
||||
break;
|
||||
default:
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
|
||||
furi_hal_subghz_load_registers(furi_hal_subghz_preset_2fsk_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_2fsk_async_patable);
|
||||
}else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
|
||||
} else if(value >= 778999847 && value <= 928000000) {
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPath868);
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -424,7 +424,7 @@ void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
} else {
|
||||
furi_check(0);
|
||||
furi_crash(NULL);
|
||||
}
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ void furi_hal_version_init() {
|
||||
case FuriHalVersionOtpVersion1:
|
||||
furi_hal_version_load_otp_v1();
|
||||
break;
|
||||
default: furi_check(0);
|
||||
default: furi_crash(NULL);
|
||||
}
|
||||
FURI_LOG_I("FuriHalVersion", "Init OK");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#include <furi-hal.h>
|
||||
|
||||
#include <aes.h>
|
||||
#include <comp.h>
|
||||
#include <pka.h>
|
||||
#include <rf.h>
|
||||
#include <rng.h>
|
||||
#include <rtc.h>
|
||||
#include <tim.h>
|
||||
#include <usb_device.h>
|
||||
@@ -34,16 +30,8 @@ void furi_hal_init() {
|
||||
FURI_LOG_I("HAL", "TIM16 OK");
|
||||
MX_COMP1_Init();
|
||||
FURI_LOG_I("HAL", "COMP1 OK");
|
||||
MX_RF_Init();
|
||||
FURI_LOG_I("HAL", "RF OK");
|
||||
MX_PKA_Init();
|
||||
FURI_LOG_I("HAL", "PKA OK");
|
||||
MX_RNG_Init();
|
||||
FURI_LOG_I("HAL", "RNG OK");
|
||||
MX_AES1_Init();
|
||||
FURI_LOG_I("HAL", "AES1 OK");
|
||||
MX_AES2_Init();
|
||||
FURI_LOG_I("HAL", "AES2 OK");
|
||||
|
||||
furi_hal_crypto_init();
|
||||
|
||||
// VCP + USB
|
||||
furi_hal_vcp_init();
|
||||
|
||||
@@ -53,12 +53,9 @@ C_SOURCES += \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_ipcc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pka.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rng.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rtc_ex.c \
|
||||
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \
|
||||
@@ -81,7 +78,6 @@ CFLAGS += \
|
||||
-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \
|
||||
-I$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
|
||||
C_SOURCES += \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/list.c \
|
||||
$(CUBE_DIR)/Middlewares/Third_Party/FreeRTOS/Source/queue.c \
|
||||
|
||||
Reference in New Issue
Block a user