From 3403742655702257d5c4972ab6ec23eb95c3fede Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 16 Oct 2013 20:01:46 -0500 Subject: Minor lib/password.c cleanup, described on the list. (Inline two functions.) --- lib/password.c | 65 ++++++++++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/lib/password.c b/lib/password.c index b340ef48..6e8f0554 100644 --- a/lib/password.c +++ b/lib/password.c @@ -7,57 +7,46 @@ #include "xregcomp.h" #include -static unsigned int random_number_generator(int fd) -{ - unsigned int randnum; - - xreadall(fd, &randnum, sizeof(randnum)); - return randnum; -} - -static char inttoc(int i) -{ - // salt value uses 64 chracters in "./0-9a-zA-Z" - const char character_set[]="./0123456789abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - i &= 0x3f; // masking for using 10 bits only - return character_set[i]; -} - int get_salt(char *salt, char *algo) { - int i, randfd, salt_length = 0, offset; + int i, len = 0, offset = 0; + char buf[12]; - if (!strcmp(algo,"des")){ - // 2 bytes salt value is used in des - salt_length = 2; - offset = 0; - } else { + if (!strcmp(algo,"des")) len = 2; + else { *salt++ = '$'; - if (!strcmp(algo,"md5")){ + if (!strcmp(algo,"md5")) { *salt++ = '1'; - // 8 bytes salt value is used in md5 - salt_length = 8; - } else if (!strcmp(algo,"sha256")){ + len = 8; + } else if (!strcmp(algo,"sha256")) { *salt++ = '5'; - // 16 bytes salt value is used in sha256 - salt_length = 16; - } else if (!strcmp(algo,"sha512")){ + len = 16; + } else if (!strcmp(algo,"sha512")) { *salt++ = '6'; - // 16 bytes salt value is used in sha512 - salt_length = 16; + len = 16; } else return -1; *salt++ = '$'; offset = 3; } - randfd = xopen("/dev/urandom", O_RDONLY); - for (i=0; i> (bitpos&7)) & 0x3f; + bits += 46; + if (bits > 57) bits += 8; + if (bits > 90) bits += 7; + + salt[i] = bits; + } + salt[i] = 0; return offset; } -- cgit v1.2.3