mirror of
https://github.com/sheumann/hush.git
synced 2025-01-04 22:34:37 +00:00
passwd: small size optimization. salt generation improved
(really generated different salts even if called back-to-back).
This commit is contained in:
parent
ab24e18c7a
commit
002526481e
@ -63,6 +63,10 @@ baseline: busybox_unstripped
|
|||||||
objsizes: busybox_unstripped
|
objsizes: busybox_unstripped
|
||||||
$(srctree)/scripts/objsizes
|
$(srctree)/scripts/objsizes
|
||||||
|
|
||||||
|
.PHONY: bigdata
|
||||||
|
bigdata: busybox_unstripped
|
||||||
|
nm --size-sort busybox_unstripped | grep -vi ' [tr] ' | tail -20
|
||||||
|
|
||||||
# Documentation Targets
|
# Documentation Targets
|
||||||
.PHONY: doc
|
.PHONY: doc
|
||||||
doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include <string.h>
|
|
||||||
#include <crypt.h>
|
#include <crypt.h>
|
||||||
|
|
||||||
char *pw_encrypt(const char *clear, const char *salt)
|
char *pw_encrypt(const char *clear, const char *salt)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
#include <sys/times.h> /* times() */
|
||||||
|
|
||||||
|
|
||||||
static void nuke_str(char *str)
|
static void nuke_str(char *str)
|
||||||
@ -19,28 +20,35 @@ static int i64c(int i)
|
|||||||
return '.';
|
return '.';
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
return '/';
|
return '/';
|
||||||
if (i >= 2 && i < 12)
|
if (i < 12)
|
||||||
return ('0' - 2 + i);
|
return ('0' - 2 + i);
|
||||||
if (i >= 12 && i < 38)
|
if (i < 38)
|
||||||
return ('A' - 12 + i);
|
return ('A' - 12 + i);
|
||||||
if (i >= 38 && i < 63)
|
|
||||||
return ('a' - 38 + i);
|
return ('a' - 38 + i);
|
||||||
return 'z';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *crypt_make_salt(void)
|
static void crypt_make_salt(char *p, int cnt)
|
||||||
{
|
{
|
||||||
time_t now;
|
#if !defined(__GLIBC__)
|
||||||
static unsigned long x;
|
struct tms t;
|
||||||
static char result[3];
|
#define TIMES times(&t)
|
||||||
|
#else
|
||||||
|
/* glibc allows for times(NULL) a-la time() */
|
||||||
|
#define TIMES times(NULL)
|
||||||
|
#endif
|
||||||
|
unsigned long x = x; /* it's pointless to initialize it anyway :) */
|
||||||
|
|
||||||
time(&now);
|
x += getpid();
|
||||||
x += now + getpid() + clock();
|
do {
|
||||||
result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077);
|
/* clock() and times() variability is different between systems */
|
||||||
result[1] = i64c(((x >> 12) ^ x) & 077);
|
/* hopefully at least one is good enough */
|
||||||
result[2] = '\0';
|
x += time(NULL) + clock() + TIMES;
|
||||||
return result;
|
*p++ = i64c(((x >> 18) ^ (x >> 6)) & 0x3f);
|
||||||
|
*p++ = i64c(((x >> 12) ^ x) & 0x3f);
|
||||||
|
usleep(100); /* or else time() etc won't change */
|
||||||
|
} while (--cnt);
|
||||||
|
*p = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -88,14 +96,12 @@ static char* new_password(const struct passwd *pw, const char *old_crypted,
|
|||||||
goto err_ret;
|
goto err_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(salt, 0, sizeof(salt));
|
/*memset(salt, 0, sizeof(salt)); - why?*/
|
||||||
if (algo == 1) { /* MD5 */
|
crypt_make_salt(salt, 1); /* des */
|
||||||
|
if (algo) { /* MD5 */
|
||||||
strcpy(salt, "$1$");
|
strcpy(salt, "$1$");
|
||||||
strcat(salt, crypt_make_salt());
|
crypt_make_salt(salt + 3, 4);
|
||||||
strcat(salt, crypt_make_salt());
|
|
||||||
strcat(salt, crypt_make_salt());
|
|
||||||
}
|
}
|
||||||
strcat(salt, crypt_make_salt());
|
|
||||||
ret = xstrdup(pw_encrypt(newp, salt)); /* returns ptr to static */
|
ret = xstrdup(pw_encrypt(newp, salt)); /* returns ptr to static */
|
||||||
/* whee, success! */
|
/* whee, success! */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user