From aa83760418f5ed5ce35a9add6517b2ca98ccb5bd Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Wed, 22 Mar 2023 16:44:03 +0100 Subject: Add crypto sources for future use. * the goal is to support AES-CBC-HMAC-SHA as AEAD cipher Signed-off-by: Toni Uhlig --- crypto/hmac.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 crypto/hmac.c (limited to 'crypto/hmac.c') diff --git a/crypto/hmac.c b/crypto/hmac.c new file mode 100644 index 0000000..f9b81c1 --- /dev/null +++ b/crypto/hmac.c @@ -0,0 +1,37 @@ +#include "hmac.h" + +/* function doing the HMAC-SHA-1 calculation */ +void hmac_sha1(const uint8_t* key, const uint32_t keysize, const uint8_t* msg, const uint32_t msgsize, uint8_t* output) +{ + struct sha1 outer, inner; + uint8_t tmp; + + sha1_reset(&outer); + sha1_reset(&inner); + + uint32_t i; + for (i = 0; i < keysize; ++i) + { + tmp = key[i] ^ 0x5C; + sha1_input(&outer, &tmp, 1); + tmp = key[i] ^ 0x36; + sha1_input(&inner, &tmp, 1); + } + for (; i < 64; ++i) + { + tmp = 0x5C; + sha1_input(&outer, &tmp, 1); + tmp = 0x36; + sha1_input(&inner, &tmp, 1); + } + + sha1_input(&inner, msg, msgsize); + sha1_result(&inner, output); + + sha1_input(&outer, output, HMAC_SHA1_HASH_SIZE); + sha1_result(&outer, output); +} + + + + -- cgit v1.2.3