Initial commit
authorDavid Llewellyn-Jones <david@flypig.co.uk>
Sun, 7 Aug 2016 01:24:44 +0000 (02:24 +0100)
committerDavid Llewellyn-Jones <david@flypig.co.uk>
Sun, 7 Aug 2016 01:24:44 +0000 (02:24 +0100)
16 files changed:
.gitignore [new file with mode: 0644]
HmacMd5-old.c [new file with mode: 0644]
b64-cl.c [new file with mode: 0644]
b64-cl.h [new file with mode: 0644]
bin.txt [new file with mode: 0644]
cencode.c [new file with mode: 0644]
cencode.h [new file with mode: 0644]
hmacmd5.c [new file with mode: 0644]
hmacmd5.h [new file with mode: 0644]
md5-cl.c [new file with mode: 0644]
md5-cl.h [new file with mode: 0644]
md5.c [new file with mode: 0644]
md5.h [new file with mode: 0644]
pass.txt [new file with mode: 0644]
pwdhash-all.js [new file with mode: 0644]
salted.c [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a83ea81
--- /dev/null
@@ -0,0 +1,37 @@
+# Prerequisites
+*.d
+
+# Object files
+*.o
+*.ko
+*.obj
+*.elf
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Libraries
+*.lib
+*.a
+*.la
+*.lo
+
+# Shared objects (inc. Windows DLLs)
+*.dll
+*.so
+*.so.*
+*.dylib
+
+# Executables
+*.exe
+*.out
+*.app
+*.i*86
+*.x86_64
+*.hex
+
+# Debug files
+*.dSYM/
+*.su
+
diff --git a/HmacMd5-old.c b/HmacMd5-old.c
new file mode 100644 (file)
index 0000000..b84f974
--- /dev/null
@@ -0,0 +1,620 @@
+/*\r
+ **********************************************************************\r
+ ** md5.h -- Header file for implementation of MD5                   **\r
+ ** RSA Data Security, Inc. MD5 Message Digest Algorithm             **\r
+ ** Created: 2/17/90 RLR                                             **\r
+ ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version              **\r
+ ** Revised (for MD5): RLR 4/27/91                                   **\r
+ **   -- G modified to have y&~z instead of y&z                      **\r
+ **   -- FF, GG, HH modified to add in last register done            **\r
+ **   -- Access pattern: round 2 works mod 5, round 3 works mod 3    **\r
+ **   -- distinct additive constant for each step                    **\r
+ **   -- round 4 added, working mod 7                                **\r
+ **********************************************************************\r
+ */\r
+\r
+/*\r
+ **********************************************************************\r
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **\r
+ **                                                                  **\r
+ ** License to copy and use this software is granted provided that   **\r
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message     **\r
+ ** Digest Algorithm" in all material mentioning or referencing this **\r
+ ** software or this function.                                       **\r
+ **                                                                  **\r
+ ** License is also granted to make and use derivative works         **\r
+ ** provided that such works are identified as "derived from the RSA **\r
+ ** Data Security, Inc. MD5 Message Digest Algorithm" in all         **\r
+ ** material mentioning or referencing the derived work.             **\r
+ **                                                                  **\r
+ ** RSA Data Security, Inc. makes no representations concerning      **\r
+ ** either the merchantability of this software or the suitability   **\r
+ ** of this software for any particular purpose.  It is provided "as **\r
+ ** is" without express or implied warranty of any kind.             **\r
+ **                                                                  **\r
+ ** These notices must be retained in any copies of any part of this **\r
+ ** documentation and/or software.                                   **\r
+ **********************************************************************\r
+ */\r
+\r
+#include "md5.h"\r
+\r
+/* typedef a 32 bit type */\r
+typedef unsigned long int UINT4;\r
+\r
+/* Data structure for MD5 (Message Digest) computation */\r
+typedef struct {\r
+  UINT4 i[2];                   /* number of _bits_ handled mod 2^64 */\r
+  UINT4 buf[4];                                    /* scratch buffer */\r
+  unsigned char in[64];                              /* input buffer */\r
+  unsigned char digest[16];     /* actual digest after MD5Final call */\r
+} MD5_CTX;\r
+\r
+void MD5Init ();\r
+void MD5Update ();\r
+void MD5Final ();\r
+\r
+/*\r
+ **********************************************************************\r
+ ** End of md5.h                                                     **\r
+ ******************************* (cut) ********************************\r
+ */\r
+\r
+/*\r
+ **********************************************************************\r
+ ** md5.c                                                            **\r
+ ** RSA Data Security, Inc. MD5 Message Digest Algorithm             **\r
+ ** Created: 2/17/90 RLR                                             **\r
+ ** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version                  **\r
+ **********************************************************************\r
+ */\r
+\r
+/*\r
+ **********************************************************************\r
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **\r
+ **                                                                  **\r
+ ** License to copy and use this software is granted provided that   **\r
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message     **\r
+ ** Digest Algorithm" in all material mentioning or referencing this **\r
+ ** software or this function.                                       **\r
+ **                                                                  **\r
+ ** License is also granted to make and use derivative works         **\r
+ ** provided that such works are identified as "derived from the RSA **\r
+ ** Data Security, Inc. MD5 Message Digest Algorithm" in all         **\r
+ ** material mentioning or referencing the derived work.             **\r
+ **                                                                  **\r
+ ** RSA Data Security, Inc. makes no representations concerning      **\r
+ ** either the merchantability of this software or the suitability   **\r
+ ** of this software for any particular purpose.  It is provided "as **\r
+ ** is" without express or implied warranty of any kind.             **\r
+ **                                                                  **\r
+ ** These notices must be retained in any copies of any part of this **\r
+ ** documentation and/or software.                                   **\r
+ **********************************************************************\r
+ */\r
+\r
+/* -- include the following line if the md5.h header file is separate -- */\r
+/* #include "md5.h" */\r
+\r
+/* forward declaration */\r
+static void Transform ();\r
+\r
+static unsigned char PADDING[64] = {\r
+  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
+};\r
+\r
+/* F, G and H are basic MD5 functions: selection, majority, parity */\r
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))\r
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))\r
+#define H(x, y, z) ((x) ^ (y) ^ (z))\r
+#define I(x, y, z) ((y) ^ ((x) | (~z))) \r
+\r
+/* ROTATE_LEFT rotates x left n bits */\r
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))\r
+\r
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */\r
+/* Rotation is separate from addition to prevent recomputation */\r
+#define FF(a, b, c, d, x, s, ac) \\r
+  {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \\r
+   (a) = ROTATE_LEFT ((a), (s)); \\r
+   (a) += (b); \\r
+  }\r
+#define GG(a, b, c, d, x, s, ac) \\r
+  {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \\r
+   (a) = ROTATE_LEFT ((a), (s)); \\r
+   (a) += (b); \\r
+  }\r
+#define HH(a, b, c, d, x, s, ac) \\r
+  {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \\r
+   (a) = ROTATE_LEFT ((a), (s)); \\r
+   (a) += (b); \\r
+  }\r
+#define II(a, b, c, d, x, s, ac) \\r
+  {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \\r
+   (a) = ROTATE_LEFT ((a), (s)); \\r
+   (a) += (b); \\r
+  }\r
+\r
+void MD5Init (mdContext)\r
+MD5_CTX *mdContext;\r
+{\r
+  mdContext->i[0] = mdContext->i[1] = (UINT4)0;\r
+\r
+  /* Load magic initialization constants.\r
+   */\r
+  mdContext->buf[0] = (UINT4)0x67452301;\r
+  mdContext->buf[1] = (UINT4)0xefcdab89;\r
+  mdContext->buf[2] = (UINT4)0x98badcfe;\r
+  mdContext->buf[3] = (UINT4)0x10325476;\r
+}\r
+\r
+void MD5Update (mdContext, inBuf, inLen)\r
+MD5_CTX *mdContext;\r
+unsigned char *inBuf;\r
+unsigned int inLen;\r
+{\r
+  UINT4 in[16];\r
+  int mdi;\r
+  unsigned int i, ii;\r
+\r
+  /* compute number of bytes mod 64 */\r
+  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);\r
+\r
+  /* update number of bits */\r
+  if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])\r
+    mdContext->i[1]++;\r
+  mdContext->i[0] += ((UINT4)inLen << 3);\r
+  mdContext->i[1] += ((UINT4)inLen >> 29);\r
+\r
+  while (inLen--) {\r
+    /* add new character to buffer, increment mdi */\r
+    mdContext->in[mdi++] = *inBuf++;\r
+\r
+    /* transform if necessary */\r
+    if (mdi == 0x40) {\r
+      for (i = 0, ii = 0; i < 16; i++, ii += 4)\r
+        in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |\r
+                (((UINT4)mdContext->in[ii+2]) << 16) |\r
+                (((UINT4)mdContext->in[ii+1]) << 8) |\r
+                ((UINT4)mdContext->in[ii]);\r
+      Transform (mdContext->buf, in);\r
+      mdi = 0;\r
+    }\r
+  }\r
+}\r
+\r
+void MD5Final (mdContext)\r
+MD5_CTX *mdContext;\r
+{\r
+  UINT4 in[16];\r
+  int mdi;\r
+  unsigned int i, ii;\r
+  unsigned int padLen;\r
+\r
+  /* save number of bits */\r
+  in[14] = mdContext->i[0];\r
+  in[15] = mdContext->i[1];\r
+\r
+  /* compute number of bytes mod 64 */\r
+  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);\r
+\r
+  /* pad out to 56 mod 64 */\r
+  padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);\r
+  MD5Update (mdContext, PADDING, padLen);\r
+\r
+  /* append length in bits and transform */\r
+  for (i = 0, ii = 0; i < 14; i++, ii += 4)\r
+    in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |\r
+            (((UINT4)mdContext->in[ii+2]) << 16) |\r
+            (((UINT4)mdContext->in[ii+1]) << 8) |\r
+            ((UINT4)mdContext->in[ii]);\r
+  Transform (mdContext->buf, in);\r
+\r
+  /* store buffer in digest */\r
+  for (i = 0, ii = 0; i < 4; i++, ii += 4) {\r
+    mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);\r
+    mdContext->digest[ii+1] =\r
+      (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);\r
+    mdContext->digest[ii+2] =\r
+      (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);\r
+    mdContext->digest[ii+3] =\r
+      (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);\r
+  }\r
+}\r
+\r
+/* Basic MD5 step. Transform buf based on in.\r
+ */\r
+static void Transform (buf, in)\r
+UINT4 *buf;\r
+UINT4 *in;\r
+{\r
+  UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];\r
+\r
+  /* Round 1 */\r
+#define S11 7\r
+#define S12 12\r
+#define S13 17\r
+#define S14 22\r
+  FF ( a, b, c, d, in[ 0], S11, 3614090360); /* 1 */\r
+  FF ( d, a, b, c, in[ 1], S12, 3905402710); /* 2 */\r
+  FF ( c, d, a, b, in[ 2], S13,  606105819); /* 3 */\r
+  FF ( b, c, d, a, in[ 3], S14, 3250441966); /* 4 */\r
+  FF ( a, b, c, d, in[ 4], S11, 4118548399); /* 5 */\r
+  FF ( d, a, b, c, in[ 5], S12, 1200080426); /* 6 */\r
+  FF ( c, d, a, b, in[ 6], S13, 2821735955); /* 7 */\r
+  FF ( b, c, d, a, in[ 7], S14, 4249261313); /* 8 */\r
+  FF ( a, b, c, d, in[ 8], S11, 1770035416); /* 9 */\r
+  FF ( d, a, b, c, in[ 9], S12, 2336552879); /* 10 */\r
+  FF ( c, d, a, b, in[10], S13, 4294925233); /* 11 */\r
+  FF ( b, c, d, a, in[11], S14, 2304563134); /* 12 */\r
+  FF ( a, b, c, d, in[12], S11, 1804603682); /* 13 */\r
+  FF ( d, a, b, c, in[13], S12, 4254626195); /* 14 */\r
+  FF ( c, d, a, b, in[14], S13, 2792965006); /* 15 */\r
+  FF ( b, c, d, a, in[15], S14, 1236535329); /* 16 */\r
+\r
+  /* Round 2 */\r
+#define S21 5\r
+#define S22 9\r
+#define S23 14\r
+#define S24 20\r
+  GG ( a, b, c, d, in[ 1], S21, 4129170786); /* 17 */\r
+  GG ( d, a, b, c, in[ 6], S22, 3225465664); /* 18 */\r
+  GG ( c, d, a, b, in[11], S23,  643717713); /* 19 */\r
+  GG ( b, c, d, a, in[ 0], S24, 3921069994); /* 20 */\r
+  GG ( a, b, c, d, in[ 5], S21, 3593408605); /* 21 */\r
+  GG ( d, a, b, c, in[10], S22,   38016083); /* 22 */\r
+  GG ( c, d, a, b, in[15], S23, 3634488961); /* 23 */\r
+  GG ( b, c, d, a, in[ 4], S24, 3889429448); /* 24 */\r
+  GG ( a, b, c, d, in[ 9], S21,  568446438); /* 25 */\r
+  GG ( d, a, b, c, in[14], S22, 3275163606); /* 26 */\r
+  GG ( c, d, a, b, in[ 3], S23, 4107603335); /* 27 */\r
+  GG ( b, c, d, a, in[ 8], S24, 1163531501); /* 28 */\r
+  GG ( a, b, c, d, in[13], S21, 2850285829); /* 29 */\r
+  GG ( d, a, b, c, in[ 2], S22, 4243563512); /* 30 */\r
+  GG ( c, d, a, b, in[ 7], S23, 1735328473); /* 31 */\r
+  GG ( b, c, d, a, in[12], S24, 2368359562); /* 32 */\r
+\r
+  /* Round 3 */\r
+#define S31 4\r
+#define S32 11\r
+#define S33 16\r
+#define S34 23\r
+  HH ( a, b, c, d, in[ 5], S31, 4294588738); /* 33 */\r
+  HH ( d, a, b, c, in[ 8], S32, 2272392833); /* 34 */\r
+  HH ( c, d, a, b, in[11], S33, 1839030562); /* 35 */\r
+  HH ( b, c, d, a, in[14], S34, 4259657740); /* 36 */\r
+  HH ( a, b, c, d, in[ 1], S31, 2763975236); /* 37 */\r
+  HH ( d, a, b, c, in[ 4], S32, 1272893353); /* 38 */\r
+  HH ( c, d, a, b, in[ 7], S33, 4139469664); /* 39 */\r
+  HH ( b, c, d, a, in[10], S34, 3200236656); /* 40 */\r
+  HH ( a, b, c, d, in[13], S31,  681279174); /* 41 */\r
+  HH ( d, a, b, c, in[ 0], S32, 3936430074); /* 42 */\r
+  HH ( c, d, a, b, in[ 3], S33, 3572445317); /* 43 */\r
+  HH ( b, c, d, a, in[ 6], S34,   76029189); /* 44 */\r
+  HH ( a, b, c, d, in[ 9], S31, 3654602809); /* 45 */\r
+  HH ( d, a, b, c, in[12], S32, 3873151461); /* 46 */\r
+  HH ( c, d, a, b, in[15], S33,  530742520); /* 47 */\r
+  HH ( b, c, d, a, in[ 2], S34, 3299628645); /* 48 */\r
+\r
+  /* Round 4 */\r
+#define S41 6\r
+#define S42 10\r
+#define S43 15\r
+#define S44 21\r
+  II ( a, b, c, d, in[ 0], S41, 4096336452); /* 49 */\r
+  II ( d, a, b, c, in[ 7], S42, 1126891415); /* 50 */\r
+  II ( c, d, a, b, in[14], S43, 2878612391); /* 51 */\r
+  II ( b, c, d, a, in[ 5], S44, 4237533241); /* 52 */\r
+  II ( a, b, c, d, in[12], S41, 1700485571); /* 53 */\r
+  II ( d, a, b, c, in[ 3], S42, 2399980690); /* 54 */\r
+  II ( c, d, a, b, in[10], S43, 4293915773); /* 55 */\r
+  II ( b, c, d, a, in[ 1], S44, 2240044497); /* 56 */\r
+  II ( a, b, c, d, in[ 8], S41, 1873313359); /* 57 */\r
+  II ( d, a, b, c, in[15], S42, 4264355552); /* 58 */\r
+  II ( c, d, a, b, in[ 6], S43, 2734768916); /* 59 */\r
+  II ( b, c, d, a, in[13], S44, 1309151649); /* 60 */\r
+  II ( a, b, c, d, in[ 4], S41, 4149444226); /* 61 */\r
+  II ( d, a, b, c, in[11], S42, 3174756917); /* 62 */\r
+  II ( c, d, a, b, in[ 2], S43,  718787259); /* 63 */\r
+  II ( b, c, d, a, in[ 9], S44, 3951481745); /* 64 */\r
+\r
+  buf[0] += a;\r
+  buf[1] += b;\r
+  buf[2] += c;\r
+  buf[3] += d;\r
+}\r
+\r
+/*\r
+ **********************************************************************\r
+ ** End of md5.c                                                     **\r
+ ******************************* (cut) ********************************\r
+ */\r
+\r
+/*\r
+ **********************************************************************\r
+ ** md5driver.c -- sample routines to test                           **\r
+ ** RSA Data Security, Inc. MD5 message digest algorithm.            **\r
+ ** Created: 2/16/90 RLR                                             **\r
+ ** Updated: 1/91 SRD                                                **\r
+ **********************************************************************\r
+ */\r
+\r
+/*\r
+ **********************************************************************\r
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **\r
+ **                                                                  **\r
+ ** RSA Data Security, Inc. makes no representations concerning      **\r
+ ** either the merchantability of this software or the suitability   **\r
+ ** of this software for any particular purpose.  It is provided "as **\r
+ ** is" without express or implied warranty of any kind.             **\r
+ **                                                                  **\r
+ ** These notices must be retained in any copies of any part of this **\r
+ ** documentation and/or software.                                   **\r
+ **********************************************************************\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <sys/types.h>\r
+#include <time.h>\r
+#include <string.h>\r
+/* -- include the following file if the file md5.h is separate -- */\r
+/* #include "md5.h" */\r
+\r
+/* Prints message digest buffer in mdContext as 32 hexadecimal digits.\r
+   Order is from low-order byte to high-order byte of digest.\r
+   Each byte is printed with high-order hexadecimal digit first.\r
+ */\r
+static void MDPrint (mdContext)\r
+MD5_CTX *mdContext;\r
+{\r
+  int i;\r
+\r
+  for (i = 0; i < 16; i++)\r
+    printf ("%02x", mdContext->digest[i]);\r
+}\r
+\r
+/* size of test block */\r
+#define TEST_BLOCK_SIZE 1000\r
+\r
+/* number of blocks to process */\r
+#define TEST_BLOCKS 10000\r
+\r
+/* number of test bytes = TEST_BLOCK_SIZE * TEST_BLOCKS */\r
+static long TEST_BYTES = (long)TEST_BLOCK_SIZE * (long)TEST_BLOCKS;\r
+\r
+/* A time trial routine, to measure the speed of MD5.\r
+   Measures wall time required to digest TEST_BLOCKS * TEST_BLOCK_SIZE\r
+   characters.\r
+ */\r
+static void MDTimeTrial ()\r
+{\r
+  MD5_CTX mdContext;\r
+  time_t endTime, startTime;\r
+  unsigned char data[TEST_BLOCK_SIZE];\r
+  unsigned int i;\r
+\r
+  /* initialize test data */\r
+  for (i = 0; i < TEST_BLOCK_SIZE; i++)\r
+    data[i] = (unsigned char)(i & 0xFF);\r
+\r
+  /* start timer */\r
+  printf ("MD5 time trial. Processing %ld characters...\n", TEST_BYTES);\r
+  time (&startTime);\r
+\r
+  /* digest data in TEST_BLOCK_SIZE byte blocks */\r
+  MD5Init (&mdContext);\r
+  for (i = TEST_BLOCKS; i > 0; i--)\r
+    MD5Update (&mdContext, data, TEST_BLOCK_SIZE);\r
+  MD5Final (&mdContext);\r
+\r
+  /* stop timer, get time difference */\r
+  time (&endTime);\r
+  MDPrint (&mdContext);\r
+  printf (" is digest of test input.\n");\r
+  printf\r
+    ("Seconds to process test input: %ld\n", (long)(endTime-startTime));\r
+  printf\r
+    ("Characters processed per second: %ld\n",\r
+     TEST_BYTES/(endTime-startTime));\r
+}\r
+\r
+/* Computes the message digest for string inString.\r
+   Prints out message digest, a space, the string (in quotes) and a\r
+   carriage return.\r
+ */\r
+static void MDString (inString)\r
+char *inString;\r
+{\r
+  MD5_CTX mdContext;\r
+  unsigned int len = strlen (inString);\r
+\r
+  MD5Init (&mdContext);\r
+  MD5Update (&mdContext, inString, len);\r
+  MD5Final (&mdContext);\r
+  MDPrint (&mdContext);\r
+  printf (" \"%s\"\n\n", inString);\r
+}\r
+\r
+/* Computes the message digest for a specified file.\r
+   Prints out message digest, a space, the file name, and a carriage\r
+   return.\r
+ */\r
+static void MDFile (filename)\r
+char *filename;\r
+{\r
+  FILE *inFile = fopen (filename, "rb");\r
+  MD5_CTX mdContext;\r
+  int bytes;\r
+  unsigned char data[1024];\r
+\r
+  if (inFile == NULL) {\r
+    printf ("%s can't be opened.\n", filename);\r
+    return;\r
+  }\r
+\r
+  MD5Init (&mdContext);\r
+  while ((bytes = fread (data, 1, 1024, inFile)) != 0)\r
+    MD5Update (&mdContext, data, bytes);\r
+  MD5Final (&mdContext);\r
+  MDPrint (&mdContext);\r
+  printf (" %s\n", filename);\r
+  fclose (inFile);\r
+}\r
+\r
+/* Writes the message digest of the data from stdin onto stdout,\r
+   followed by a carriage return.\r
+ */\r
+static void MDFilter ()\r
+{\r
+  MD5_CTX mdContext;\r
+  int bytes;\r
+  unsigned char data[16];\r
+\r
+  MD5Init (&mdContext);\r
+  while ((bytes = fread (data, 1, 16, stdin)) != 0)\r
+    MD5Update (&mdContext, data, bytes);\r
+  MD5Final (&mdContext);\r
+  MDPrint (&mdContext);\r
+  printf ("\n");\r
+}\r
+\r
+/* Runs a standard suite of test data.\r
+ */\r
+static void MDTestSuite ()\r
+{\r
+  printf ("MD5 test suite results:\n\n");\r
+  MDString ("");\r
+  MDString ("a");\r
+  MDString ("abc");\r
+  MDString ("message digest");\r
+  MDString ("abcdefghijklmnopqrstuvwxyz");\r
+  MDString\r
+    ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");\r
+  MDString\r
+    ("1234567890123456789012345678901234567890\\r
+1234567890123456789012345678901234567890");\r
+  /* Contents of file foo are "abc" */\r
+  MDFile ("foo");\r
+}\r
+\r
+static void MD5 (mdContext, inString)\r
+MD5_CTX * mdContext;\r
+char  * inString;\r
+{\r
+  unsigned int len = strlen (inString);\r
+\r
+  MD5Init (mdContext);\r
+  MD5Update (mdContext, inString, len);\r
+  MD5Final (mdContext);\r
+}\r
+\r
+static void MDPrintDebug (digest)\r
+unsigned char digest[16];\r
+{\r
+  int i;\r
+\r
+  for (i = 0; i < 16; i++)\r
+    printf ("%02x", digest[i]);\r
+}\r
+\r
+static void MDHmac (key, inString)\r
+unsigned char * key;\r
+unsigned char * inString;\r
+{\r
+  mbedtls_md5_context mdContext;\r
+  unsigned int keylen;\r
+  int pos;\r
+  unsigned char ipad[64];\r
+  unsigned char opad[64];\r
+  unsigned char hash[16];\r
+\r
+  // Ensure key length is exaclty 16 bytes\r
+  keylen = strlen(key);\r
+  if (keylen > 64) {\r
+    mbedtls_md5(key, keylen, hash);\r
+    memcpy(ipad, hash, 16);\r
+    memcpy(opad, hash, 16);\r
+    keylen = 16;\r
+  }\r
+  else {\r
+    memcpy(ipad, key, keylen);\r
+    memcpy(opad, key, keylen);\r
+  }\r
+  for (pos = keylen; pos < 64; pos++) {\r
+    ipad[pos] = '\0';\r
+    opad[pos] = '\0';\r
+  }\r
+\r
+  for (pos = 0; pos < 64; pos++) {\r
+    ipad[pos] ^= 0x36;\r
+    opad[pos] ^= 0x5C;\r
+  }\r
+\r
+  mbedtls_md5_init(& mdContext);\r
+  mbedtls_md5_starts(& mdContext);\r
+  mbedtls_md5_update(& mdContext, ipad, 64);\r
+  mbedtls_md5_update(& mdContext, inString, strlen(inString));\r
+  mbedtls_md5_finish(& mdContext, hash);\r
+  mbedtls_md5_free(& mdContext);\r
+\r
+  mbedtls_md5_init(& mdContext);\r
+  mbedtls_md5_starts(& mdContext);\r
+  mbedtls_md5_update(& mdContext, opad, 64);\r
+  mbedtls_md5_update(& mdContext, hash, 16);\r
+  mbedtls_md5_finish(& mdContext, hash);\r
+  mbedtls_md5_free(& mdContext);\r
+\r
+  MDPrintDebug (hash);\r
+  printf ("\n");\r
+}\r
+\r
+static void MDTestHmac ()\r
+{\r
+  unsigned char output[16];\r
+  mbedtls_md5("Hello", 5, output);\r
+  MDPrintDebug(output);\r
+  printf ("\n");\r
+       \r
+  MDHmac ("key", "The quick brown fox jumps over the lazy dog");\r
+}\r
+\r
+void main (argc, argv)\r
+int argc;\r
+char *argv[];\r
+{\r
+  int i;\r
+\r
+  /* For each command line argument in turn:\r
+  ** filename          -- prints message digest and name of file\r
+  ** -sstring          -- prints message digest and contents of string\r
+  ** -t                -- prints time trial statistics for 1M characters\r
+  ** -x                -- execute a standard suite of test data\r
+  ** (no args)         -- writes messages digest of stdin onto stdout\r
+  */\r
+  if (argc == 1)\r
+    MDFilter ();\r
+  else\r
+    for (i = 1; i < argc; i++)\r
+      if (argv[i][0] == '-' && argv[i][1] == 's')\r
+        MDString (argv[i] + 2);\r
+      else if (strcmp (argv[i], "-t") == 0)\r
+        MDTimeTrial ();\r
+      else if (strcmp (argv[i], "-x") == 0)\r
+        MDTestSuite ();\r
+      else if (strcmp (argv[i], "-h") == 0)\r
+        MDTestHmac ();\r
+      else MDFile (argv[i]);\r
+}\r
+\r
+/*\r
+ **********************************************************************\r
+ ** End of md5driver.c                                               **\r
+ ******************************* (cut) ********************************\r
+ */\r
diff --git a/b64-cl.c b/b64-cl.c
new file mode 100644 (file)
index 0000000..4733f09
--- /dev/null
+++ b/b64-cl.c
@@ -0,0 +1,55 @@
+#include "b64-cl.h"
+
+const char b64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+u32 b64_encode (u8 *base64_hash, const u32 len, const u8 *base64_plain)
+{
+        u8 *out_ptr = (u8 *) base64_hash;
+        u8 *in_ptr  = (u8 *) base64_plain;
+
+        u32 i;
+
+        for (i = 0; i < (len - 2); i += 3)
+        {
+                char out_val0 = b64_table [                            ((in_ptr[0] >> 2) & 0x3f)];
+                char out_val1 = b64_table [((in_ptr[0] << 4) & 0x30) | ((in_ptr[1] >> 4) & 0x0f)];
+                char out_val2 = b64_table [((in_ptr[1] << 2) & 0x3c) | ((in_ptr[2] >> 6) & 0x03)];
+                char out_val3 = b64_table [                            ((in_ptr[2] >> 0) & 0x3f)];
+
+                out_ptr[0] = out_val0 & 0x7f;
+                out_ptr[1] = out_val1 & 0x7f;
+                out_ptr[2] = out_val2 & 0x7f;
+                out_ptr[3] = out_val3 & 0x7f;
+
+                in_ptr  += 3;
+                out_ptr += 4;
+        }
+               if (i == (len - 1)) {
+                char out_val0 = b64_table [                            ((in_ptr[0] >> 2) & 0x3f)];
+                char out_val1 = b64_table [((in_ptr[0] << 4) & 0x30)                            ];
+
+                out_ptr[0] = out_val0 & 0x7f;
+                out_ptr[1] = out_val1 & 0x7f;
+                out_ptr[2] = '=';
+                out_ptr[3] = '=';
+                       
+                in_ptr  += 3;
+                out_ptr += 4;
+               }
+               if (i == (len - 2)) {
+                char out_val0 = b64_table [                            ((in_ptr[0] >> 2) & 0x3f)];
+                char out_val1 = b64_table [((in_ptr[0] << 4) & 0x30) | ((in_ptr[1] >> 4) & 0x0f)];
+                char out_val2 = b64_table [((in_ptr[1] << 2) & 0x3c)                            ];
+
+                out_ptr[0] = out_val0 & 0x7f;
+                out_ptr[1] = out_val1 & 0x7f;
+                out_ptr[2] = out_val2 & 0x7f;
+                out_ptr[3] = '=';
+
+                in_ptr  += 3;
+                out_ptr += 4;
+               }
+
+               return (out_ptr - base64_hash + 0);
+}
+
diff --git a/b64-cl.h b/b64-cl.h
new file mode 100644 (file)
index 0000000..71efc72
--- /dev/null
+++ b/b64-cl.h
@@ -0,0 +1,15 @@
+#ifndef __B64CL_H
+#define __B64CL_H (1)
+
+#include <stdint.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <string.h>
+
+typedef unsigned char u8;
+typedef uint32_t u32;
+typedef uint32_t u32x;
+
+u32 b64_encode (u8 *base64_hash, const u32 len, const u8 *base64_plain);
+
+#endif // ifndef __B64CL_H
diff --git a/bin.txt b/bin.txt
new file mode 100644 (file)
index 0000000..13522d0
--- /dev/null
+++ b/bin.txt
@@ -0,0 +1 @@
+\87Cµ cÍ
\ No newline at end of file
diff --git a/cencode.c b/cencode.c
new file mode 100644 (file)
index 0000000..1f1c241
--- /dev/null
+++ b/cencode.c
@@ -0,0 +1,136 @@
+/**
+ * @file
+ * @author  devolve <http://sourceforge.net/projects/libb64>
+ * @version 1.0
+ *
+ * @section LICENSE
+ *
+ * Public domain
+ *
+ * @section DESCRIPTION
+ *
+ * This is part of the libb64 project, and has been placed in the public domain.
+ * For details, see http://sourceforge.net/projects/libb64
+ *
+ * The cencode source provides support for base64 encoding data. It can be
+ * used in conjunction with the cdecode source. It's used by base64, which
+ * provides a higher-level interface to the functionality. 
+ *
+ */
+
+#include "pico/debug.h"
+#include "pico/log.h"
+#include "pico/cencode.h"
+
+const int CHARS_PER_LINE = 72;
+
+/**
+ * Internal function for encoding base64 strings
+ */
+void base64_init_encodestate(base64_encodestate* state_in)
+{
+       state_in->step = step_A;
+       state_in->result = 0;
+       state_in->stepcount = 0;
+}
+
+/**
+ * Internal function for encoding base64 strings
+ */
+char base64_encode_value(char value_in)
+{
+       static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+       if (value_in > 63) return '=';
+       return encoding[(int)value_in];
+}
+
+/**
+ * Internal function for encoding base64 strings
+ */
+int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in)
+{
+       const char* plainchar = plaintext_in;
+       const char* const plaintextend = plaintext_in + length_in;
+       char* codechar = code_out;
+       char result;
+       char fragment;
+       
+       result = state_in->result;
+       
+       switch (state_in->step)
+       {
+               while (1)
+               {
+       case step_A:
+                       if (plainchar == plaintextend)
+                       {
+                               state_in->result = result;
+                               state_in->step = step_A;
+                               return codechar - code_out;
+                       }
+                       fragment = *plainchar++;
+                       result = (fragment & 0x0fc) >> 2;
+                       *codechar++ = base64_encode_value(result);
+                       result = (fragment & 0x003) << 4;
+       case step_B:
+                       if (plainchar == plaintextend)
+                       {
+                               state_in->result = result;
+                               state_in->step = step_B;
+                               return codechar - code_out;
+                       }
+                       fragment = *plainchar++;
+                       result |= (fragment & 0x0f0) >> 4;
+                       *codechar++ = base64_encode_value(result);
+                       result = (fragment & 0x00f) << 2;
+       case step_C:
+                       if (plainchar == plaintextend)
+                       {
+                               state_in->result = result;
+                               state_in->step = step_C;
+                               return codechar - code_out;
+                       }
+                       fragment = *plainchar++;
+                       result |= (fragment & 0x0c0) >> 6;
+                       *codechar++ = base64_encode_value(result);
+                       result  = (fragment & 0x03f) >> 0;
+                       *codechar++ = base64_encode_value(result);
+                       
+                       ++(state_in->stepcount);
+                       if (state_in->stepcount == CHARS_PER_LINE/4)
+                       {
+                               //*codechar++ = '\n';
+                               state_in->stepcount = 0;
+                       }
+               }
+       }
+       /* control should not reach here */
+       return codechar - code_out;
+}
+
+/**
+ * Internal function for encoding base64 strings
+ */
+int base64_encode_blockend(char* code_out, base64_encodestate* state_in)
+{
+       char* codechar = code_out;
+       
+       switch (state_in->step)
+       {
+       case step_B:
+               *codechar++ = base64_encode_value(state_in->result);
+               *codechar++ = '=';
+               *codechar++ = '=';
+               break;
+       case step_C:
+               *codechar++ = base64_encode_value(state_in->result);
+               *codechar++ = '=';
+               break;
+       case step_A:
+               break;
+       }
+       //*codechar++ = '\n';
+       
+       return codechar - code_out;
+}
+
diff --git a/cencode.h b/cencode.h
new file mode 100644 (file)
index 0000000..c1450d9
--- /dev/null
+++ b/cencode.h
@@ -0,0 +1,45 @@
+/**
+ * @file
+ * @author  devolve <http://sourceforge.net/projects/libb64>
+ * @version 1.0
+ *
+ * @section LICENSE
+ *
+ * Public domain
+ *
+ * @section DESCRIPTION
+ *
+ * This is part of the libb64 project, and has been placed in the public domain.
+ * For details, see http://sourceforge.net/projects/libb64
+ *
+ * The cencode source provides support for base64 encoding data. It can be
+ * used in conjunction with the cdecode source. It's used by base64, which
+ * provides a higher-level interface to the functionality. 
+ *
+ */
+
+#ifndef BASE64_CENCODE_H
+#define BASE64_CENCODE_H
+
+typedef enum
+{
+       step_A, step_B, step_C
+} base64_encodestep;
+
+typedef struct
+{
+       base64_encodestep step;
+       char result;
+       int stepcount;
+} base64_encodestate;
+
+void base64_init_encodestate(base64_encodestate* state_in);
+
+char base64_encode_value(char value_in);
+
+int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);
+
+int base64_encode_blockend(char* code_out, base64_encodestate* state_in);
+
+#endif /* BASE64_CENCODE_H */
+
diff --git a/hmacmd5.c b/hmacmd5.c
new file mode 100644 (file)
index 0000000..78445d5
--- /dev/null
+++ b/hmacmd5.c
@@ -0,0 +1,219 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <time.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "cencode.h"
+#include "md5.h"
+
+#include "hmacmd5.h"
+
+#define SPH_kkPasswordPrefixLength (2)
+
+void md5print(unsigned char digest[DIGEST_SIZE]) {
+       int pos;
+
+       for (pos = 0; pos < DIGEST_SIZE; pos++) {
+               printf ("%02x", digest[pos]);
+       }
+}
+
+void writeHexByte(unsigned char byte, unsigned char * hex) {
+       static char number[] = "0123456789abcdef";
+       
+       hex[0] = number[(byte >> 4)];
+       hex[1] = number[(byte % 16)];
+}
+
+void md5hmac(unsigned char * key, unsigned char * inString, unsigned char digest[DIGEST_SIZE]) {
+       mbedtls_md5_context mdContext;
+       unsigned int keylen;
+       int pos;
+       unsigned char ipad[BLOCK_SIZE];
+       unsigned char opad[BLOCK_SIZE];
+       unsigned char hash[DIGEST_SIZE];
+
+       // Ensure key length is exaclty 16 bytes
+       keylen = strlen(key);
+       if (keylen > BLOCK_SIZE) {
+               mbedtls_md5(key, keylen, hash);
+               memcpy(ipad, hash, DIGEST_SIZE);
+               memcpy(opad, hash, DIGEST_SIZE);
+               keylen = DIGEST_SIZE;
+       }
+       else {
+               memcpy(ipad, key, keylen);
+               memcpy(opad, key, keylen);
+       }
+       for (pos = keylen; pos < BLOCK_SIZE; pos++) {
+               ipad[pos] = '\0';
+               opad[pos] = '\0';
+       }
+
+       for (pos = 0; pos < BLOCK_SIZE; pos++) {
+               ipad[pos] ^= 0x36;
+               opad[pos] ^= 0x5C;
+       }
+
+       mbedtls_md5_init(& mdContext);
+       mbedtls_md5_starts(& mdContext);
+       mbedtls_md5_update(& mdContext, ipad, BLOCK_SIZE);
+       mbedtls_md5_update(& mdContext, inString, strlen(inString));
+       mbedtls_md5_finish(& mdContext, hash);
+       mbedtls_md5_free(& mdContext);
+
+       mbedtls_md5_init(& mdContext);
+       mbedtls_md5_starts(& mdContext);
+       mbedtls_md5_update(& mdContext, opad, BLOCK_SIZE);
+       mbedtls_md5_update(& mdContext, hash, DIGEST_SIZE);
+       mbedtls_md5_finish(& mdContext, digest);
+       mbedtls_md5_free(& mdContext);
+}
+
+static void md5hmactest() {
+       unsigned char digest[DIGEST_SIZE];
+       //unsigned char output[DIGEST_SIZE];
+       //mbedtls_md5("Hello", 5, output);
+       //md5print(output);
+       //printf ("\n");
+
+       md5hmac("key", "The quick brown fox jumps over the lazy dog", digest);
+       md5print(digest);
+       printf ("\n");
+}
+
+bool containsnonalphanumeric(unsigned char * password, int length) {
+       bool nonalphanumeric;
+       unsigned int pos;
+       char check;
+       int startingSize;
+
+       nonalphanumeric = false;
+       for (pos = 0; (pos < length) && !nonalphanumeric; pos++) {
+               check = password[pos];
+               if (!((check >= 'a') && (check <= 'z'))
+                       && !((check >= 'A') && (check <= 'Z'))
+                       && !((check >= '0') && (check <= '9'))
+                       && !(check == '_')) {
+                       nonalphanumeric = true;
+               }
+       }
+       
+       return nonalphanumeric;
+}
+
+bool contains(unsigned char * password, int length, char start, char end) {
+       bool doescontain = false;
+       unsigned int pos;
+
+       for (pos = 0; (pos < length) && (doescontain == false); pos++) {
+               if ((password[pos] >= start) && (password[pos] <= end)) {
+                       doescontain = true;
+               }
+       }
+       
+       return doescontain;
+}
+
+void rotate(unsigned char * torotate, int length, int steps) {
+       char scratch[RESULT_MAX];
+       unsigned int pos;
+       
+       for (pos = 0; pos < length; pos++) {
+               scratch[pos] = torotate[(pos + steps) % length];
+       }
+
+       for (pos = 0; pos < length; pos++) {
+               torotate[pos] = scratch[pos];
+       }
+}
+
+void SPH_HashedPassowrd(unsigned char * password, unsigned char * realm, unsigned char result[RESULT_MAX]) {
+       unsigned char digest[DIGEST_SIZE];
+       base64_encodestate state_in;
+       size_t size;
+       unsigned char hash[25];
+       int extraSize = 0;
+       bool nonalphanumeric;
+       int startingSize;
+       int extraPos;
+       char next;
+       unsigned int pos;
+
+       md5hmac(password, realm, digest);
+
+       base64_init_encodestate(& state_in);
+       size = base64_encode_block(digest, DIGEST_SIZE, hash, & state_in);
+       size += base64_encode_blockend(hash + size, & state_in);
+       hash[24] = '\0';
+       hash[23] = '\0';
+       hash[22] = '\0';
+       extraSize = strlen(hash);
+
+       size = strlen(password) + SPH_kkPasswordPrefixLength;
+
+       nonalphanumeric = containsnonalphanumeric(password, strlen(password));
+       startingSize = size - 4;
+
+       startingSize = startingSize < extraSize ? startingSize : extraSize;
+       memcpy(result, hash, startingSize);
+       extraPos = startingSize;
+
+       // Add the extras
+       next = (extraPos < extraSize) ? hash[extraPos] : 0;
+       extraPos++;
+       if (!contains(result, startingSize, 'A', 'Z')) {
+               next = 'A' + (next % ('Z' - 'A' + 1));
+       }
+       result[startingSize] = next;
+       startingSize++;
+
+       next = (extraPos < extraSize) ? hash[extraPos] : 0;
+       extraPos++;
+       if (!contains(result, startingSize, 'a', 'z')) {
+               next = 'a' + (next % ('z' - 'a' + 1));
+       }
+       result[startingSize] = next;
+       startingSize++;
+
+       next = (extraPos < extraSize) ? hash[extraPos] : 0;
+       extraPos++;
+       if (!contains(result, startingSize, '0', '9')) {
+               next = '0' + (next % ('9' - '0' + 1));
+       }
+       result[startingSize] = next;
+       startingSize++;
+
+       if (containsnonalphanumeric(result, startingSize) && nonalphanumeric) {
+               next = (extraPos < extraSize) ? hash[extraPos] : 0;
+               extraPos++;
+       }
+       else {
+               next = '+';
+       }
+       result[startingSize] = next;
+       startingSize++;
+
+       if (!nonalphanumeric) {
+               for (pos = 0; pos < startingSize; pos++) {
+                       if (containsnonalphanumeric(result + pos, 1)) {
+                               next = (extraPos < extraSize) ? hash[extraPos] : 0;
+                               extraPos++;
+                               next = 'A' + (next % ('Z' - 'A' + 1));
+                               result[pos] = next;
+                       }
+               }
+       }
+
+       next = (extraPos < extraSize) ? hash[extraPos] : 0;
+       rotate(result, startingSize, next);
+       result[startingSize] = '\0';
+}
+
+//int main(int argc, char * argv[]) {
+//     SPH_HashedPassowrd("lsksjfjsdfsjdflsksjfjsdfsjdflsksjfjsdfsjdflsksjfjsdfsjdf", "flypig.co.uk");
+//
+//     return 0;
+//}
+
diff --git a/hmacmd5.h b/hmacmd5.h
new file mode 100644 (file)
index 0000000..4d54dac
--- /dev/null
+++ b/hmacmd5.h
@@ -0,0 +1,17 @@
+#ifndef __HMACMD5_H
+#define __HMACMD5_H (1)
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdbool.h>
+
+#define DIGEST_SIZE (16)
+#define BLOCK_SIZE (64)
+#define RESULT_MAX (50)
+
+void md5print(unsigned char digest[DIGEST_SIZE]);
+void md5hmac(unsigned char * key, unsigned char * inString, unsigned char digest[DIGEST_SIZE]);
+void SPH_HashedPassowrd(unsigned char * password, unsigned char * realm, unsigned char result[RESULT_MAX]);
+void writeHexByte(unsigned char byte, unsigned char * hex);
+
+#endif // ifndef __HMACMD5_H
diff --git a/md5-cl.c b/md5-cl.c
new file mode 100644 (file)
index 0000000..aee9c1e
--- /dev/null
+++ b/md5-cl.c
@@ -0,0 +1,494 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <string.h>
+
+#include "md5-cl.h"
+
+#define MD5_STEP(f,a,b,c,d,x,K,s)   \
+{                                   \
+  a += K;                           \
+  a += x;                           \
+  a += f (b, c, d);                 \
+  a  = rotl32 (a, s);               \
+  a += b;                           \
+}
+
+#define MD5_F(x,y,z)    ((z) ^ ((x) & ((y) ^ (z))))
+#define MD5_G(x,y,z)    ((y) ^ ((z) & ((x) ^ (y))))
+#define MD5_H(x,y,z)    ((x) ^ (y) ^ (z))
+#define MD5_I(x,y,z)    ((y) ^ ((x) | ~(z)))
+#define MD5_Fo(x,y,z)   (MD5_F((x), (y), (z)))
+#define MD5_Go(x,y,z)   (MD5_G((x), (y), (z)))
+
+#define MD5S00  7u
+#define MD5S01 12u
+#define MD5S02 17u
+#define MD5S03 22u
+#define MD5S10  5u
+#define MD5S11  9u
+#define MD5S12 14u
+#define MD5S13 20u
+#define MD5S20  4u
+#define MD5S21 11u
+#define MD5S22 16u
+#define MD5S23 23u
+#define MD5S30  6u
+#define MD5S31 10u
+#define MD5S32 15u
+#define MD5S33 21u
+
+#define MD5C00 0xd76aa478u
+#define MD5C01 0xe8c7b756u
+#define MD5C02 0x242070dbu
+#define MD5C03 0xc1bdceeeu
+#define MD5C04 0xf57c0fafu
+#define MD5C05 0x4787c62au
+#define MD5C06 0xa8304613u
+#define MD5C07 0xfd469501u
+#define MD5C08 0x698098d8u
+#define MD5C09 0x8b44f7afu
+#define MD5C0a 0xffff5bb1u
+#define MD5C0b 0x895cd7beu
+#define MD5C0c 0x6b901122u
+#define MD5C0d 0xfd987193u
+#define MD5C0e 0xa679438eu
+#define MD5C0f 0x49b40821u
+#define MD5C10 0xf61e2562u
+#define MD5C11 0xc040b340u
+#define MD5C12 0x265e5a51u
+#define MD5C13 0xe9b6c7aau
+#define MD5C14 0xd62f105du
+#define MD5C15 0x02441453u
+#define MD5C16 0xd8a1e681u
+#define MD5C17 0xe7d3fbc8u
+#define MD5C18 0x21e1cde6u
+#define MD5C19 0xc33707d6u
+#define MD5C1a 0xf4d50d87u
+#define MD5C1b 0x455a14edu
+#define MD5C1c 0xa9e3e905u
+#define MD5C1d 0xfcefa3f8u
+#define MD5C1e 0x676f02d9u
+#define MD5C1f 0x8d2a4c8au
+#define MD5C20 0xfffa3942u
+#define MD5C21 0x8771f681u
+#define MD5C22 0x6d9d6122u
+#define MD5C23 0xfde5380cu
+#define MD5C24 0xa4beea44u
+#define MD5C25 0x4bdecfa9u
+#define MD5C26 0xf6bb4b60u
+#define MD5C27 0xbebfbc70u
+#define MD5C28 0x289b7ec6u
+#define MD5C29 0xeaa127fau
+#define MD5C2a 0xd4ef3085u
+#define MD5C2b 0x04881d05u
+#define MD5C2c 0xd9d4d039u
+#define MD5C2d 0xe6db99e5u
+#define MD5C2e 0x1fa27cf8u
+#define MD5C2f 0xc4ac5665u
+#define MD5C30 0xf4292244u
+#define MD5C31 0x432aff97u
+#define MD5C32 0xab9423a7u
+#define MD5C33 0xfc93a039u
+#define MD5C34 0x655b59c3u
+#define MD5C35 0x8f0ccc92u
+#define MD5C36 0xffeff47du
+#define MD5C37 0x85845dd1u
+#define MD5C38 0x6fa87e4fu
+#define MD5C39 0xfe2ce6e0u
+#define MD5C3a 0xa3014314u
+#define MD5C3b 0x4e0811a1u
+#define MD5C3c 0xf7537e82u
+#define MD5C3d 0xbd3af235u
+#define MD5C3e 0x2ad7d2bbu
+#define MD5C3f 0xeb86d391u
+
+u32x rotl32 (const u32x a, const u32 n)
+{
+  u32x result;
+
+  result = a << n;
+  result |= a >> (32 - n);
+
+  return result;
+ // 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])
+{
+  u32x a = digest[0];
+  u32x b = digest[1];
+  u32x c = digest[2];
+  u32x d = digest[3];
+
+  u32x w0_t = w0[0];
+  u32x w1_t = w0[1];
+  u32x w2_t = w0[2];
+  u32x w3_t = w0[3];
+  u32x w4_t = w1[0];
+  u32x w5_t = w1[1];
+  u32x w6_t = w1[2];
+  u32x w7_t = w1[3];
+  u32x w8_t = w2[0];
+  u32x w9_t = w2[1];
+  u32x wa_t = w2[2];
+  u32x wb_t = w2[3];
+  u32x wc_t = w3[0];
+  u32x wd_t = w3[1];
+  u32x we_t = w3[2];
+  u32x wf_t = w3[3];
+
+  MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
+  MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
+  MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
+  MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
+  MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
+  MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
+  MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
+  MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
+  MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
+  MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
+  MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
+  MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
+  MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
+  MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
+  MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
+  MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
+
+  MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
+  MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
+  MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
+  MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
+  MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
+  MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
+  MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
+  MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
+  MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
+  MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
+  MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
+  MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
+  MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
+  MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
+  MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
+  MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
+
+  MD5_STEP (MD5_H , a, b, c, d, w5_t, MD5C20, MD5S20);
+  MD5_STEP (MD5_H , d, a, b, c, w8_t, MD5C21, MD5S21);
+  MD5_STEP (MD5_H , c, d, a, b, wb_t, MD5C22, MD5S22);
+  MD5_STEP (MD5_H , b, c, d, a, we_t, MD5C23, MD5S23);
+  MD5_STEP (MD5_H , a, b, c, d, w1_t, MD5C24, MD5S20);
+  MD5_STEP (MD5_H , d, a, b, c, w4_t, MD5C25, MD5S21);
+  MD5_STEP (MD5_H , c, d, a, b, w7_t, MD5C26, MD5S22);
+  MD5_STEP (MD5_H , b, c, d, a, wa_t, MD5C27, MD5S23);
+  MD5_STEP (MD5_H , a, b, c, d, wd_t, MD5C28, MD5S20);
+  MD5_STEP (MD5_H , d, a, b, c, w0_t, MD5C29, MD5S21);
+  MD5_STEP (MD5_H , c, d, a, b, w3_t, MD5C2a, MD5S22);
+  MD5_STEP (MD5_H , b, c, d, a, w6_t, MD5C2b, MD5S23);
+  MD5_STEP (MD5_H , a, b, c, d, w9_t, MD5C2c, MD5S20);
+  MD5_STEP (MD5_H , d, a, b, c, wc_t, MD5C2d, MD5S21);
+  MD5_STEP (MD5_H , c, d, a, b, wf_t, MD5C2e, MD5S22);
+  MD5_STEP (MD5_H , b, c, d, a, w2_t, MD5C2f, MD5S23);
+
+  MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
+  MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
+  MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
+  MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
+  MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
+  MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
+  MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
+  MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
+  MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
+  MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
+  MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
+  MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
+  MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
+  MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
+  MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
+  MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
+
+  digest[0] += a;
+  digest[1] += b;
+  digest[2] += c;
+  digest[3] += d;
+}
+
+void append_0x80_2x4_S (u32 w0[4], u32 w1[4], const u32 offset)
+{
+  switch (offset)
+  {
+    case 0:
+      w0[0] = 0x80;
+      break;
+
+    case 1:
+      w0[0] = w0[0] | 0x8000;
+      break;
+
+    case 2:
+      w0[0] = w0[0] | 0x800000;
+      break;
+
+    case 3:
+      w0[0] = w0[0] | 0x80000000;
+      break;
+
+    case 4:
+      w0[1] = 0x80;
+      break;
+
+    case 5:
+      w0[1] = w0[1] | 0x8000;
+      break;
+
+    case 6:
+      w0[1] = w0[1] | 0x800000;
+      break;
+
+    case 7:
+      w0[1] = w0[1] | 0x80000000;
+      break;
+
+    case 8:
+      w0[2] = 0x80;
+      break;
+
+    case 9:
+      w0[2] = w0[2] | 0x8000;
+      break;
+
+    case 10:
+      w0[2] = w0[2] | 0x800000;
+      break;
+
+    case 11:
+      w0[2] = w0[2] | 0x80000000;
+      break;
+
+    case 12:
+      w0[3] = 0x80;
+      break;
+
+    case 13:
+      w0[3] = w0[3] | 0x8000;
+      break;
+
+    case 14:
+      w0[3] = w0[3] | 0x800000;
+      break;
+
+    case 15:
+      w0[3] = w0[3] | 0x80000000;
+      break;
+
+    case 16:
+      w1[0] = 0x80;
+      break;
+
+    case 17:
+      w1[0] = w1[0] | 0x8000;
+      break;
+
+    case 18:
+      w1[0] = w1[0] | 0x800000;
+      break;
+
+    case 19:
+      w1[0] = w1[0] | 0x80000000;
+      break;
+
+    case 20:
+      w1[1] = 0x80;
+      break;
+
+    case 21:
+      w1[1] = w1[1] | 0x8000;
+      break;
+
+    case 22:
+      w1[1] = w1[1] | 0x800000;
+      break;
+
+    case 23:
+      w1[1] = w1[1] | 0x80000000;
+      break;
+
+    case 24:
+      w1[2] = 0x80;
+      break;
+
+    case 25:
+      w1[2] = w1[2] | 0x8000;
+      break;
+
+    case 26:
+      w1[2] = w1[2] | 0x800000;
+      break;
+
+    case 27:
+      w1[2] = w1[2] | 0x80000000;
+      break;
+
+    case 28:
+      w1[3] = 0x80;
+      break;
+
+    case 29:
+      w1[3] = w1[3] | 0x8000;
+      break;
+
+    case 30:
+      w1[3] = w1[3] | 0x800000;
+      break;
+
+    case 31:
+      w1[3] = w1[3] | 0x80000000;
+      break;
+  }
+}
+
+void append_0x80_2x4_VV (u32x w0[4], u32x w1[4], const u32x offset)
+{
+  append_0x80_2x4_S (w0, w1, offset);
+}
+
+
+// HMAC MD5 ///////////////////////////////////////////////////////
+
+void hmac_md5_pad (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;
+  w0[2] = w0[2] ^ 0x36363636;
+  w0[3] = w0[3] ^ 0x36363636;
+  w1[0] = w1[0] ^ 0x36363636;
+  w1[1] = w1[1] ^ 0x36363636;
+  w1[2] = w1[2] ^ 0x36363636;
+  w1[3] = w1[3] ^ 0x36363636;
+  w2[0] = w2[0] ^ 0x36363636;
+  w2[1] = w2[1] ^ 0x36363636;
+  w2[2] = w2[2] ^ 0x36363636;
+  w2[3] = w2[3] ^ 0x36363636;
+  w3[0] = w3[0] ^ 0x36363636;
+  w3[1] = w3[1] ^ 0x36363636;
+  w3[2] = w3[2] ^ 0x36363636;
+  w3[3] = w3[3] ^ 0x36363636;
+
+  ipad[0] = MD5M_A;
+  ipad[1] = MD5M_B;
+  ipad[2] = MD5M_C;
+  ipad[3] = MD5M_D;
+
+  md5_transform (w0, w1, w2, w3, ipad);
+
+  w0[0] = w0[0] ^ 0x6a6a6a6a;
+  w0[1] = w0[1] ^ 0x6a6a6a6a;
+  w0[2] = w0[2] ^ 0x6a6a6a6a;
+  w0[3] = w0[3] ^ 0x6a6a6a6a;
+  w1[0] = w1[0] ^ 0x6a6a6a6a;
+  w1[1] = w1[1] ^ 0x6a6a6a6a;
+  w1[2] = w1[2] ^ 0x6a6a6a6a;
+  w1[3] = w1[3] ^ 0x6a6a6a6a;
+  w2[0] = w2[0] ^ 0x6a6a6a6a;
+  w2[1] = w2[1] ^ 0x6a6a6a6a;
+  w2[2] = w2[2] ^ 0x6a6a6a6a;
+  w2[3] = w2[3] ^ 0x6a6a6a6a;
+  w3[0] = w3[0] ^ 0x6a6a6a6a;
+  w3[1] = w3[1] ^ 0x6a6a6a6a;
+  w3[2] = w3[2] ^ 0x6a6a6a6a;
+  w3[3] = w3[3] ^ 0x6a6a6a6a;
+
+  opad[0] = MD5M_A;
+  opad[1] = MD5M_B;
+  opad[2] = MD5M_C;
+  opad[3] = MD5M_D;
+
+  md5_transform (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])
+{
+  digest[0] = ipad[0];
+  digest[1] = ipad[1];
+  digest[2] = ipad[2];
+  digest[3] = ipad[3];
+
+  md5_transform (w0, w1, w2, w3, digest);
+
+  w0[0] = digest[0];
+  w0[1] = digest[1];
+  w0[2] = digest[2];
+  w0[3] = digest[3];
+  w1[0] = 0x80;
+  w1[1] = 0;
+  w1[2] = 0;
+  w1[3] = 0;
+  w2[0] = 0;
+  w2[1] = 0;
+  w2[2] = 0;
+  w2[3] = 0;
+  w3[0] = 0;
+  w3[1] = 0;
+  w3[2] = (64 + 16) * 8;
+  w3[3] = 0;
+
+  digest[0] = opad[0];
+  digest[1] = opad[1];
+  digest[2] = opad[2];
+  digest[3] = opad[3];
+
+  md5_transform (w0, w1, w2, w3, digest);
+}
+
+void md5hmac_cl(u8 * inKey, u32 key_len, u8 * inData, u32 pw_len, u8 outDigest[DIGEST_SIZE])
+{
+  u32 pos;
+
+  /**
+   * data
+   */
+
+  u32 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
+   */
+
+  u32 key_buf[16];
+
+  for (pos = 0; pos < key_len; pos++) {
+    ((u8 *)key_buf)[pos] = inKey[pos];
+  }
+  for (pos = key_len; pos < 64; pos++) {
+    ((u8 *)key_buf)[pos] = 0;
+  }
+
+  /**
+   * pads
+   */
+
+  u32x ipad[4];
+  u32x opad[4];
+
+  hmac_md5_pad (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 (data_buf, data_buf + 4, data_buf + 8, data_buf + 12, ipad, opad, (u32x *)outDigest);
+}
+
+
+
+
diff --git a/md5-cl.h b/md5-cl.h
new file mode 100644 (file)
index 0000000..37338bb
--- /dev/null
+++ b/md5-cl.h
@@ -0,0 +1,18 @@
+#ifndef __MD5CL_H
+#define __MD5CL_H (1)
+
+#include "b64-cl.h"
+
+#define MD5M_A 0x67452301u
+#define MD5M_B 0xefcdab89u
+#define MD5M_C 0x98badcfeu
+#define MD5M_D 0x10325476u
+
+#define DIGEST_SIZE (16)
+
+void md5_transform (const u32x w0[4], const u32x w1[4], const u32x w2[4], const u32x w3[4], u32x digest[4]);
+void append_0x80_2x4_VV (u32x w0[4], u32x w1[4], const u32x offset);
+u32x rotl32 (const u32x a, const u32 n);
+void md5hmac_cl(u8 * inKey, u32 key_len, u8 * inData, u32 pw_len, u8 outDigest[DIGEST_SIZE]);
+
+#endif // ifndef __MD5CL_H
diff --git a/md5.c b/md5.c
new file mode 100644 (file)
index 0000000..c30f4ea
--- /dev/null
+++ b/md5.c
@@ -0,0 +1,406 @@
+/*
+ *  RFC 1321 compliant MD5 implementation
+ *
+ *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ *  SPDX-License-Identifier: Apache-2.0
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  This file is part of mbed TLS (https://tls.mbed.org)
+ */
+/*
+ *  The MD5 algorithm was designed by Ron Rivest in 1991.
+ *
+ *  http://www.ietf.org/rfc/rfc1321.txt
+ */
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+//#include "mbedtls/config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
+#define MBEDTLS_MD5_C
+
+#if defined(MBEDTLS_MD5_C)
+
+#include "md5.h"
+
+#include <string.h>
+
+#if defined(MBEDTLS_SELF_TEST)
+#if defined(MBEDTLS_PLATFORM_C)
+#include "mbedtls/platform.h"
+#else
+#include <stdio.h>
+#define mbedtls_printf printf
+#endif /* MBEDTLS_PLATFORM_C */
+#endif /* MBEDTLS_SELF_TEST */
+
+#if !defined(MBEDTLS_MD5_ALT)
+
+/* Implementation that should never be optimized out by the compiler */
+static void mbedtls_zeroize( void *v, size_t n ) {
+    volatile unsigned char *p = v; while( n-- ) *p++ = 0;
+}
+
+/*
+ * 32-bit integer manipulation macros (little endian)
+ */
+#ifndef GET_UINT32_LE
+#define GET_UINT32_LE(n,b,i)                            \
+{                                                       \
+    (n) = ( (uint32_t) (b)[(i)    ]       )             \
+        | ( (uint32_t) (b)[(i) + 1] <<  8 )             \
+        | ( (uint32_t) (b)[(i) + 2] << 16 )             \
+        | ( (uint32_t) (b)[(i) + 3] << 24 );            \
+}
+#endif
+
+#ifndef PUT_UINT32_LE
+#define PUT_UINT32_LE(n,b,i)                                    \
+{                                                               \
+    (b)[(i)    ] = (unsigned char) ( ( (n)       ) & 0xFF );    \
+    (b)[(i) + 1] = (unsigned char) ( ( (n) >>  8 ) & 0xFF );    \
+    (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF );    \
+    (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF );    \
+}
+#endif
+
+void mbedtls_md5_init( mbedtls_md5_context *ctx )
+{
+    memset( ctx, 0, sizeof( mbedtls_md5_context ) );
+}
+
+void mbedtls_md5_free( mbedtls_md5_context *ctx )
+{
+    if( ctx == NULL )
+        return;
+
+    mbedtls_zeroize( ctx, sizeof( mbedtls_md5_context ) );
+}
+
+void mbedtls_md5_clone( mbedtls_md5_context *dst,
+                        const mbedtls_md5_context *src )
+{
+    *dst = *src;
+}
+
+/*
+ * MD5 context setup
+ */
+void mbedtls_md5_starts( mbedtls_md5_context *ctx )
+{
+    ctx->total[0] = 0;
+    ctx->total[1] = 0;
+
+    ctx->state[0] = 0x67452301;
+    ctx->state[1] = 0xEFCDAB89;
+    ctx->state[2] = 0x98BADCFE;
+    ctx->state[3] = 0x10325476;
+}
+
+#if !defined(MBEDTLS_MD5_PROCESS_ALT)
+void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] )
+{
+    uint32_t X[16], A, B, C, D;
+
+    GET_UINT32_LE( X[ 0], data,  0 );
+    GET_UINT32_LE( X[ 1], data,  4 );
+    GET_UINT32_LE( X[ 2], data,  8 );
+    GET_UINT32_LE( X[ 3], data, 12 );
+    GET_UINT32_LE( X[ 4], data, 16 );
+    GET_UINT32_LE( X[ 5], data, 20 );
+    GET_UINT32_LE( X[ 6], data, 24 );
+    GET_UINT32_LE( X[ 7], data, 28 );
+    GET_UINT32_LE( X[ 8], data, 32 );
+    GET_UINT32_LE( X[ 9], data, 36 );
+    GET_UINT32_LE( X[10], data, 40 );
+    GET_UINT32_LE( X[11], data, 44 );
+    GET_UINT32_LE( X[12], data, 48 );
+    GET_UINT32_LE( X[13], data, 52 );
+    GET_UINT32_LE( X[14], data, 56 );
+    GET_UINT32_LE( X[15], data, 60 );
+
+#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
+
+#define P(a,b,c,d,k,s,t)                                \
+{                                                       \
+    a += F(b,c,d) + X[k] + t; a = S(a,s) + b;           \
+}
+
+    A = ctx->state[0];
+    B = ctx->state[1];
+    C = ctx->state[2];
+    D = ctx->state[3];
+
+#define F(x,y,z) (z ^ (x & (y ^ z)))
+
+    P( A, B, C, D,  0,  7, 0xD76AA478 );
+    P( D, A, B, C,  1, 12, 0xE8C7B756 );
+    P( C, D, A, B,  2, 17, 0x242070DB );
+    P( B, C, D, A,  3, 22, 0xC1BDCEEE );
+    P( A, B, C, D,  4,  7, 0xF57C0FAF );
+    P( D, A, B, C,  5, 12, 0x4787C62A );
+    P( C, D, A, B,  6, 17, 0xA8304613 );
+    P( B, C, D, A,  7, 22, 0xFD469501 );
+    P( A, B, C, D,  8,  7, 0x698098D8 );
+    P( D, A, B, C,  9, 12, 0x8B44F7AF );
+    P( C, D, A, B, 10, 17, 0xFFFF5BB1 );
+    P( B, C, D, A, 11, 22, 0x895CD7BE );
+    P( A, B, C, D, 12,  7, 0x6B901122 );
+    P( D, A, B, C, 13, 12, 0xFD987193 );
+    P( C, D, A, B, 14, 17, 0xA679438E );
+    P( B, C, D, A, 15, 22, 0x49B40821 );
+
+#undef F
+
+#define F(x,y,z) (y ^ (z & (x ^ y)))
+
+    P( A, B, C, D,  1,  5, 0xF61E2562 );
+    P( D, A, B, C,  6,  9, 0xC040B340 );
+    P( C, D, A, B, 11, 14, 0x265E5A51 );
+    P( B, C, D, A,  0, 20, 0xE9B6C7AA );
+    P( A, B, C, D,  5,  5, 0xD62F105D );
+    P( D, A, B, C, 10,  9, 0x02441453 );
+    P( C, D, A, B, 15, 14, 0xD8A1E681 );
+    P( B, C, D, A,  4, 20, 0xE7D3FBC8 );
+    P( A, B, C, D,  9,  5, 0x21E1CDE6 );
+    P( D, A, B, C, 14,  9, 0xC33707D6 );
+    P( C, D, A, B,  3, 14, 0xF4D50D87 );
+    P( B, C, D, A,  8, 20, 0x455A14ED );
+    P( A, B, C, D, 13,  5, 0xA9E3E905 );
+    P( D, A, B, C,  2,  9, 0xFCEFA3F8 );
+    P( C, D, A, B,  7, 14, 0x676F02D9 );
+    P( B, C, D, A, 12, 20, 0x8D2A4C8A );
+
+#undef F
+
+#define F(x,y,z) (x ^ y ^ z)
+
+    P( A, B, C, D,  5,  4, 0xFFFA3942 );
+    P( D, A, B, C,  8, 11, 0x8771F681 );
+    P( C, D, A, B, 11, 16, 0x6D9D6122 );
+    P( B, C, D, A, 14, 23, 0xFDE5380C );
+    P( A, B, C, D,  1,  4, 0xA4BEEA44 );
+    P( D, A, B, C,  4, 11, 0x4BDECFA9 );
+    P( C, D, A, B,  7, 16, 0xF6BB4B60 );
+    P( B, C, D, A, 10, 23, 0xBEBFBC70 );
+    P( A, B, C, D, 13,  4, 0x289B7EC6 );
+    P( D, A, B, C,  0, 11, 0xEAA127FA );
+    P( C, D, A, B,  3, 16, 0xD4EF3085 );
+    P( B, C, D, A,  6, 23, 0x04881D05 );
+    P( A, B, C, D,  9,  4, 0xD9D4D039 );
+    P( D, A, B, C, 12, 11, 0xE6DB99E5 );
+    P( C, D, A, B, 15, 16, 0x1FA27CF8 );
+    P( B, C, D, A,  2, 23, 0xC4AC5665 );
+
+#undef F
+
+#define F(x,y,z) (y ^ (x | ~z))
+
+    P( A, B, C, D,  0,  6, 0xF4292244 );
+    P( D, A, B, C,  7, 10, 0x432AFF97 );
+    P( C, D, A, B, 14, 15, 0xAB9423A7 );
+    P( B, C, D, A,  5, 21, 0xFC93A039 );
+    P( A, B, C, D, 12,  6, 0x655B59C3 );
+    P( D, A, B, C,  3, 10, 0x8F0CCC92 );
+    P( C, D, A, B, 10, 15, 0xFFEFF47D );
+    P( B, C, D, A,  1, 21, 0x85845DD1 );
+    P( A, B, C, D,  8,  6, 0x6FA87E4F );
+    P( D, A, B, C, 15, 10, 0xFE2CE6E0 );
+    P( C, D, A, B,  6, 15, 0xA3014314 );
+    P( B, C, D, A, 13, 21, 0x4E0811A1 );
+    P( A, B, C, D,  4,  6, 0xF7537E82 );
+    P( D, A, B, C, 11, 10, 0xBD3AF235 );
+    P( C, D, A, B,  2, 15, 0x2AD7D2BB );
+    P( B, C, D, A,  9, 21, 0xEB86D391 );
+
+#undef F
+
+    ctx->state[0] += A;
+    ctx->state[1] += B;
+    ctx->state[2] += C;
+    ctx->state[3] += D;
+}
+#endif /* !MBEDTLS_MD5_PROCESS_ALT */
+
+/*
+ * MD5 process buffer
+ */
+void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
+{
+    size_t fill;
+    uint32_t left;
+
+    if( ilen == 0 )
+        return;
+
+    left = ctx->total[0] & 0x3F;
+    fill = 64 - left;
+
+    ctx->total[0] += (uint32_t) ilen;
+    ctx->total[0] &= 0xFFFFFFFF;
+
+    if( ctx->total[0] < (uint32_t) ilen )
+        ctx->total[1]++;
+
+    if( left && ilen >= fill )
+    {
+        memcpy( (void *) (ctx->buffer + left), input, fill );
+        mbedtls_md5_process( ctx, ctx->buffer );
+        input += fill;
+        ilen  -= fill;
+        left = 0;
+    }
+
+    while( ilen >= 64 )
+    {
+        mbedtls_md5_process( ctx, input );
+        input += 64;
+        ilen  -= 64;
+    }
+
+    if( ilen > 0 )
+    {
+        memcpy( (void *) (ctx->buffer + left), input, ilen );
+    }
+}
+
+static const unsigned char md5_padding[64] =
+{
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/*
+ * MD5 final digest
+ */
+void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
+{
+    uint32_t last, padn;
+    uint32_t high, low;
+    unsigned char msglen[8];
+
+    high = ( ctx->total[0] >> 29 )
+         | ( ctx->total[1] <<  3 );
+    low  = ( ctx->total[0] <<  3 );
+
+    PUT_UINT32_LE( low,  msglen, 0 );
+    PUT_UINT32_LE( high, msglen, 4 );
+
+    last = ctx->total[0] & 0x3F;
+    padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
+
+    mbedtls_md5_update( ctx, md5_padding, padn );
+    mbedtls_md5_update( ctx, msglen, 8 );
+
+    PUT_UINT32_LE( ctx->state[0], output,  0 );
+    PUT_UINT32_LE( ctx->state[1], output,  4 );
+    PUT_UINT32_LE( ctx->state[2], output,  8 );
+    PUT_UINT32_LE( ctx->state[3], output, 12 );
+}
+
+#endif /* !MBEDTLS_MD5_ALT */
+
+/*
+ * output = MD5( input buffer )
+ */
+void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] )
+{
+    mbedtls_md5_context ctx;
+
+    mbedtls_md5_init( &ctx );
+    mbedtls_md5_starts( &ctx );
+    mbedtls_md5_update( &ctx, input, ilen );
+    mbedtls_md5_finish( &ctx, output );
+    mbedtls_md5_free( &ctx );
+}
+
+#if defined(MBEDTLS_SELF_TEST)
+/*
+ * RFC 1321 test vectors
+ */
+static const unsigned char md5_test_buf[7][81] =
+{
+    { "" },
+    { "a" },
+    { "abc" },
+    { "message digest" },
+    { "abcdefghijklmnopqrstuvwxyz" },
+    { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
+    { "12345678901234567890123456789012345678901234567890123456789012" \
+      "345678901234567890" }
+};
+
+static const int md5_test_buflen[7] =
+{
+    0, 1, 3, 14, 26, 62, 80
+};
+
+static const unsigned char md5_test_sum[7][16] =
+{
+    { 0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04,
+      0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E },
+    { 0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8,
+      0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61 },
+    { 0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0,
+      0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72 },
+    { 0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D,
+      0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0 },
+    { 0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00,
+      0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B },
+    { 0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5,
+      0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F },
+    { 0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55,
+      0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A }
+};
+
+/*
+ * Checkup routine
+ */
+int mbedtls_md5_self_test( int verbose )
+{
+    int i;
+    unsigned char md5sum[16];
+
+    for( i = 0; i < 7; i++ )
+    {
+        if( verbose != 0 )
+            mbedtls_printf( "  MD5 test #%d: ", i + 1 );
+
+        mbedtls_md5( md5_test_buf[i], md5_test_buflen[i], md5sum );
+
+        if( memcmp( md5sum, md5_test_sum[i], 16 ) != 0 )
+        {
+            if( verbose != 0 )
+                mbedtls_printf( "failed\n" );
+
+            return( 1 );
+        }
+
+        if( verbose != 0 )
+            mbedtls_printf( "passed\n" );
+    }
+
+    if( verbose != 0 )
+        mbedtls_printf( "\n" );
+
+    return( 0 );
+}
+
+#endif /* MBEDTLS_SELF_TEST */
+
+#endif /* MBEDTLS_MD5_C */
diff --git a/md5.h b/md5.h
new file mode 100644 (file)
index 0000000..ced5718
--- /dev/null
+++ b/md5.h
@@ -0,0 +1,136 @@
+/**
+ * \file md5.h
+ *
+ * \brief MD5 message digest algorithm (hash function)
+ *
+ *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
+ *  SPDX-License-Identifier: Apache-2.0
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  This file is part of mbed TLS (https://tls.mbed.org)
+ */
+#ifndef MBEDTLS_MD5_H
+#define MBEDTLS_MD5_H
+
+#if !defined(MBEDTLS_CONFIG_FILE)
+//#include "config.h"
+#else
+#include MBEDTLS_CONFIG_FILE
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+#if !defined(MBEDTLS_MD5_ALT)
+// Regular implementation
+//
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief          MD5 context structure
+ */
+typedef struct
+{
+    uint32_t total[2];          /*!< number of bytes processed  */
+    uint32_t state[4];          /*!< intermediate digest state  */
+    unsigned char buffer[64];   /*!< data block being processed */
+}
+mbedtls_md5_context;
+
+/**
+ * \brief          Initialize MD5 context
+ *
+ * \param ctx      MD5 context to be initialized
+ */
+void mbedtls_md5_init( mbedtls_md5_context *ctx );
+
+/**
+ * \brief          Clear MD5 context
+ *
+ * \param ctx      MD5 context to be cleared
+ */
+void mbedtls_md5_free( mbedtls_md5_context *ctx );
+
+/**
+ * \brief          Clone (the state of) an MD5 context
+ *
+ * \param dst      The destination context
+ * \param src      The context to be cloned
+ */
+void mbedtls_md5_clone( mbedtls_md5_context *dst,
+                        const mbedtls_md5_context *src );
+
+/**
+ * \brief          MD5 context setup
+ *
+ * \param ctx      context to be initialized
+ */
+void mbedtls_md5_starts( mbedtls_md5_context *ctx );
+
+/**
+ * \brief          MD5 process buffer
+ *
+ * \param ctx      MD5 context
+ * \param input    buffer holding the  data
+ * \param ilen     length of the input data
+ */
+void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
+
+/**
+ * \brief          MD5 final digest
+ *
+ * \param ctx      MD5 context
+ * \param output   MD5 checksum result
+ */
+void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] );
+
+/* Internal use */
+void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] );
+
+#ifdef __cplusplus
+}
+#endif
+
+#else  /* MBEDTLS_MD5_ALT */
+#include "md5_alt.h"
+#endif /* MBEDTLS_MD5_ALT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief          Output = MD5( input buffer )
+ *
+ * \param input    buffer holding the  data
+ * \param ilen     length of the input data
+ * \param output   MD5 checksum result
+ */
+void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] );
+
+/**
+ * \brief          Checkup routine
+ *
+ * \return         0 if successful, or 1 if the test failed
+ */
+int mbedtls_md5_self_test( int verbose );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* mbedtls_md5.h */
diff --git a/pass.txt b/pass.txt
new file mode 100644 (file)
index 0000000..3160506
--- /dev/null
+++ b/pass.txt
@@ -0,0 +1 @@
+hashcat
diff --git a/pwdhash-all.js b/pwdhash-all.js
new file mode 100644 (file)
index 0000000..f8dcb6b
--- /dev/null
@@ -0,0 +1,454 @@
+/*
+ * Remote PwdHash
+ * A JavaScript implementation of the PwdHash hashing algorithm.
+ * Version 1.0 Copyright (C) Stanford University 2004-2006
+ * Author: Collin Jackson
+ * Other Contributors: Dan Boneh, John Mitchell, Nick Miyake, and Blake Ross
+ * Distributed under the BSD License
+ * See http://crypto.stanford.edu/PwdHash for more info.
+ * Requires the Javascript MD5 library, available here: http://pajhome.org.uk/crypt/md5
+ */
+
+/*
+ * Initialize page with default hashing parameters.
+ */
+function Init() {
+  document.inputform.term.value = "http://www.example.com/";
+  document.hashpass.sitePassword.value = "";
+  document.hashpass.hashedPassword.value = "Press Generate";
+  document.hashpass.hashedPassword.disabled = true;
+}
+
+var SPH_kPasswordPrefix = "@@";
+
+/*
+ * Returns a conforming hashed password generated from the form's field values.
+ */
+function Generate()
+{
+  var uri = document.inputform.term.value;
+  var domain = (new SPH_DomainExtractor()).extractDomain(uri);
+  var size = SPH_kPasswordPrefix.length;
+  var data = document.hashpass.sitePassword.value;
+  if (data.substring(0, size) == SPH_kPasswordPrefix)
+    data = data.substring(size);
+  var result = new String(new SPH_HashedPassword(data, domain));
+  return result;
+}
+
+/*
+ * Obtain a conforming hashed password and put it in the hashed password field
+ */
+function GenerateToTextField()
+{
+       if ((document.hashpass.sitePassword.value != "") && (document.inputform.term.value != "")) {
+               document.hashpass.hashedPassword.value = Generate();
+               document.hashpass.hashedPassword.disabled = false;
+  }
+  else {
+               if (document.hashpass.hashedPassword.value != "") {
+                       document.hashpass.hashedPassword.value = "";
+               }
+  }
+}
+
+
+
+
+
+/*
+Copyright 2005 Collin Jackson
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+    * Neither the name of Stanford University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+/*
+ * Domain name extractor. Turns host names into domain names
+ * Adapted from Chris Zarate's public domain genpass tool:
+ *  http://labs.zarate.org/passwd/
+ */
+    
+function SPH_DomainExtractor() { }
+
+SPH_DomainExtractor.prototype = {
+
+  extractDomain: function(host) {
+
+    var s;  // the final result
+
+    // Begin Chris Zarate's code
+    host=host.replace('http:\/\/','');
+    host=host.replace('https:\/\/','');
+    re=new RegExp("([^/]+)");
+    host=host.match(re)[1];
+    host=host.split('.');
+
+    if(host[2]!=null) {
+      s=host[host.length-2]+'.'+host[host.length-1];
+      domains='ab.ca|ac.ac|ac.at|ac.be|ac.cn|ac.il|ac.in|ac.jp|ac.kr|ac.nz|ac.th|ac.uk|ac.za|adm.br|adv.br|agro.pl|ah.cn|aid.pl|alt.za|am.br|arq.br|art.br|arts.ro|asn.au|asso.fr|asso.mc|atm.pl|auto.pl|bbs.tr|bc.ca|bio.br|biz.pl|bj.cn|br.com|cn.com|cng.br|cnt.br|co.ac|co.at|co.il|co.in|co.jp|co.kr|co.nz|co.th|co.uk|co.za|com.au|com.br|com.cn|com.ec|com.fr|com.hk|com.mm|com.mx|com.pl|com.ro|com.ru|com.sg|com.tr|com.tw|cq.cn|cri.nz|de.com|ecn.br|edu.au|edu.cn|edu.hk|edu.mm|edu.mx|edu.pl|edu.tr|edu.za|eng.br|ernet.in|esp.br|etc.br|eti.br|eu.com|eu.lv|fin.ec|firm.ro|fm.br|fot.br|fst.br|g12.br|gb.com|gb.net|gd.cn|gen.nz|gmina.pl|go.jp|go.kr|go.th|gob.mx|gov.br|gov.cn|gov.ec|gov.il|gov.in|gov.mm|gov.mx|gov.sg|gov.tr|gov.za|govt.nz|gs.cn|gsm.pl|gv.ac|gv.at|gx.cn|gz.cn|hb.cn|he.cn|hi.cn|hk.cn|hl.cn|hn.cn|hu.com|idv.tw|ind.br|inf.br|info.pl|info.ro|iwi.nz|jl.cn|jor.br|jpn.com|js.cn|k12.il|k12.tr|lel.br|ln.cn|ltd.uk|mail.pl|maori.nz|mb.ca|me.uk|med.br|med.ec|media.pl|mi.th|miasta.pl|mil.br|mil.ec|mil.nz|mil.pl|mil.tr|mil.za|mo.cn|muni.il|nb.ca|ne.jp|ne.kr|net.au|net.br|net.cn|net.ec|net.hk|net.il|net.in|net.mm|net.mx|net.nz|net.pl|net.ru|net.sg|net.th|net.tr|net.tw|net.za|nf.ca|ngo.za|nm.cn|nm.kr|no.com|nom.br|nom.pl|nom.ro|nom.za|ns.ca|nt.ca|nt.ro|ntr.br|nx.cn|odo.br|on.ca|or.ac|or.at|or.jp|or.kr|or.th|org.au|org.br|org.cn|org.ec|org.hk|org.il|org.mm|org.mx|org.nz|org.pl|org.ro|org.ru|org.sg|org.tr|org.tw|org.uk|org.za|pc.pl|pe.ca|plc.uk|ppg.br|presse.fr|priv.pl|pro.br|psc.br|psi.br|qc.ca|qc.com|qh.cn|re.kr|realestate.pl|rec.br|rec.ro|rel.pl|res.in|ru.com|sa.com|sc.cn|school.nz|school.za|se.com|se.net|sh.cn|shop.pl|sk.ca|sklep.pl|slg.br|sn.cn|sos.pl|store.ro|targi.pl|tj.cn|tm.fr|tm.mc|tm.pl|tm.ro|tm.za|tmp.br|tourism.pl|travel.pl|tur.br|turystyka.pl|tv.br|tw.cn|uk.co|uk.com|uk.net|us.com|uy.com|vet.br|web.za|web.com|www.ro|xj.cn|xz.cn|yk.ca|yn.cn|za.com';
+      domains=domains.split('|');
+      for(var i=0;i<domains.length;i++) {
+        if(s==domains[i]) {
+          s=host[host.length-3]+'.'+s;
+          break;
+        }
+      }
+    } else {
+      s=host.join('.');
+    }
+    // End Chris Zarate's code
+    return s;
+  }
+}
+
+
+
+
+
+/*
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
+ * Digest Algorithm, as defined in RFC 1321.
+ * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ * See http://pajhome.org.uk/crypt/md5 for more info.
+ */
+
+/*
+ * Configurable variables. You may need to tweak these to be compatible with
+ * the server-side, but the defaults work in most cases.
+ */
+var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
+var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
+var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */
+
+/*
+ * These are the functions you'll usually want to call
+ * They take string arguments and return either hex or base-64 encoded strings
+ */
+function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
+function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
+function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
+function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
+function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
+function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
+
+/*
+ * Perform a simple self-test to see if the VM is working
+ */
+function md5_vm_test()
+{
+  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
+}
+
+/*
+ * Calculate the MD5 of an array of little-endian words, and a bit length
+ */
+function core_md5(x, len)
+{
+  /* append padding */
+  x[len >> 5] |= 0x80 << ((len) % 32);
+  x[(((len + 64) >>> 9) << 4) + 14] = len;
+
+  var a =  1732584193;
+  var b = -271733879;
+  var c = -1732584194;
+  var d =  271733878;
+
+  for(var i = 0; i < x.length; i += 16)
+  {
+    var olda = a;
+    var oldb = b;
+    var oldc = c;
+    var oldd = d;
+
+    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
+    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
+    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
+    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
+    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
+    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
+    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
+    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
+    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
+    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
+    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
+    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
+    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
+    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
+    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
+    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);
+
+    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
+    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
+    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
+    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
+    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
+    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
+    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
+    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
+    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
+    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
+    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
+    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
+    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
+    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
+    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
+    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
+
+    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
+    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
+    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
+    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
+    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
+    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
+    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
+    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
+    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
+    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
+    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
+    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
+    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
+    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
+    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
+    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
+
+    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
+    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
+    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
+    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
+    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
+    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
+    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
+    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
+    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
+    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
+    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
+    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
+    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
+    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
+    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
+    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
+
+    a = safe_add(a, olda);
+    b = safe_add(b, oldb);
+    c = safe_add(c, oldc);
+    d = safe_add(d, oldd);
+  }
+  return Array(a, b, c, d);
+
+}
+
+/*
+ * These functions implement the four basic operations the algorithm uses.
+ */
+function md5_cmn(q, a, b, x, s, t)
+{
+  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
+}
+function md5_ff(a, b, c, d, x, s, t)
+{
+  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
+}
+function md5_gg(a, b, c, d, x, s, t)
+{
+  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
+}
+function md5_hh(a, b, c, d, x, s, t)
+{
+  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
+}
+function md5_ii(a, b, c, d, x, s, t)
+{
+  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
+}
+
+/*
+ * Calculate the HMAC-MD5, of a key and some data
+ */
+function core_hmac_md5(key, data)
+{
+  var bkey = str2binl(key);
+  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
+
+  var ipad = Array(16), opad = Array(16);
+  for(var i = 0; i < 16; i++)
+  {
+    ipad[i] = bkey[i] ^ 0x36363636;
+    opad[i] = bkey[i] ^ 0x5C5C5C5C;
+  }
+
+  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
+  return core_md5(opad.concat(hash), 512 + 128);
+}
+
+/*
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
+ * to work around bugs in some JS interpreters.
+ */
+function safe_add(x, y)
+{
+  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
+  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
+  return (msw << 16) | (lsw & 0xFFFF);
+}
+
+/*
+ * Bitwise rotate a 32-bit number to the left.
+ */
+function bit_rol(num, cnt)
+{
+  return (num << cnt) | (num >>> (32 - cnt));
+}
+
+/*
+ * Convert a string to an array of little-endian words
+ * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
+ */
+function str2binl(str)
+{
+  var bin = Array();
+  var mask = (1 << chrsz) - 1;
+  for(var i = 0; i < str.length * chrsz; i += chrsz)
+    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
+  return bin;
+}
+
+/*
+ * Convert an array of little-endian words to a string
+ */
+function binl2str(bin)
+{
+  var str = "";
+  var mask = (1 << chrsz) - 1;
+  for(var i = 0; i < bin.length * 32; i += chrsz)
+    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
+  return str;
+}
+
+/*
+ * Convert an array of little-endian words to a hex string.
+ */
+function binl2hex(binarray)
+{
+  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
+  var str = "";
+  for(var i = 0; i < binarray.length * 4; i++)
+  {
+    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
+           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
+  }
+  return str;
+}
+
+/*
+ * Convert an array of little-endian words to a base-64 string
+ */
+function binl2b64(binarray)
+{
+  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+  var str = "";
+  for(var i = 0; i < binarray.length * 4; i += 3)
+  {
+    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
+                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
+                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
+    for(var j = 0; j < 4; j++)
+    {
+      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
+      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
+    }
+  }
+  return str;
+}
+
+
+
+
+
+
+/*
+Copyright 2005 Collin Jackson
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+    * Neither the name of Stanford University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+/**
+ * Hashed Password
+ * Combination of page URI and plaintext password.
+ * Treated as a string, it is the hashed password.
+ */
+
+function SPH_HashedPassword(password, realm) {
+  var hashedPassword = this._getHashedPassword(password, realm);
+  this.toString = function() { return hashedPassword; }
+}
+
+var SPH_kPasswordPrefix = "@@";
+
+SPH_HashedPassword.prototype = {
+
+  /**
+   * Determine the hashed password from the salt and the master password
+   */
+  _getHashedPassword: function(password, realm) {
+    var hash = b64_hmac_md5(password, realm);
+    var size = password.length + SPH_kPasswordPrefix.length;
+    var nonalphanumeric = password.match(/\W/) != null;
+    var result = this._applyConstraints(hash, size, nonalphanumeric);
+    return result;
+  },
+
+  /**
+   * Fiddle with the password a bit after hashing it so that it will get through
+   * most website filters. We require one upper and lower case, one digit, and
+   * we look at the user's password to determine if there should be at least one 
+   * alphanumeric or not.
+   */
+  _applyConstraints: function(hash, size, nonalphanumeric) {
+    var startingSize = size - 4;  // Leave room for some extra characters
+    var result = hash.substring(0, startingSize);
+    var extras = hash.substring(startingSize).split('');
+
+    // Some utility functions to keep things tidy
+    function nextExtra() { return extras.length ? extras.shift().charCodeAt(0) : 0; }
+    function nextExtraChar() { return String.fromCharCode(nextExtra()); }
+    function rotate(arr, amount) { while(amount--) arr.push(arr.shift()) }
+    function between(min, interval, offset) { return min + offset % interval; }
+    function nextBetween(base, interval) { 
+      return String.fromCharCode(between(base.charCodeAt(0), interval, nextExtra()));
+    }
+    function contains(regex) { return result.match(regex); }
+
+    // Add the extra characters
+    result += (contains(/[A-Z]/) ? nextExtraChar() : nextBetween('A', 26));
+    result += (contains(/[a-z]/) ? nextExtraChar() : nextBetween('a', 26));
+    result += (contains(/[0-9]/) ? nextExtraChar() : nextBetween('0', 10));
+    result += (contains(/\W/) && nonalphanumeric ? nextExtraChar() : '+');
+    while (contains(/\W/) && !nonalphanumeric) {
+      result = result.replace(/\W/, nextBetween('A', 26));
+    }
+
+    // Rotate the result to make it harder to guess the inserted locations
+    result = result.split('');
+    rotate(result, nextExtra());
+    return result.join('');
+  }
+}
+
+
+
diff --git a/salted.c b/salted.c
new file mode 100644 (file)
index 0000000..dadd650
--- /dev/null
+++ b/salted.c
@@ -0,0 +1,194 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <time.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "md5-cl.h"
+#include "b64-cl.h"
+
+#include "hmacmd5.h"
+
+#define SALT_MAX (5)
+#define PASS_MAX (32)
+
+//void mangle(char * password)
+u32x mangle_md5 (u32x w0[4], u32x w1[4], const u32x in_len)
+{
+        u32x out_len = in_len;
+        u32 i;
+
+        u32x digest[4];
+        u32x w0_t[4];
+        u32x w1_t[4];
+        u32x w2_t[4];
+        u32x w3_t[4];
+
+        append_0x80_2x4_VV (w0, w1, out_len);
+
+        w0_t[0] = w0[0];
+        w0_t[1] = w0[1];
+        w0_t[2] = w0[2];
+        w0_t[3] = w0[3];
+        w1_t[0] = w1[0];
+        w1_t[1] = w1[1];
+        w1_t[2] = w1[2];
+        w1_t[3] = w1[3];
+        w2_t[0] = 0;
+        w2_t[1] = 0;
+        w2_t[2] = 0;
+        w2_t[3] = 0;
+        w3_t[0] = 0;
+        w3_t[1] = 0;
+        w3_t[2] = (out_len) * 8;
+        w3_t[3] = 0;
+
+        digest[0] = MD5M_A;
+        digest[1] = MD5M_B;
+        digest[2] = MD5M_C;
+        digest[3] = MD5M_D;
+
+        md5_transform (w0_t, w1_t, w2_t, w3_t, digest);
+
+        u8 b64encoded[16];
+
+/*
+        ((u8 *)digest)[0] = 0x87;
+        ((u8 *)digest)[1] = 0x43;
+        ((u8 *)digest)[2] = 0xb5;
+        ((u8 *)digest)[3] = 0x20;
+        ((u8 *)digest)[4] = 0x63;
+        ((u8 *)digest)[5] = 0xcd;
+*/
+        out_len = b64_encode (b64encoded, 6, (u8 *)digest);
+
+        for (i = out_len; i < 16; i++) {
+                b64encoded[i] = 0;
+        }
+
+/*
+        b64encoded[0] = 'h';
+        b64encoded[1] = '0';
+        b64encoded[2] = 'O';
+        b64encoded[3] = '1';
+        b64encoded[4] = 'I';
+        b64encoded[5] = 'G';
+        b64encoded[6] = 'P';
+        b64encoded[7] = 'N';
+*/
+
+
+        w0[0] = ((u32x *)b64encoded)[0];
+        w0[1] = ((u32x *)b64encoded)[1];
+        w0[2] = ((u32x *)b64encoded)[2];
+        w0[3] = ((u32x *)b64encoded)[3];
+        w1[0] = 0;
+        w1[1] = 0;
+        w1[2] = 0;
+        w1[3] = 0;
+
+        return (out_len);
+}
+
+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[3] = w0[3];
+               data[4] = w1[0];
+               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");
+
+               w0[0] = digest[0];
+               w0[1] = digest[1];
+               w0[2] = digest[2];
+               w0[3] = digest[3];
+               w1[0] = 0;
+               w1[1] = 0;
+               w1[2] = 0;
+               w1[3] = 0;
+
+        out_len = b64_encode ((u8 *)data, 16, (u8 *)w0);
+
+        for (i = out_len; i < 32; i++) {
+                ((u8 *)data)[i] = 0;
+        }
+        
+               w0[0] = data[0];
+               w0[1] = data[1];
+               w0[2] = data[2];
+               w0[3] = data[3];
+               w1[0] = data[4];
+               w1[1] = data[5];
+               w1[2] = data[6];
+               w1[3] = data[7];
+
+        return (out_len);
+}
+
+int main(int argc, char * argv[]) {
+       unsigned char result[RESULT_MAX];
+       unsigned char salt[SALT_MAX];
+       unsigned char digest[DIGEST_SIZE];
+       unsigned char hash[DIGEST_SIZE * 2 + 1];
+       size_t size;
+       int pos;
+       char password[PASS_MAX];
+
+       for (pos = 0; pos < PASS_MAX; pos++) {
+               password[pos] = 0;
+       }
+
+       if (argc > 1) {
+               strncpy(password, argv[1], PASS_MAX);
+       }
+       else {
+               strncpy(password, "hashcat", PASS_MAX);
+       }
+       password[PASS_MAX - 1] = '\0';
+       
+       if (argc > 2) {
+               strncpy(salt, argv[2], SALT_MAX);
+       }
+       else {
+               strncpy(salt, "1234", SALT_MAX);
+       }
+       salt[SALT_MAX - 1] = '\0';
+
+       SPH_HashedPassowrd("hashcat", "flypig.co.uk", result);
+
+       //mangle(password);
+
+       mangle_hmac ((u32x *)password, (u32x *)(password + 16), strlen(password));
+
+       //md5hmac(salt, password, digest);
+
+       md5hmac_cl(salt, strlen(salt), password, strlen(password), digest);
+
+
+       for (pos = 0; pos < DIGEST_SIZE; pos++) {
+               writeHexByte(digest[pos], hash + (pos * 2));
+       }
+       hash[DIGEST_SIZE * 2] = '\0';
+
+       printf("(password, salt) = (\"%s\", \"%s\")\n", password, salt);
+       printf("Result: %s:%s\n", hash, salt);
+
+       return 0;
+}
+