furi-hal-crypto.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /** Store key in crypto storage
  30. *
  31. * @param key FuriHalCryptoKey to store. Only Master, Simple or
  32. * Encrypted
  33. * @param slot pinter to int where store slot number will be saved
  34. *
  35. * @return true on success
  36. */
  37. bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot);
  38. /** Init AES engine and load key from crypto store
  39. *
  40. * @param slot store slot number
  41. * @param[in] iv pointer to 16 bytes Initialization Vector data
  42. *
  43. * @return true on success
  44. */
  45. bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv);
  46. /** Unload key engine and deinit AES engine
  47. *
  48. * @param slot store slot number
  49. *
  50. * @return true on success
  51. */
  52. bool furi_hal_crypto_store_unload_key(uint8_t slot);
  53. /** Encrypt data
  54. *
  55. * @param input pointer to input data
  56. * @param output pointer to output data
  57. * @param size input/output buffer size in bytes
  58. *
  59. * @return true on success
  60. */
  61. bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size);
  62. /** Decrypt data
  63. *
  64. * @param input pointer to input data
  65. * @param output pointer to output data
  66. * @param size input/output buffer size in bytes
  67. *
  68. * @return true on success
  69. */
  70. bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size);