33 "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
35static void md5to64(
char *s,
unsigned long v,
int n)
56 const char *magic =
"$1$";
58 static char passwd[120], *p;
59 static const char *
sp, *ep;
60 unsigned char final[16];
68 while (*salt && *salt !=
'$')
72 magiclen = salt - magic;
83 for (ep =
sp; *ep && *ep !=
'$' && ep < (
sp + 8); ++ep)
106 for (pl = strlen(pw); pl > 0; pl -= 16)
107 SquidMD5Update(&ctx, (
unsigned const char *)
final, pl > 16 ? 16 : pl);
110 memset(
final, 0,
sizeof final);
113 for (j = 0, i = strlen(pw); i; i >>= 1)
120 memset(passwd, 0,
sizeof(passwd));
121 strncat(passwd, magic, magiclen);
122 strncat(passwd,
sp, sl);
132 for (i = 0; i < 1000; ++i) {
152 p = passwd + strlen(passwd);
154 l = (
final[0] << 16) | (
final[6] << 8) |
final[12];
157 l = (
final[1] << 16) | (
final[7] << 8) |
final[13];
160 l = (
final[2] << 16) | (
final[8] << 8) |
final[14];
163 l = (
final[3] << 16) | (
final[9] << 8) |
final[15];
166 l = (
final[4] << 16) | (
final[10] << 8) |
final[5];
175 memset(
final, 0,
sizeof final);
185 static unsigned char digest[16];
196 for (idx=0; idx<16; ++idx)
197 snprintf(&sum[idx*2],(33-(idx*2)),
"%02x",digest[idx]);
202 memset(digest, 0,
sizeof digest);
char * md5sum(const char *s)
char * crypt_md5(const char *pw, const char *salt)
static void md5to64(char *s, unsigned long v, int n)
static unsigned char itoa64[]
SQUIDCEXTERN void SquidMD5Init(struct SquidMD5Context *context)
SQUIDCEXTERN void SquidMD5Update(struct SquidMD5Context *context, const void *buf, unsigned len)
SQUIDCEXTERN void SquidMD5Final(uint8_t digest[16], struct SquidMD5Context *context)