Hello,
In testutils.h, there is a nettle-meta definition for MACs, similar to hashes and ciphers:
/* FIXME: When interface stabilizes, move to nettle-meta.h */ struct nettle_mac { const char *name;
/* Size of the context struct */ unsigned context_size;
/* Size of digests */ unsigned digest_size;
/* Suggested key size; other sizes are sometimes possible. */ unsigned key_size;
nettle_set_key_func *set_key; nettle_hash_update_func *update; nettle_hash_digest_func *digest; };
This is, however, not usable for HMAC, because Nettle build uses -Wcast-function-type and the set_key member has an incompatible type with hmac_*_set_key, which requires a key length argument as HMAC allows arbitrary key length up to the hash block size.
Is there any plan to make it more generic and eventually move it to nettle-meta.h? That would be particularly useful in applications passing around HMAC functions (e.g., HKDF, deterministic ECDSA).
For example, I'm thinking to use nettle_hash_update_func for set_key and provide a wrapper around other MACs which don't take key length, something like:
void _cmac_aes128_set_key(struct cmac_aes128_ctx *ctx, size_t length, const uint8_t *key) { assert (length == AES128_KEY_LENGTH); cmac_aes128_set_key (ctx, length, key); }
Regards,