#include "md5-cl.h"
+const u8 domain[] = "flypig.co.uk";
+const u32x domain_len = 12;
+
+
#define MD5_STEP(f,a,b,c,d,x,K,s) \
{ \
a += K; \
// return rotate (a, n);
}
-void md5_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4])
+void md5_transform_cl (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4])
{
u32x a = digest[0];
u32x b = digest[1];
// HMAC MD5 ///////////////////////////////////////////////////////
-void hmac_md5_pad (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[4], u32x opad[4])
+void hmac_md5_pad_cl (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[4], u32x opad[4])
{
w0[0] = w0[0] ^ 0x36363636;
w0[1] = w0[1] ^ 0x36363636;
ipad[2] = MD5M_C;
ipad[3] = MD5M_D;
- md5_transform (w0, w1, w2, w3, ipad);
+ md5_transform_cl (w0, w1, w2, w3, ipad);
w0[0] = w0[0] ^ 0x6a6a6a6a;
w0[1] = w0[1] ^ 0x6a6a6a6a;
opad[2] = MD5M_C;
opad[3] = MD5M_D;
- md5_transform (w0, w1, w2, w3, opad);
+ md5_transform_cl (w0, w1, w2, w3, opad);
}
-void hmac_md5_run (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[4], u32x opad[4], u32x digest[4])
+void hmac_md5_run_cl (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u32x ipad[4], u32x opad[4], u32x digest[4])
{
digest[0] = ipad[0];
digest[1] = ipad[1];
digest[2] = ipad[2];
digest[3] = ipad[3];
- md5_transform (w0, w1, w2, w3, digest);
+ md5_transform_cl (w0, w1, w2, w3, digest);
w0[0] = digest[0];
w0[1] = digest[1];
digest[2] = opad[2];
digest[3] = opad[3];
- md5_transform (w0, w1, w2, w3, digest);
+ md5_transform_cl (w0, w1, w2, w3, digest);
+}
+
+void md5hmac_none(u8 const * const inData, const u32x pw_len, u8 outDigest[16])
+{
+ u32 pos;
+ u32 boundary;
+
+ boundary = pw_len;
+ if (boundary > 16) {
+ boundary = 16;
+ }
+
+ for (pos = 0; pos < boundary; pos++) {
+ outDigest[pos] = inData[pos];
+ }
+ for (pos = boundary; pos < 16; pos++) {
+ outDigest[pos] = 0;
+ }
+}
+
+void md5hmac_domain(u8 const * const inData, const u32x pw_len, u8 outDigest[16])
+{
+ u32 pos;
+
+ // data
+
+ u32x data_buf[16];
+
+ for (pos = 0; pos < pw_len; pos++) {
+ ((u8 *)data_buf)[pos] = inData[pos];
+ }
+ for (pos = pw_len; pos < 64; pos++) {
+ ((u8 *)data_buf)[pos] = 0;
+ }
+
+ // key
+
+ u32x key_buf[16];
+
+ for (pos = 0; pos < domain_len; pos++) {
+ ((u8 *)key_buf)[pos] = domain[pos];
+ }
+ for (pos = domain_len; pos < 64; pos++) {
+ ((u8 *)key_buf)[pos] = 0;
+ }
+
+ // pads
+
+ u32x ipad[4];
+ u32x opad[4];
+
+ hmac_md5_pad_cl (key_buf, key_buf + 4, key_buf + 8, key_buf + 12, ipad, opad);
+
+ // loop
+
+ append_0x80_2x4_VV (data_buf, data_buf + 4, pw_len);
+
+ data_buf[14] = (64 + pw_len) * 8;
+
+ hmac_md5_run_cl (data_buf, data_buf + 4, data_buf + 8, data_buf + 12, ipad, opad, (u32x *)outDigest);
}
void md5hmac_cl(u8 * inKey, u32 key_len, u8 * inData, u32 pw_len, u8 outDigest[DIGEST_SIZE])
u32x ipad[4];
u32x opad[4];
- hmac_md5_pad (key_buf, key_buf + 4, key_buf + 8, key_buf + 12, ipad, opad);
+ hmac_md5_pad_cl (key_buf, key_buf + 4, key_buf + 8, key_buf + 12, ipad, opad);
/**
* loop
data_buf[14] = (64 + pw_len) * 8;
- hmac_md5_run (data_buf, data_buf + 4, data_buf + 8, data_buf + 12, ipad, opad, (u32x *)outDigest);
+ hmac_md5_run_cl (data_buf, data_buf + 4, data_buf + 8, data_buf + 12, ipad, opad, (u32x *)outDigest);
}