#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);
}
digest[2] = MD5M_C;
digest[3] = MD5M_D;
- md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
+ md5_transform_cl (w0_t, w1_t, w2_t, w3_t, digest);
u8 b64encoded[16];
u32x mangle_hmac (u32x w0[4], u32x w1[4], const u32x in_len)
{
u32x out_len = in_len;
+
u32 digest[4];
u32 data[8];
u32 i;
-
+
data[0] = w0[0];
data[1] = w0[1];
data[2] = w0[2];
data[5] = w1[1];
data[6] = w1[2];
data[7] = w1[3];
-
- md5hmac_cl("flypig.co.uk", strlen("flypig.co.uk"), (u8 *)data, in_len, (u8 *)digest);
- printf("HMAC: ");
- for (i = 0; i < 16; i++) {
- printf("%x", ((u8 *)digest)[i]);
- }
- printf("\n");
+ md5hmac_domain((u8 *)data, in_len, (u8 *)digest);
+
+// printf("HMAC: ");
+// for (i = 0; i < 16; i++) {
+// printf("%x", ((u8 *)digest)[i]);
+// }
+// printf("\n");
w0[0] = digest[0];
w0[1] = digest[1];
w1[3] = 0;
out_len = b64_encode ((u8 *)data, 16, (u8 *)w0);
+ //out_len = 8;
- for (i = out_len; i < 32; i++) {
- ((u8 *)data)[i] = 0;
- }
-
+ for (i = out_len; i < 32; i++) {
+ ((u8 *)data)[i] = 0;
+ }
+
w0[0] = data[0];
w0[1] = data[1];
w0[2] = data[2];
return (out_len);
}
+void writeHexByte(unsigned char byte, unsigned char * hex) {
+ static char number[] = "0123456789abcdef";
+
+ hex[0] = number[(byte >> 4)];
+ hex[1] = number[(byte % 16)];
+}
+
int main(int argc, char * argv[]) {
unsigned char result[RESULT_MAX];
unsigned char salt[SALT_MAX];
}
salt[SALT_MAX - 1] = '\0';
- SPH_HashedPassowrd("hashcat", "flypig.co.uk", result);
+ //SPH_HashedPassowrd("hashcat", "flypig.co.uk", result);
//mangle(password);
- mangle_hmac ((u32x *)password, (u32x *)(password + 16), strlen(password));
+ size = mangle_hmac ((u32x *)password, (u32x *)(password + 16), strlen(password));
//md5hmac(salt, password, digest);
- md5hmac_cl(salt, strlen(salt), password, strlen(password), digest);
+ md5hmac_cl(salt, strlen(salt), password, size, digest);
for (pos = 0; pos < DIGEST_SIZE; pos++) {