2 * File imported from FreeBSD, original by Poul-Henning Kamp.
4 * $FreeBSD: src/lib/libcrypt/crypt-md5.c,v 1.5 1999年12月17日 20:21:45 peter Exp $
6 * contrib/pgcrypto/crypt-md5.c
17"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
34 px_crypt_md5(
const char *pw,
const char *salt,
char *passwd,
unsigned dstlen)
36 static const char *magic =
"1ドル$";
/* This string is magic for this
37 * algorithm. Having it this way, we
38 * can get better later on */
51 if (!passwd || dstlen < 120)
54 /* Refine the Salt first */
57 /* If it starts with the magic string, then skip that */
58 if (strncmp(sp, magic, strlen(magic)) == 0)
61 /* It stops at the first '$', max 8 chars */
62 for (ep = sp; *ep && *ep !=
'$' && ep < (sp + 8); ep++)
65 /* get the length of the true salt */
68 /* we need two PX_MD objects */
75 /* this path is possible under low-memory circumstances */
80 /* The password first, since that is what is most unknown */
83 /* Then our magic string */
86 /* Then the raw salt */
89 /* Then just as many characters of the MD5(pw,salt,pw) */
94 for (pl = strlen(pw); pl > 0; pl -=
MD5_SIZE)
97 /* Don't leave anything around in vm they could use. */
100 /* Then something really weird... */
101 for (
i = strlen(pw);
i;
i >>= 1)
107 /* Now make the output string */
108 strcpy(passwd, magic);
109 strncat(passwd, sp, sl);
115 * and now, just to make sure things don't run too fast On a 60 Mhz
116 * Pentium this takes 34 msec, so you would need 30 seconds to build a
117 * 1000 entry dictionary...
119 for (
i = 0;
i < 1000;
i++)
140 p = passwd + strlen(passwd);
142 l = (
final[0] << 16) | (
final[6] << 8) |
final[12];
145 l = (
final[1] << 16) | (
final[7] << 8) |
final[13];
148 l = (
final[2] << 16) | (
final[8] << 8) |
final[14];
151 l = (
final[3] << 16) | (
final[9] << 8) |
final[15];
154 l = (
final[4] << 16) | (
final[10] << 8) |
final[5];
162 /* Don't leave anything around in vm they could use. */
char * px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen)
static const char _crypt_a64[]
static void _crypt_to64(char *s, unsigned long v, int n)
void err(int eval, const char *fmt,...)
int px_find_digest(const char *name, PX_MD **res)
void px_memset(void *ptr, int c, size_t len)
#define px_md_finish(md, buf)
#define px_md_update(md, data, dlen)