hmac_sha256.h 1021 B

123456789101112131415161718192021222324252627
  1. typedef struct hmac_context {
  2. void (*init_hash)(const struct hmac_context* context);
  3. void (*update_hash)(
  4. const struct hmac_context* context,
  5. const uint8_t* message,
  6. unsigned message_size);
  7. void (*finish_hash)(const struct hmac_context* context, uint8_t* hash_result);
  8. unsigned block_size; /* Hash function block size in bytes, eg 64 for SHA-256. */
  9. unsigned result_size; /* Hash function result size in bytes, eg 32 for SHA-256. */
  10. uint8_t* tmp; /* Must point to a buffer of at least (2 * result_size + block_size) bytes. */
  11. } hmac_context;
  12. typedef struct hmac_sha256_context {
  13. hmac_context hmac_ctx;
  14. sha256_context sha_ctx;
  15. uint8_t tmp[32 * 2 + 64];
  16. } hmac_sha256_context;
  17. void hmac_sha256_init(hmac_sha256_context* ctx, const uint8_t* K);
  18. void hmac_sha256_update(
  19. const hmac_sha256_context* ctx,
  20. const uint8_t* message,
  21. unsigned message_size);
  22. void hmac_sha256_finish(const hmac_sha256_context* ctx, const uint8_t* K, uint8_t* hash_result);