diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2023-03-22 16:44:03 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2023-03-22 16:44:03 +0100 |
commit | aa83760418f5ed5ce35a9add6517b2ca98ccb5bd (patch) | |
tree | 784d5e108ea31e20c5183cc9508d695f35e626bc /crypto/hmac.c | |
parent | ba6815ef8fb8ae472412b5af2837a7caba2799c2 (diff) |
Add crypto sources for future use.add/crypto
* the goal is to support AES-CBC-HMAC-SHA as AEAD cipher
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'crypto/hmac.c')
-rw-r--r-- | crypto/hmac.c | 37 |
1 files changed, 37 insertions, 0 deletions
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); +} + + + + |