crypto_wrapper.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(
  19. ESubGhzChatCryptoCtx* ctx,
  20. const uint8_t* key,
  21. FuriString* flipper_name,
  22. uint32_t tick);
  23. void crypto_ctx_get_key(ESubGhzChatCryptoCtx* ctx, uint8_t* key);
  24. bool crypto_ctx_decrypt(ESubGhzChatCryptoCtx* ctx, uint8_t* in, size_t in_len, uint8_t* out);
  25. bool crypto_ctx_encrypt(ESubGhzChatCryptoCtx* ctx, uint8_t* in, size_t in_len, uint8_t* out);
  26. typedef bool (*CryptoCtxReplayDictWriter)(uint64_t run_id, uint32_t counter, void* context);
  27. typedef bool (*CryptoCtxReplayDictReader)(uint64_t* run_id, uint32_t* counter, void* context);
  28. size_t crypto_ctx_dump_replay_dict(
  29. ESubGhzChatCryptoCtx* ctx,
  30. CryptoCtxReplayDictWriter writer,
  31. void* writer_ctx);
  32. size_t crypto_ctx_read_replay_dict(
  33. ESubGhzChatCryptoCtx* ctx,
  34. CryptoCtxReplayDictReader reader,
  35. void* reader_ctx);
  36. #ifdef __cplusplus
  37. }
  38. #endif