hmac_sha256.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include "sha256.h"
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef struct hmac_context {
  7. void (*init_hash)(const struct hmac_context* context);
  8. void (*update_hash)(
  9. const struct hmac_context* context,
  10. const uint8_t* message,
  11. unsigned message_size);
  12. void (*finish_hash)(const struct hmac_context* context, uint8_t* hash_result);
  13. unsigned block_size; /* Hash function block size in bytes, eg 64 for SHA-256. */
  14. unsigned result_size; /* Hash function result size in bytes, eg 32 for SHA-256. */
  15. uint8_t* tmp; /* Must point to a buffer of at least (2 * result_size + block_size) bytes. */
  16. } hmac_context;
  17. typedef struct hmac_sha256_context {
  18. hmac_context hmac_ctx;
  19. sha256_context sha_ctx;
  20. uint8_t tmp[32 * 2 + 64];
  21. } hmac_sha256_context;
  22. void hmac_sha256_init(hmac_sha256_context* ctx, const uint8_t* K);
  23. void hmac_sha256_update(
  24. const hmac_sha256_context* ctx,
  25. const uint8_t* message,
  26. unsigned message_size);
  27. void hmac_sha256_finish(const hmac_sha256_context* ctx, const uint8_t* K, uint8_t* hash_result);
  28. #ifdef __cplusplus
  29. }
  30. #endif