2021-10-03 10:36:05 +00:00
|
|
|
/**
|
2022-01-05 16:10:18 +00:00
|
|
|
* @file furi_hal_crypto.h
|
2021-10-03 10:36:05 +00:00
|
|
|
* Cryptography HAL API
|
|
|
|
*/
|
2021-09-15 09:59:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-09-15 09:59:49 +00:00
|
|
|
/** FuriHalCryptoKey Type */
|
|
|
|
typedef enum {
|
|
|
|
FuriHalCryptoKeyTypeMaster, /**< Master key */
|
2021-11-01 13:11:25 +00:00
|
|
|
FuriHalCryptoKeyTypeSimple, /**< Simple enencrypted key */
|
2021-09-15 09:59:49 +00:00
|
|
|
FuriHalCryptoKeyTypeEncrypted, /**< Encrypted with Master key */
|
|
|
|
} FuriHalCryptoKeyType;
|
|
|
|
|
|
|
|
/** FuriHalCryptoKey Size in bits */
|
|
|
|
typedef enum {
|
|
|
|
FuriHalCryptoKeySize128,
|
|
|
|
FuriHalCryptoKeySize256,
|
|
|
|
} FuriHalCryptoKeySize;
|
|
|
|
|
|
|
|
/** FuriHalCryptoKey */
|
|
|
|
typedef struct {
|
|
|
|
FuriHalCryptoKeyType type;
|
|
|
|
FuriHalCryptoKeySize size;
|
|
|
|
uint8_t* data;
|
|
|
|
} FuriHalCryptoKey;
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Initialize cryptography layer This includes AES engines, PKA and RNG
|
2021-09-15 09:59:49 +00:00
|
|
|
*/
|
|
|
|
void furi_hal_crypto_init();
|
|
|
|
|
2021-12-22 20:04:08 +00:00
|
|
|
bool furi_hal_crypto_verify_enclave(uint8_t* keys_nb, uint8_t* valid_keys_nb);
|
|
|
|
|
|
|
|
bool furi_hal_crypto_verify_key(uint8_t key_slot);
|
|
|
|
|
2021-09-15 09:59:49 +00:00
|
|
|
/** Store key in crypto storage
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param key FuriHalCryptoKey to store. Only Master, Simple or
|
|
|
|
* Encrypted
|
|
|
|
* @param slot pinter to int where store slot number will be saved
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-09-15 09:59:49 +00:00
|
|
|
*/
|
|
|
|
bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot);
|
|
|
|
|
|
|
|
/** Init AES engine and load key from crypto store
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param slot store slot number
|
|
|
|
* @param[in] iv pointer to 16 bytes Initialization Vector data
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-09-15 09:59:49 +00:00
|
|
|
*/
|
|
|
|
bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv);
|
|
|
|
|
|
|
|
/** Unload key engine and deinit AES engine
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param slot store slot number
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-09-15 09:59:49 +00:00
|
|
|
*/
|
|
|
|
bool furi_hal_crypto_store_unload_key(uint8_t slot);
|
|
|
|
|
|
|
|
/** Encrypt data
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param input pointer to input data
|
|
|
|
* @param output pointer to output data
|
|
|
|
* @param size input/output buffer size in bytes
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-09-15 09:59:49 +00:00
|
|
|
*/
|
2021-11-01 13:11:25 +00:00
|
|
|
bool furi_hal_crypto_encrypt(const uint8_t* input, uint8_t* output, size_t size);
|
2021-09-15 09:59:49 +00:00
|
|
|
|
|
|
|
/** Decrypt data
|
2021-10-03 10:36:05 +00:00
|
|
|
*
|
|
|
|
* @param input pointer to input data
|
|
|
|
* @param output pointer to output data
|
|
|
|
* @param size input/output buffer size in bytes
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-09-15 09:59:49 +00:00
|
|
|
*/
|
2021-11-01 13:11:25 +00:00
|
|
|
bool furi_hal_crypto_decrypt(const uint8_t* input, uint8_t* output, size_t size);
|
2022-09-14 16:11:38 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|