summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt/crypt2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/crypt/crypt2.c')
-rw-r--r--src/lib/libc/crypt/crypt2.c107
1 files changed, 0 insertions, 107 deletions
diff --git a/src/lib/libc/crypt/crypt2.c b/src/lib/libc/crypt/crypt2.c
deleted file mode 100644
index f64721368a..0000000000
--- a/src/lib/libc/crypt/crypt2.c
+++ /dev/null
@@ -1,107 +0,0 @@
1/* $OpenBSD: crypt2.c,v 1.5 2014/05/17 13:27:55 tedu Exp $ */
2
3/*
4 * FreeSec: libcrypt
5 *
6 * Copyright (c) 1994 David Burren
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 4. Neither the name of the author nor the names of other contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *
34 * This is an original implementation of the DES and the crypt(3) interfaces
35 * by David Burren <davidb@werj.com.au>.
36 *
37 * An excellent reference on the underlying algorithm (and related
38 * algorithms) is:
39 *
40 * B. Schneier, Applied Cryptography: protocols, algorithms,
41 * and source code in C, John Wiley & Sons, 1994.
42 *
43 * Note that in that book's description of DES the lookups for the initial,
44 * pbox, and final permutations are inverted (this has been brought to the
45 * attention of the author). A list of errata for this book has been
46 * posted to the sci.crypt newsgroup by the author and is available for FTP.
47 */
48
49#include <sys/types.h>
50#include <sys/param.h>
51#include <pwd.h>
52#include <unistd.h>
53#include <string.h>
54
55#ifdef DEBUG
56# include <stdio.h>
57#endif
58
59extern const u_char _des_bits8[8];
60extern const u_int32_t _des_bits32[32];
61extern int _des_initialised;
62void _des_init(void);
63u_int32_t _des_setup_salt(int32_t salt);
64int _des_do_des(u_int32_t , u_int32_t , u_int32_t *, u_int32_t *, int, u_int32_t);
65
66int
67setkey(const char *key)
68{
69 int i, j;
70 u_int32_t packed_keys[2];
71 u_char *p;
72
73 p = (u_char *) packed_keys;
74
75 for (i = 0; i < 8; i++) {
76 p[i] = 0;
77 for (j = 0; j < 8; j++)
78 if (*key++ & 1)
79 p[i] |= _des_bits8[j];
80 }
81 return(des_setkey((char *)p));
82}
83
84int
85encrypt(char *block, int flag)
86{
87 u_int32_t saltbits, io[2];
88 u_char *p;
89 int i, j, retval;
90
91 if (!_des_initialised)
92 _des_init();
93
94 saltbits = _des_setup_salt(0);
95 p = (u_char *)block;
96 for (i = 0; i < 2; i++) {
97 io[i] = 0L;
98 for (j = 0; j < 32; j++)
99 if (*p++ & 1)
100 io[i] |= _des_bits32[j];
101 }
102 retval = _des_do_des(io[0], io[1], io, io + 1, flag ? -1 : 1, saltbits);
103 for (i = 0; i < 2; i++)
104 for (j = 0; j < 32; j++)
105 block[(i << 5) | j] = (io[i] & _des_bits32[j]) ? 1 : 0;
106 return(retval);
107}