summaryrefslogtreecommitdiff
path: root/libbb/pw_encrypt.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-07 01:16:34 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-07 01:16:34 +0000
commitd1a84a2880073f6cc5e2f9f4e5f236cd110f01a0 (patch)
tree8e5b81c863ef3b91870812e822fecc3d97b0aff7 /libbb/pw_encrypt.c
parentdb12d1d733ab7de0c5f4cda261eb79fd334a4ed9 (diff)
downloadbusybox-w32-d1a84a2880073f6cc5e2f9f4e5f236cd110f01a0.tar.gz
busybox-w32-d1a84a2880073f6cc5e2f9f4e5f236cd110f01a0.tar.bz2
busybox-w32-d1a84a2880073f6cc5e2f9f4e5f236cd110f01a0.zip
libbb: move crypt_make_salt() to pw_encrypt.c, reuse
bin-to-ascii64 conversion which does not require an array. function old new delta to64 29 33 +4 to64_msb_first 63 62 -1 ascii64 65 - -65
Diffstat (limited to 'libbb/pw_encrypt.c')
-rw-r--r--libbb/pw_encrypt.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c
index 572591ea9..6fc0ba87c 100644
--- a/libbb/pw_encrypt.c
+++ b/libbb/pw_encrypt.c
@@ -1,6 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * Utility routine. 3 * Utility routines.
4 * 4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * 6 *
@@ -9,25 +9,62 @@
9 9
10#include "libbb.h" 10#include "libbb.h"
11 11
12#if ENABLE_USE_BB_CRYPT 12/* static const uint8_t ascii64[] =
13 13 * "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
14/*
15 * DES and MD5 crypt implementations are taken from uclibc.
16 * They were modified to not use static buffers.
17 */ 14 */
18 15
19/* Used by pw_encrypt_XXX.c */ 16static int i64c(int i)
20static const uint8_t ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 17{
18 i &= 0x3f;
19 if (i == 0)
20 return '.';
21 if (i == 1)
22 return '/';
23 if (i < 12)
24 return ('0' - 2 + i);
25 if (i < 38)
26 return ('A' - 12 + i);
27 return ('a' - 38 + i);
28}
29
30int FAST_FUNC crypt_make_salt(char *p, int cnt, int x)
31{
32 x += getpid() + time(NULL);
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 return x;
48}
49
50#if ENABLE_USE_BB_CRYPT
51
21static char* 52static char*
22to64(char *s, unsigned v, int n) 53to64(char *s, unsigned v, int n)
23{ 54{
24 while (--n >= 0) { 55 while (--n >= 0) {
25 *s++ = ascii64[v & 0x3f]; 56 /* *s++ = ascii64[v & 0x3f]; */
57 *s++ = i64c(v);
26 v >>= 6; 58 v >>= 6;
27 } 59 }
28 return s; 60 return s;
29} 61}
30 62
63/*
64 * DES and MD5 crypt implementations are taken from uclibc.
65 * They were modified to not use static buffers.
66 */
67
31#include "pw_encrypt_des.c" 68#include "pw_encrypt_des.c"
32#include "pw_encrypt_md5.c" 69#include "pw_encrypt_md5.c"
33#if ENABLE_USE_BB_CRYPT_SHA 70#if ENABLE_USE_BB_CRYPT_SHA