furi_hal_crypto.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @file furi_hal_crypto.h
  3. * Cryptography HAL API
  4. */
  5. #pragma once
  6. #include <stdbool.h>
  7. #include <stdint.h>
  8. #include <stddef.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /** FuriHalCryptoKey Type */
  13. typedef enum {
  14. FuriHalCryptoKeyTypeMaster, /**< Master key */
  15. FuriHalCryptoKeyTypeSimple, /**< Simple enencrypted key */
  16. FuriHalCryptoKeyTypeEncrypted, /**< Encrypted with Master key */
  17. } FuriHalCryptoKeyType;
  18. /** FuriHalCryptoKey Size in bits */
  19. typedef enum {
  20. FuriHalCryptoKeySize128,
  21. FuriHalCryptoKeySize256,
  22. } FuriHalCryptoKeySize;
  23. /** FuriHalCryptoKey */
  24. typedef struct {
  25. FuriHalCryptoKeyType type;
  26. FuriHalCryptoKeySize size;
  27. uint8_t* data;
  28. } FuriHalCryptoKey;
  29. /** Initialize cryptography layer This includes AES engines, PKA and RNG
  30. */
  31. void furi_hal_crypto_init();
  32. bool furi_hal_crypto_verify_enclave(uint8_t* keys_nb, uint8_t* valid_keys_nb);
  33. bool furi_hal_crypto_verify_key(uint8_t key_slot);
  34. /** Store key in crypto storage
  35. *
  36. * @param key FuriHalCryptoKey to store. Only Master, Simple or
  37. * Encrypted
  38. * @param slot pinter to int where store slot number will be saved
  39. *
  40. * @return true on success
  41. */
  42. bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot);
  43. /** Init AES engine and load key from crypto store
  44. *
  45. * @param slot store slot number
  46. * @param[in] iv pointer to 16 bytes Initialization Vector data
  47. *
  48. * @return true on success
  49. */
  50. bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv);
  51. /** Unload key engine and deinit AES engine
  52. *
  53. * @param slot store slot number
  54. *
  55. * @return true on success
  56. */
  57. bool furi_hal_crypto_store_unload_key(uint8_t slot);
  58. /** Encrypt data
  59. *
  60. * @param input pointer to input data
  61. * @param output pointer to output data
  62. * @param size input/output buffer size in bytes
  63. *
  64. * @return true on success
  65. */
  66. bool furi_hal_crypto_encrypt(const uint8_t* input, uint8_t* output, size_t size);
  67. /** Decrypt data
  68. *
  69. * @param input pointer to input data
  70. * @param output pointer to output data
  71. * @param size input/output buffer size in bytes
  72. *
  73. * @return true on success
  74. */
  75. bool furi_hal_crypto_decrypt(const uint8_t* input, uint8_t* output, size_t size);
  76. #ifdef __cplusplus
  77. }
  78. #endif