summaryrefslogtreecommitdiffstats
path: root/lib/libcrypt
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2002-03-06 17:18:09 +0000
committermarkm <markm@FreeBSD.org>2002-03-06 17:18:09 +0000
commitff64831dcfcd492ea83c2737516a9d787ad12777 (patch)
treefd253f00aca83bdf5f7478695b3926570dd4df84 /lib/libcrypt
parent506a396cdb6278fa21dba5d8afa255c493b62098 (diff)
downloadFreeBSD-src-ff64831dcfcd492ea83c2737516a9d787ad12777.zip
FreeBSD-src-ff64831dcfcd492ea83c2737516a9d787ad12777.tar.gz
No functional change, but big code cleanup. WARNS, lint(1) and style(9).
Diffstat (limited to 'lib/libcrypt')
-rw-r--r--lib/libcrypt/crypt-md5.c94
-rw-r--r--lib/libcrypt/crypt.c16
-rw-r--r--lib/libcrypt/crypt.h2
-rw-r--r--lib/libcrypt/misc.c11
4 files changed, 63 insertions, 60 deletions
diff --git a/lib/libcrypt/crypt-md5.c b/lib/libcrypt/crypt-md5.c
index 32ad75b..e6fbe72 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;
}
diff --git a/lib/libcrypt/crypt.c b/lib/libcrypt/crypt.c
index 4f77c75..a41ee85 100644
--- a/lib/libcrypt/crypt.c
+++ b/lib/libcrypt/crypt.c
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <string.h>
#include <libutil.h>
+#include <unistd.h>
#include "crypt.h"
static const struct {
@@ -58,6 +59,7 @@ static const struct {
#endif
{
NULL,
+ NULL,
NULL
}
};
@@ -68,7 +70,7 @@ static void
crypt_setdefault(void)
{
char *def;
- int i;
+ size_t i;
if (crypt_type != -1)
return;
@@ -79,7 +81,7 @@ crypt_setdefault(void)
}
for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) {
if (strcmp(def, crypt_types[i].name) == 0) {
- crypt_type = i;
+ crypt_type = (int)i;
return;
}
}
@@ -95,14 +97,14 @@ crypt_get_format(void)
}
int
-crypt_set_format(char *type)
+crypt_set_format(const char *type)
{
- int i;
+ size_t i;
crypt_setdefault();
for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) {
if (strcmp(type, crypt_types[i].name) == 0) {
- crypt_type = i;
+ crypt_type = (int)i;
return (1);
}
}
@@ -110,9 +112,9 @@ crypt_set_format(char *type)
}
char *
-crypt(char *passwd, char *salt)
+crypt(const char *passwd, const char *salt)
{
- int i;
+ size_t i;
crypt_setdefault();
for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) {
diff --git a/lib/libcrypt/crypt.h b/lib/libcrypt/crypt.h
index b62bd8e..2488ac8 100644
--- a/lib/libcrypt/crypt.h
+++ b/lib/libcrypt/crypt.h
@@ -34,5 +34,5 @@ char *crypt_des(const char *pw, const char *salt);
char *crypt_md5(const char *pw, const char *salt);
char *crypt_blowfish(const char *pw, const char *salt);
-extern void _crypt_to64(char *s, unsigned long v, int n);
+extern void _crypt_to64(char *s, u_long v, int n);
diff --git a/lib/libcrypt/misc.c b/lib/libcrypt/misc.c
index de2e024..594c580 100644
--- a/lib/libcrypt/misc.c
+++ b/lib/libcrypt/misc.c
@@ -30,14 +30,15 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
+#include <sys/types.h>
+
+#include "crypt.h"
+
+static char itoa64[] = /* 0 ... 63 => ascii - 64 */
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
void
-_crypt_to64(s, v, n)
- char *s;
- unsigned long v;
- int n;
+_crypt_to64(char *s, u_long v, int n)
{
while (--n >= 0) {
*s++ = itoa64[v&0x3f];
OpenPOWER on IntegriCloud