Comparison

util-src/hashes.c @ 9966:9f1c5ae8d70b

util.hashes: Remove now unused hmac() function
author Kim Alvefur <zash@zash.se>
date Fri, 19 Apr 2019 13:24:32 +0200
parent 9965:d8e645b4d195
child 9967:dc9bb31cbffe
comparison
equal deleted inserted replaced
9965:d8e645b4d195 9966:9f1c5ae8d70b
74 int (*Final)(unsigned char *, void *); 74 int (*Final)(unsigned char *, void *);
75 size_t digestLength; 75 size_t digestLength;
76 void *ctx, *ctxo; 76 void *ctx, *ctxo;
77 }; 77 };
78 78
79 static void hmac(struct hash_desc *desc, const char *key, size_t key_len,
80 const char *msg, size_t msg_len, unsigned char *result) {
81 union xory {
82 unsigned char bytes[64];
83 uint32_t quadbytes[16];
84 };
85
86 int i;
87 unsigned char hashedKey[64]; /* Maximum used digest length */
88 union xory k_ipad, k_opad;
89
90 if(key_len > 64) {
91 desc->Init(desc->ctx);
92 desc->Update(desc->ctx, key, key_len);
93 desc->Final(hashedKey, desc->ctx);
94 key = (const char *)hashedKey;
95 key_len = desc->digestLength;
96 }
97
98 memcpy(k_ipad.bytes, key, key_len);
99 memset(k_ipad.bytes + key_len, 0, 64 - key_len);
100 memcpy(k_opad.bytes, k_ipad.bytes, 64);
101
102 for(i = 0; i < 16; i++) {
103 k_ipad.quadbytes[i] ^= HMAC_IPAD;
104 k_opad.quadbytes[i] ^= HMAC_OPAD;
105 }
106
107 desc->Init(desc->ctx);
108 desc->Update(desc->ctx, k_ipad.bytes, 64);
109 desc->Init(desc->ctxo);
110 desc->Update(desc->ctxo, k_opad.bytes, 64);
111 desc->Update(desc->ctx, msg, msg_len);
112 desc->Final(result, desc->ctx);
113 desc->Update(desc->ctxo, result, desc->digestLength);
114 desc->Final(result, desc->ctxo);
115 }
116
117 #define MAKE_HMAC_FUNCTION(myFunc, evp, size, type) \ 79 #define MAKE_HMAC_FUNCTION(myFunc, evp, size, type) \
118 static int myFunc(lua_State *L) { \ 80 static int myFunc(lua_State *L) { \
119 unsigned char hash[size], result[2*size]; \ 81 unsigned char hash[size], result[2*size]; \
120 size_t key_len, msg_len; \ 82 size_t key_len, msg_len; \
121 unsigned int out_len; \ 83 unsigned int out_len; \