diff options
| author | Benedict <benedict@0xb8000.de> | 2016-09-02 20:12:53 +0200 |
|---|---|---|
| committer | Benedict <benedict@0xb8000.de> | 2017-02-21 13:00:26 +0100 |
| commit | fe73b0589483a11389fd68b1b0910229039bfcca (patch) | |
| tree | 614e416715fc4835c83edbe4632a934d540a97d6 /lib/lib4.c | |
| parent | 2f6023b20f70885b874bf78c4c07046b30c479ab (diff) | |
completed set4, challenge 28
Diffstat (limited to 'lib/lib4.c')
| -rw-r--r-- | lib/lib4.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -20,3 +20,31 @@ int aes_ctr_edit(char *ciphertext, int ciphertext_length, int offset, char *newt aes_ctr(plaintext, ciphertext_length, ciphertext, key, nonce); return 0; } + +void sha1_hmac(unsigned int *mac, unsigned char *message, unsigned int msg_len, unsigned char *key, + unsigned int key_len) +{ + char *res = malloc(msg_len + key_len); + + memcpy(res, key, key_len); + memcpy(&res[key_len], message, msg_len); + + SHA1Context sh; + + SHA1Reset(&sh); + SHA1Input(&sh, res, (msg_len + key_len)); + SHA1Result(&sh); + + memcpy(mac, &(sh.Message_Digest), 20); +} + +int sha1_hmac_verify(unsigned int *mac, unsigned char *msg, unsigned int msg_len, + unsigned char *key, unsigned int key_len) +{ + unsigned int com_mac[5]; + + sha1_hmac(com_mac, msg, msg_len, key, key_len); + + return !memcmp(com_mac, mac, 20); + +} |
