hmac_sha256.h 1.0 KB

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