summaryrefslogtreecommitdiff
path: root/libbb/crypt_make_salt.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-05-08 23:23:35 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-05-08 23:23:35 +0000
commita035e9f1a9028ad7fb4e9082cc7e383c3e4615cf (patch)
tree089381ac1517da548d262ed60a7b12a742c9ee51 /libbb/crypt_make_salt.c
parenta04561f5f7b6f1975c1bded6f11001f03190058c (diff)
downloadbusybox-w32-a035e9f1a9028ad7fb4e9082cc7e383c3e4615cf.tar.gz
busybox-w32-a035e9f1a9028ad7fb4e9082cc7e383c3e4615cf.tar.bz2
busybox-w32-a035e9f1a9028ad7fb4e9082cc7e383c3e4615cf.zip
cryptpw: forgot svn add... how typical of me :(
Diffstat (limited to 'libbb/crypt_make_salt.c')
-rw-r--r--libbb/crypt_make_salt.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/libbb/crypt_make_salt.c b/libbb/crypt_make_salt.c
new file mode 100644
index 000000000..12e96328f
--- /dev/null
+++ b/libbb/crypt_make_salt.c
@@ -0,0 +1,48 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * crypt_make_salt
4 *
5 * i64c was also put here, this is the only function that uses it.
6 *
7 * Lifted from loginutils/passwd.c by Thomas Lundquist <thomasez@zelow.no>
8 *
9 */
10
11#include "libbb.h"
12
13static int i64c(int i)
14{
15 i &= 0x3f;
16 if (i == 0)
17 return '.';
18 if (i == 1)
19 return '/';
20 if (i < 12)
21 return ('0' - 2 + i);
22 if (i < 38)
23 return ('A' - 12 + i);
24 return ('a' - 38 + i);
25}
26
27
28void crypt_make_salt(char *p, int cnt)
29{
30 unsigned x = x; /* it's pointless to initialize it anyway :) */
31
32 x += getpid() + time(NULL) + clock();
33 do {
34 /* x = (x*1664525 + 1013904223) % 2^32 generator is lame
35 * (low-order bit is not "random", etc...),
36 * but for our purposes it is good enough */
37 x = x*1664525 + 1013904223;
38 /* BTW, Park and Miller's "minimal standard generator" is
39 * x = x*16807 % ((2^31)-1)
40 * It has no problem with visibly alternating lowest bit
41 * but is also weak in cryptographic sense + needs div,
42 * which needs more code (and slower) on many CPUs */
43 *p++ = i64c(x >> 16);
44 *p++ = i64c(x >> 22);
45 } while (--cnt);
46 *p = '\0';
47}
48