|
@ -1,3 +1,5 @@ |
|
|
|
|
|
/* $OpenBSD: md5crypt.c,v 1.6 1996/10/15 09:25:32 deraadt Exp $ */ |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* ---------------------------------------------------------------------------- |
|
|
* ---------------------------------------------------------------------------- |
|
|
* "THE BEER-WARE LICENSE" (Revision 42): |
|
|
* "THE BEER-WARE LICENSE" (Revision 42): |
|
@ -6,20 +8,25 @@ |
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp |
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp |
|
|
* ---------------------------------------------------------------------------- |
|
|
* ---------------------------------------------------------------------------- |
|
|
* |
|
|
* |
|
|
|
|
|
* $FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp $ |
|
|
|
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
static char rcsid[] = "$OpenBSD: md5crypt.c,v 1.5 1996/09/15 09:30:46 tholo Exp $"; |
|
|
|
|
|
|
|
|
static char rcsid[] = "$OpenBSD: md5crypt.c,v 1.6 1996/10/15 09:25:32 deraadt Exp $"; |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
|
|
|
|
|
|
#include <unistd.h> |
|
|
#include <unistd.h> |
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
#include <md5.h> |
|
|
#include <md5.h> |
|
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ |
|
|
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ |
|
|
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
|
|
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
|
|
|
|
|
|
|
|
|
|
|
static void to64 __P((char *, unsigned long, int)); |
|
|
|
|
|
|
|
|
static void |
|
|
static void |
|
|
to64(s, v, n) |
|
|
to64(s, v, n) |
|
|
char *s; |
|
|
char *s; |
|
@ -47,7 +54,7 @@ md5crypt(pw, salt) |
|
|
* This string is magic for this algorithm. Having |
|
|
* This string is magic for this algorithm. Having |
|
|
* it this way, we can get get better later on |
|
|
* it this way, we can get get better later on |
|
|
*/ |
|
|
*/ |
|
|
static char *magic = "$1$"; |
|
|
|
|
|
|
|
|
static char *magic = "$1$"; |
|
|
|
|
|
|
|
|
static char passwd[120], *p; |
|
|
static char passwd[120], *p; |
|
|
static const char *sp,*ep; |
|
|
static const char *sp,*ep; |
|
@ -94,11 +101,11 @@ md5crypt(pw, salt) |
|
|
memset(final,0,sizeof final); |
|
|
memset(final,0,sizeof final); |
|
|
|
|
|
|
|
|
/* Then something really weird... */ |
|
|
/* Then something really weird... */ |
|
|
for (j=0,i = strlen(pw); i ; i >>= 1) |
|
|
|
|
|
|
|
|
for (i = strlen(pw); i ; i >>= 1) |
|
|
if(i&1) |
|
|
if(i&1) |
|
|
MD5Update(&ctx, final+j, 1); |
|
|
|
|
|
|
|
|
MD5Update(&ctx, final, 1); |
|
|
else |
|
|
else |
|
|
MD5Update(&ctx, pw+j, 1); |
|
|
|
|
|
|
|
|
MD5Update(&ctx, pw, 1); |
|
|
|
|
|
|
|
|
/* Now make the output string */ |
|
|
/* Now make the output string */ |
|
|
strcpy(passwd,magic); |
|
|
strcpy(passwd,magic); |
|
|