furi_hal_crypto.h 2.2 KB

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