source: main/trunk/greenstone2/common-src/src/getpw/crypt.c@ 26651

Last change on this file since 26651 was 26647, checked in by davidb, 11 years ago

Introduction of open-source code that implements the crypt() algorithm to make Greenstone code more portable. Motivation for adding this in came from work with cross-compiling (using mingw under Ubuntu for generating Windows native binaries)

File size: 1.9 KB
Line 
1/*
2 * UFC-crypt: ultra fast crypt(3) implementation
3 *
4 * Copyright (C) 1991, Michael Glad, email: [email protected]
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * @(#)crypt.c 2.2 10/04/91
21 *
22 * Semiportable C version
23 *
24 */
25
26#include "crypt_util.h"
27
28extern unsigned long sb0[], sb1[], sb2[], sb3[];
29extern unsigned long keytab[16][2];
30
31#define SBA(sb, v) (*(unsigned long*)((char*)(sb)+(v)))
32
33#define F(I, O1, O2, SBX, SBY) \
34 s = *k++ ^ I; \
35 O1 ^= SBA(SBX, (s & 0xffff)); O2 ^= SBA(SBX, ((s & 0xffff) + 4)); \
36 O1 ^= SBA(SBY, (s >>= 16)); O2 ^= SBA(SBY, ((s) + 4));
37
38#define G(I1, I2, O1, O2) \
39 F(I1, O1, O2, sb1, sb0) F(I2, O1, O2, sb3, sb2)
40
41#define H G(r1, r2, l1, l2) ; G(l1, l2, r1, r2)
42
43char *crypt(key, salt)
44 char *key;
45 char *salt;
46 { unsigned long l1, l2, r1, r2, i, j, s, *k;
47
48 setup_salt(salt);
49 mk_keytab(key);
50
51 l1=l2=r1=r2=0;
52
53 for(j=0; j<25; j++) {
54 k = &keytab[0][0];
55 for(i=8; i--; ) {
56 H;
57 }
58 s=l1; l1=r1; r1=s; s=l2; l2=r2; r2=s;
59 }
60
61 return output_conversion(l1, l2, r1, r2, salt);
62 }
63
Note: See TracBrowser for help on using the repository browser.