hmac.h (1065B)
1 // hmac: https://datatracker.ietf.org/doc/html/rfc2104 2 3 #ifndef HMAC_H 4 #define HMAC_H 5 6 #include <stddef.h> 7 8 #define HMAC_BLOCK_SIZE 64 9 #define HMAC_IPAD_BYTE 0x36 10 #define HMAC_OPAD_BYTE 0x5c 11 12 struct hmac_hash { 13 void (*init)(void *ctx); 14 void (*push)(void *ctx, void const *buf, size_t len); 15 void (*dgst)(void *ctx, void *digest); 16 size_t digest_size; 17 }; 18 19 struct hmac_ctx { 20 unsigned char iv[HMAC_BLOCK_SIZE]; 21 unsigned char opad[HMAC_BLOCK_SIZE]; 22 unsigned char ipad[HMAC_BLOCK_SIZE]; 23 24 struct hmac_hash const *hash; 25 void *hash_ctx; 26 }; 27 28 void 29 hmac_gen_iv_block(struct hmac_ctx *ctx, 30 struct hmac_hash const *hash, void *restrict hash_ctx, 31 void const *restrict key, size_t key_len); 32 33 void 34 hmac_init(struct hmac_ctx *ctx); 35 36 void 37 hmac_push(struct hmac_ctx *ctx, void const *buf, size_t buf_len); 38 39 void 40 hmac_dgst(struct hmac_ctx *ctx, void *digest); 41 42 void 43 hmac(struct hmac_hash const *hash, void *restrict hash_ctx, 44 void const *restrict key, size_t key_len, 45 void const *restrict buf, size_t buf_len, 46 void *restrict digest); 47 48 #endif /* HMAC_H */