crypto_wrapper.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #define RUN_ID_BYTES (sizeof(uint64_t))
  6. #define COUNTER_BYTES (sizeof(uint32_t))
  7. #define KEY_BITS 256
  8. #define IV_BYTES 12
  9. #define TAG_BYTES 16
  10. #define MSG_OVERHEAD (RUN_ID_BYTES + COUNTER_BYTES + IV_BYTES + TAG_BYTES)
  11. typedef struct ESugGhzChatCryptoCtx ESubGhzChatCryptoCtx;
  12. void crypto_init(void);
  13. /* Function to clear sensitive memory. */
  14. void crypto_explicit_bzero(void *s, size_t len);
  15. ESubGhzChatCryptoCtx *crypto_ctx_alloc(void);
  16. void crypto_ctx_free(ESubGhzChatCryptoCtx *ctx);
  17. void crypto_ctx_clear(ESubGhzChatCryptoCtx *ctx);
  18. bool crypto_ctx_set_key(ESubGhzChatCryptoCtx *ctx, const uint8_t *key,
  19. FuriString *flipper_name, uint32_t tick);
  20. void crypto_ctx_get_key(ESubGhzChatCryptoCtx *ctx, uint8_t *key);
  21. bool crypto_ctx_decrypt(ESubGhzChatCryptoCtx *ctx, uint8_t *in, size_t in_len,
  22. uint8_t *out);
  23. bool crypto_ctx_encrypt(ESubGhzChatCryptoCtx *ctx, uint8_t *in, size_t in_len,
  24. uint8_t *out);
  25. typedef bool (*CryptoCtxReplayDictWriter)(uint64_t run_id, uint32_t counter,
  26. void *context);
  27. typedef bool (*CryptoCtxReplayDictReader)(uint64_t *run_id, uint32_t *counter,
  28. void *context);
  29. size_t crypto_ctx_dump_replay_dict(ESubGhzChatCryptoCtx *ctx,
  30. CryptoCtxReplayDictWriter writer, void *writer_ctx);
  31. size_t crypto_ctx_read_replay_dict(ESubGhzChatCryptoCtx *ctx,
  32. CryptoCtxReplayDictReader reader, void *reader_ctx);
  33. #ifdef __cplusplus
  34. }
  35. #endif