furi-hal-crypto.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. /** FuriHalCryptoKey Type */
  6. typedef enum {
  7. FuriHalCryptoKeyTypeMaster, /**< Master key */
  8. FuriHalCryptoKeyTypeSimple, /**< Simple enencrypted key */
  9. FuriHalCryptoKeyTypeEncrypted, /**< Encrypted with Master key */
  10. } FuriHalCryptoKeyType;
  11. /** FuriHalCryptoKey Size in bits */
  12. typedef enum {
  13. FuriHalCryptoKeySize128,
  14. FuriHalCryptoKeySize256,
  15. } FuriHalCryptoKeySize;
  16. /** FuriHalCryptoKey */
  17. typedef struct {
  18. FuriHalCryptoKeyType type;
  19. FuriHalCryptoKeySize size;
  20. uint8_t* data;
  21. } FuriHalCryptoKey;
  22. /** Initialize cryptography layer
  23. * This includes AES engines, PKA and RNG
  24. */
  25. void furi_hal_crypto_init();
  26. /** Store key in crypto storage
  27. * @param key - FuriHalCryptoKey to store. Only Master, Simple or Encrypted
  28. * @param slot - pinter to int where store slot number will be saved
  29. * @return true on success
  30. */
  31. bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot);
  32. /** Init AES engine and load key from crypto store
  33. * @param slot - store slot number
  34. * @return true on success
  35. */
  36. bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv);
  37. /** Unload key engine and deinit AES engine
  38. * @param slot - store slot number
  39. * @return true on success
  40. */
  41. bool furi_hal_crypto_store_unload_key(uint8_t slot);
  42. /** Encrypt data
  43. * @param input - pointer to input data
  44. * @param output - pointer to output data
  45. * @param size - input/output buffer size in bytes
  46. * @return true on success
  47. */
  48. bool furi_hal_crypto_encrypt(const uint8_t *input, uint8_t *output, size_t size);
  49. /** Decrypt data
  50. * @param input - pointer to input data
  51. * @param output - pointer to output data
  52. * @param size - input/output buffer size in bytes
  53. * @return true on success
  54. */
  55. bool furi_hal_crypto_decrypt(const uint8_t *input, uint8_t *output, size_t size);