aboutsummaryrefslogtreecommitdiff
path: root/lib/libcrypt/crypt-md5.c
diff options
context:
space:
mode:
authorMark Murray <markm@FreeBSD.org>2002-03-06 17:18:09 +0000
committerMark Murray <markm@FreeBSD.org>2002-03-06 17:18:09 +0000
commitf2ac424af7b980ba4d858ecfd1644ce197d6869d (patch)
treefd253f00aca83bdf5f7478695b3926570dd4df84 /lib/libcrypt/crypt-md5.c
parent214169a10a56ee9a2271b16e36fe40835eb2d1f5 (diff)
downloadsrc-f2ac424af7b980ba4d858ecfd1644ce197d6869d.tar.gz
src-f2ac424af7b980ba4d858ecfd1644ce197d6869d.zip
No functional change, but big code cleanup. WARNS, lint(1) and style(9).
Notes
Notes: svn path=/head/; revision=91754
Diffstat (limited to 'lib/libcrypt/crypt-md5.c')
-rw-r--r--lib/libcrypt/crypt-md5.c94
1 files changed, 47 insertions, 47 deletions
diff --git a/lib/libcrypt/crypt-md5.c b/lib/libcrypt/crypt-md5.c
index 32ad75b02401..e6fbe722d1cd 100644
--- a/lib/libcrypt/crypt-md5.c
+++ b/lib/libcrypt/crypt-md5.c
@@ -22,32 +22,31 @@ __FBSDID("$FreeBSD$");
*/
char *
-crypt_md5(pw, salt)
- const char *pw;
- const char *salt;
+crypt_md5(const char *pw, const char *salt)
{
- static char *magic = "$1$"; /*
- * This string is magic for
- * this algorithm. Having
- * it this way, we can get
- * get better later on
- */
- static char passwd[120], *p;
- static const char *sp,*ep;
- unsigned char final[MD5_SIZE];
- int sl,pl,i;
MD5_CTX ctx,ctx1;
unsigned long l;
+ int sl;
+ u_int pl, i;
+ u_char final[MD5_SIZE];
+ static const char *sp, *ep;
+ static char passwd[120], *p;
+ static const char *magic = "$1$"; /*
+ * This string is magic for
+ * this algorithm. Having
+ * it this way, we can get
+ * get better later on
+ */
/* Refine the Salt first */
sp = salt;
/* If it starts with the magic string, then skip that */
- if(!strncmp(sp,magic,strlen(magic)))
+ if(!strncmp(sp, magic, strlen(magic)))
sp += strlen(magic);
/* It stops at the first '$', max 8 chars */
- for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++)
+ for(ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++)
continue;
/* get the length of the true salt */
@@ -56,83 +55,84 @@ crypt_md5(pw, salt)
MD5Init(&ctx);
/* The password first, since that is what is most unknown */
- MD5Update(&ctx,pw,strlen(pw));
+ MD5Update(&ctx, (const u_char *)pw, strlen(pw));
/* Then our magic string */
- MD5Update(&ctx,magic,strlen(magic));
+ MD5Update(&ctx, (const u_char *)magic, strlen(magic));
/* Then the raw salt */
- MD5Update(&ctx,sp,sl);
+ MD5Update(&ctx, (const u_char *)sp, (u_int)sl);
/* Then just as many characters of the MD5(pw,salt,pw) */
MD5Init(&ctx1);
- MD5Update(&ctx1,pw,strlen(pw));
- MD5Update(&ctx1,sp,sl);
- MD5Update(&ctx1,pw,strlen(pw));
- MD5Final(final,&ctx1);
+ MD5Update(&ctx1, (const u_char *)pw, strlen(pw));
+ MD5Update(&ctx1, (const u_char *)sp, (u_int)sl);
+ MD5Update(&ctx1, (const u_char *)pw, strlen(pw));
+ MD5Final(final, &ctx1);
for(pl = strlen(pw); pl > 0; pl -= MD5_SIZE)
- MD5Update(&ctx,final,pl>MD5_SIZE ? MD5_SIZE : pl);
+ MD5Update(&ctx, (const u_char *)final,
+ pl > MD5_SIZE ? MD5_SIZE : pl);
/* Don't leave anything around in vm they could use. */
- memset(final,0,sizeof final);
+ memset(final, 0, sizeof(final));
/* Then something really weird... */
- for (i = strlen(pw); i ; i >>= 1)
- if(i&1)
- MD5Update(&ctx, final, 1);
+ for (i = strlen(pw); i; i >>= 1)
+ if(i & 1)
+ MD5Update(&ctx, (const u_char *)final, 1);
else
- MD5Update(&ctx, pw, 1);
+ MD5Update(&ctx, (const u_char *)pw, 1);
/* Now make the output string */
- strcpy(passwd,magic);
- strncat(passwd,sp,sl);
- strcat(passwd,"$");
+ strcpy(passwd, magic);
+ strncat(passwd, sp, (u_int)sl);
+ strcat(passwd, "$");
- MD5Final(final,&ctx);
+ MD5Final(final, &ctx);
/*
* and now, just to make sure things don't run too fast
* On a 60 Mhz Pentium this takes 34 msec, so you would
* need 30 seconds to build a 1000 entry dictionary...
*/
- for(i=0;i<1000;i++) {
+ for(i = 0; i < 1000; i++) {
MD5Init(&ctx1);
if(i & 1)
- MD5Update(&ctx1,pw,strlen(pw));
+ MD5Update(&ctx1, (const u_char *)pw, strlen(pw));
else
- MD5Update(&ctx1,final,MD5_SIZE);
+ MD5Update(&ctx1, (const u_char *)final, MD5_SIZE);
if(i % 3)
- MD5Update(&ctx1,sp,sl);
+ MD5Update(&ctx1, (const u_char *)sp, (u_int)sl);
if(i % 7)
- MD5Update(&ctx1,pw,strlen(pw));
+ MD5Update(&ctx1, (const u_char *)pw, strlen(pw));
if(i & 1)
- MD5Update(&ctx1,final,MD5_SIZE);
+ MD5Update(&ctx1, (const u_char *)final, MD5_SIZE);
else
- MD5Update(&ctx1,pw,strlen(pw));
- MD5Final(final,&ctx1);
+ MD5Update(&ctx1, (const u_char *)pw, strlen(pw));
+ MD5Final(final, &ctx1);
}
p = passwd + strlen(passwd);
l = (final[ 0]<<16) | (final[ 6]<<8) | final[12];
- _crypt_to64(p,l,4); p += 4;
+ _crypt_to64(p, l, 4); p += 4;
l = (final[ 1]<<16) | (final[ 7]<<8) | final[13];
- _crypt_to64(p,l,4); p += 4;
+ _crypt_to64(p, l, 4); p += 4;
l = (final[ 2]<<16) | (final[ 8]<<8) | final[14];
- _crypt_to64(p,l,4); p += 4;
+ _crypt_to64(p, l, 4); p += 4;
l = (final[ 3]<<16) | (final[ 9]<<8) | final[15];
- _crypt_to64(p,l,4); p += 4;
+ _crypt_to64(p, l, 4); p += 4;
l = (final[ 4]<<16) | (final[10]<<8) | final[ 5];
- _crypt_to64(p,l,4); p += 4;
+ _crypt_to64(p, l, 4); p += 4;
l = final[11] ;
- _crypt_to64(p,l,2); p += 2;
+ _crypt_to64(p, l, 2); p += 2;
*p = '\0';
/* Don't leave anything around in vm they could use. */
- memset(final,0,sizeof final);
+ memset(final, 0, sizeof(final));
return passwd;
}