summaryrefslogtreecommitdiff
path: root/src/hmac_md5.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/hmac_md5.c
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/hmac_md5.c')
-rw-r--r--src/hmac_md5.c75
1 files changed, 38 insertions, 37 deletions
diff --git a/src/hmac_md5.c b/src/hmac_md5.c
index 310f0ef..5c46653 100644
--- a/src/hmac_md5.c
+++ b/src/hmac_md5.c
@@ -1,7 +1,8 @@
+#include "byte.h"
+#include "str.h"
+
#include "global.h"
#include "md5.h"
-#include "str.h"
-#include "byte.h"
/**
@file hmac_md5
@@ -13,40 +14,40 @@
output: unsigned char *digest: pointer to calculated digest
*/
-void hmac_md5(unsigned char *text,int text_len,unsigned char * key,int key_len,unsigned char *digest)
+void hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest)
{
- MD5_CTX context;
- unsigned char k_ipad[65]; /* inner padding - key XORd with ipad */
- unsigned char k_opad[65]; /* outer padding - key XORd with opad */
- unsigned char tk[16];
- int i;
-
- if (key_len > 64) {
- MD5_CTX tctx;
- MD5Init(&tctx);
- MD5Update(&tctx,key,key_len);
- MD5Final(tk,&tctx);
- key = tk;
- key_len = 16;
- }
-
- byte_zero(k_ipad,sizeof(k_ipad));
- byte_zero(k_opad,sizeof(k_opad));
- byte_copy(k_ipad,key_len,key);
- byte_copy(k_opad,key_len,key);
-
- for (i = 0; i < 64; i++) {
- k_ipad[i] ^= 0x36;
- k_opad[i] ^= 0x5c;
- }
-
- MD5Init(&context); /* init context for 1st pass */
- MD5Update(&context,k_ipad,64); /* start with inner pad */
- MD5Update(&context,text,text_len); /* then text of datagram */
- MD5Final(digest,&context); /* finish up 1st pass */
-
- MD5Init(&context); /* init context for 2nd pass */
- MD5Update(&context,k_opad,64); /* start with outer pad */
- MD5Update(&context,digest,16); /* then results of 1st hash */
- MD5Final(digest,&context); /* finish up 2nd pass */
+ MD5_CTX context;
+ unsigned char k_ipad[65]; /* inner padding - key XORd with ipad */
+ unsigned char k_opad[65]; /* outer padding - key XORd with opad */
+ unsigned char tk[16];
+ int i;
+
+ if (key_len > 64) {
+ MD5_CTX tctx;
+ MD5Init(&tctx);
+ MD5Update(&tctx, key, key_len);
+ MD5Final(tk, &tctx);
+ key = tk;
+ key_len = 16;
+ }
+
+ byte_zero(k_ipad, sizeof(k_ipad));
+ byte_zero(k_opad, sizeof(k_opad));
+ byte_copy(k_ipad, key_len, key);
+ byte_copy(k_opad, key_len, key);
+
+ for (i = 0; i < 64; i++) {
+ k_ipad[i] ^= 0x36;
+ k_opad[i] ^= 0x5c;
+ }
+
+ MD5Init(&context); /* init context for 1st pass */
+ MD5Update(&context, k_ipad, 64); /* start with inner pad */
+ MD5Update(&context, text, text_len); /* then text of datagram */
+ MD5Final(digest, &context); /* finish up 1st pass */
+
+ MD5Init(&context); /* init context for 2nd pass */
+ MD5Update(&context, k_opad, 64); /* start with outer pad */
+ MD5Update(&context, digest, 16); /* then results of 1st hash */
+ MD5Final(digest, &context); /* finish up 2nd pass */
}