diff options
-rw-r--r-- | include/crypt.h | 5 | ||||
-rw-r--r-- | libcrypt/des.c | 28 | ||||
-rw-r--r-- | libcrypt/md5.c | 5 |
3 files changed, 16 insertions, 22 deletions
diff --git a/include/crypt.h b/include/crypt.h index af9aaca7a..fd5d0f67f 100644 --- a/include/crypt.h +++ b/include/crypt.h @@ -44,14 +44,17 @@ extern void encrypt (char *__block, int __edflag); struct block { unsigned char b_data[64]; }; +struct ordering { + unsigned char o_data[64]; +}; struct crypt_data { /* Stuff used by the des based routines */ struct block key; + const struct ordering *EP; /* Stuff used by the md5 based routines */ char *p; const char *sp,*ep; - char KS[16][48]; }; extern char *crypt_r (const char *__key, const char *__salt, diff --git a/libcrypt/des.c b/libcrypt/des.c index 22392d929..93803d2e0 100644 --- a/libcrypt/des.c +++ b/libcrypt/des.c @@ -44,20 +44,9 @@ */ #include <crypt.h> -#include <string.h> -#include <unistd.h> -extern char *md5_magic; extern char * md5_crypt_r( const char *pw, const char *salt, struct crypt_data * data); -//struct block { -// unsigned char b_data[64]; -//}; - -struct ordering { - unsigned char o_data[64]; -}; - static const struct ordering InitialTr = { { 58,50,42,34,26,18,10, 2,60,52,44,36,28,20,12, 4, 62,54,46,38,30,22,14, 6,64,56,48,40,32,24,16, 8, @@ -181,16 +170,14 @@ static void rotate(struct block *key) key->b_data[55] = data28; } -static const struct ordering *EP = &etr; - -static void f(int i, struct block *key, struct block *a, struct block *x) +static void f(int i, struct block *key, struct block *a, struct block *x, struct crypt_data *data) { struct block e, ikey, y; int k; unsigned char *p, *q, *r; e = *a; - transpose(&e, EP, 48); + transpose(&e, data->EP, 48); for (k = rots[i]; k; k--) rotate(key); ikey = *key; transpose(&ikey, &KeyTr2, 48); @@ -244,7 +231,7 @@ extern void encrypt_r(char *blck, int edflag, struct crypt_data *data) for (k = 31; k >= 0; k--) { p->b_data[k] = b.b_data[k + 32]; } - f(j, key, p, &x); + f(j, key, p, &x, data); for (k = 31; k >= 0; k--) { p->b_data[k+32] = b.b_data[k] ^ x.b_data[k]; } @@ -264,9 +251,10 @@ extern char *crypt_r(const char *pw, const char *salt, struct crypt_data *data) /* First, check if we are supposed to be using the MD5 replacement * instead of DES... */ - if (strncmp (md5_magic, salt, sizeof (md5_magic) - 1) == 0) + if (salt[0]=='$' && salt[1]=='1' && salt[2]=='$') return md5_crypt_r(pw, salt, data); + data->EP = &etr; while (*pw && p < &pwb[64]) { int j = 7; @@ -283,7 +271,7 @@ extern char *crypt_r(const char *pw, const char *salt, struct crypt_data *data) while (p < &pwb[66]) *p++ = 0; new_etr = etr; - EP = &new_etr; + data->EP = &new_etr; if (salt[0] == 0 || salt[1] == 0) salt = "**"; for (i = 0; i < 2; i++) { char c = *salt++; @@ -306,8 +294,8 @@ extern char *crypt_r(const char *pw, const char *salt, struct crypt_data *data) if (result[1] == 0) result[1] = result[0]; - for (i = 0; i < 25; i++) encrypt(pwb,0); - EP = &etr; + for (i = 0; i < 25; i++) encrypt_r(pwb,0, data); + data->EP = &etr; p = pwb; cp = result+2; diff --git a/libcrypt/md5.c b/libcrypt/md5.c index f6e6709d7..66ff0d119 100644 --- a/libcrypt/md5.c +++ b/libcrypt/md5.c @@ -383,7 +383,10 @@ char * md5_crypt_r( const char *pw, const char *salt, struct crypt_data * data) char *p = data->p; const char *sp = data->sp; const char *ep = data->ep; - char *passwd = *data->KS; + char *passwd = data->key.b_data; /* This is a nice place where we can grab + a bit of reentrant space... I'd create + a separate field in struct crypt_data, + but this spot should do nicely... */ unsigned char final[17]; /* final[16] exists only to aid in looping */ int sl,pl,i,md5_magic_len,pw_len; MD5_CTX ctx,ctx1; |