2021-10-03 13:36:05 +03:00
|
|
|
/**
|
|
|
|
* @file furi-hal-crypto.h
|
|
|
|
* Cryptography HAL API
|
|
|
|
*/
|
2021-09-15 12:59:49 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
/** FuriHalCryptoKey Type */
|
|
|
|
typedef enum {
|
|
|
|
FuriHalCryptoKeyTypeMaster, /**< Master key */
|
2021-11-01 16:11:25 +03:00
|
|
|
FuriHalCryptoKeyTypeSimple, /**< Simple enencrypted key */
|
2021-09-15 12:59:49 +03: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 13:36:05 +03:00
|
|
|
/** Initialize cryptography layer This includes AES engines, PKA and RNG
|
2021-09-15 12:59:49 +03:00
|
|
|
*/
|
|
|
|
void furi_hal_crypto_init();
|
|
|
|
|
|
|
|
/** Store key in crypto storage
|
2021-10-03 13:36:05 +03: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 12:59:49 +03: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 13:36:05 +03:00
|
|
|
*
|
|
|
|
* @param slot store slot number
|
|
|
|
* @param[in] iv pointer to 16 bytes Initialization Vector data
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-09-15 12:59:49 +03: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 13:36:05 +03:00
|
|
|
*
|
|
|
|
* @param slot store slot number
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-09-15 12:59:49 +03:00
|
|
|
*/
|
|
|
|
bool furi_hal_crypto_store_unload_key(uint8_t slot);
|
|
|
|
|
|
|
|
/** Encrypt data
|
2021-10-03 13:36:05 +03: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 12:59:49 +03:00
|
|
|
*/
|
2021-11-01 16:11:25 +03:00
|
|
|
bool furi_hal_crypto_encrypt(const uint8_t* input, uint8_t* output, size_t size);
|
2021-09-15 12:59:49 +03:00
|
|
|
|
|
|
|
/** Decrypt data
|
2021-10-03 13:36:05 +03: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 12:59:49 +03:00
|
|
|
*/
|
2021-11-01 16:11:25 +03:00
|
|
|
bool furi_hal_crypto_decrypt(const uint8_t* input, uint8_t* output, size_t size);
|