diff options
author | tedu <> | 2014-12-08 20:36:18 +0000 |
---|---|---|
committer | tedu <> | 2014-12-08 20:36:18 +0000 |
commit | 10acb2de70dd4a4b42dd0d116bac4d41520e3ca5 (patch) | |
tree | 3a8e5aa42b3c2460510a803fb0fd503de59f49a1 /src | |
parent | c52b1aafaaead44ed582498ae01421c9181a789a (diff) | |
download | openbsd-10acb2de70dd4a4b42dd0d116bac4d41520e3ca5.tar.gz openbsd-10acb2de70dd4a4b42dd0d116bac4d41520e3ca5.tar.bz2 openbsd-10acb2de70dd4a4b42dd0d116bac4d41520e3ca5.zip |
remove setkey and encrypt interfaces. they are useless and dangerous.
ok deraadt naddy
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/crypt/Makefile.inc | 4 | ||||
-rw-r--r-- | src/lib/libc/crypt/crypt.c | 14 | ||||
-rw-r--r-- | src/lib/libc/crypt/crypt2.c | 107 |
3 files changed, 9 insertions, 116 deletions
diff --git a/src/lib/libc/crypt/Makefile.inc b/src/lib/libc/crypt/Makefile.inc index f4cf2de027..2a06f73acc 100644 --- a/src/lib/libc/crypt/Makefile.inc +++ b/src/lib/libc/crypt/Makefile.inc | |||
@@ -1,8 +1,8 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.24 2014/11/20 19:18:25 tedu Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.25 2014/12/08 20:36:18 tedu Exp $ |
2 | 2 | ||
3 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/crypt ${LIBCSRCDIR}/crypt | 3 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/crypt ${LIBCSRCDIR}/crypt |
4 | 4 | ||
5 | SRCS+= crypt.c crypt2.c cryptutil.c arc4random.c arc4random_uniform.c \ | 5 | SRCS+= crypt.c cryptutil.c arc4random.c arc4random_uniform.c \ |
6 | blowfish.c bcrypt.c | 6 | blowfish.c bcrypt.c |
7 | 7 | ||
8 | MAN+= crypt.3 crypt_checkpass.3 blowfish.3 arc4random.3 | 8 | MAN+= crypt.3 crypt_checkpass.3 blowfish.3 arc4random.3 |
diff --git a/src/lib/libc/crypt/crypt.c b/src/lib/libc/crypt/crypt.c index a4c864dea3..c7ff5d970b 100644 --- a/src/lib/libc/crypt/crypt.c +++ b/src/lib/libc/crypt/crypt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: crypt.c,v 1.24 2014/11/25 03:23:22 tedu Exp $ */ | 1 | /* $OpenBSD: crypt.c,v 1.25 2014/12/08 20:36:18 tedu Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * FreeSec: libcrypt | 4 | * FreeSec: libcrypt |
@@ -158,7 +158,7 @@ const u_int32_t _des_bits32[32] = | |||
158 | 0x00000008, 0x00000004, 0x00000002, 0x00000001 | 158 | 0x00000008, 0x00000004, 0x00000002, 0x00000001 |
159 | }; | 159 | }; |
160 | 160 | ||
161 | const u_char _des_bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; | 161 | static const u_char _des_bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; |
162 | 162 | ||
163 | static const u_int32_t *bits28, *bits24; | 163 | static const u_int32_t *bits28, *bits24; |
164 | static u_char init_perm[64], final_perm[64]; | 164 | static u_char init_perm[64], final_perm[64]; |
@@ -196,7 +196,7 @@ ascii_to_bin(char ch) | |||
196 | return(0); | 196 | return(0); |
197 | } | 197 | } |
198 | 198 | ||
199 | void | 199 | static void |
200 | _des_init(void) | 200 | _des_init(void) |
201 | { | 201 | { |
202 | int i, j, b, k, inbit, obit; | 202 | int i, j, b, k, inbit, obit; |
@@ -324,7 +324,7 @@ _des_init(void) | |||
324 | _des_initialised = 1; | 324 | _des_initialised = 1; |
325 | } | 325 | } |
326 | 326 | ||
327 | u_int32_t | 327 | static u_int32_t |
328 | _des_setup_salt(int32_t salt) | 328 | _des_setup_salt(int32_t salt) |
329 | { | 329 | { |
330 | u_int32_t obit, saltbit, saltbits; | 330 | u_int32_t obit, saltbit, saltbits; |
@@ -342,7 +342,7 @@ _des_setup_salt(int32_t salt) | |||
342 | return saltbits; | 342 | return saltbits; |
343 | } | 343 | } |
344 | 344 | ||
345 | int | 345 | static int |
346 | des_setkey(const char *key) | 346 | des_setkey(const char *key) |
347 | { | 347 | { |
348 | u_int32_t k0, k1, rawkey0, rawkey1; | 348 | u_int32_t k0, k1, rawkey0, rawkey1; |
@@ -422,7 +422,7 @@ des_setkey(const char *key) | |||
422 | return(0); | 422 | return(0); |
423 | } | 423 | } |
424 | 424 | ||
425 | int | 425 | static int |
426 | _des_do_des(u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, | 426 | _des_do_des(u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, |
427 | int count, u_int32_t saltbits) | 427 | int count, u_int32_t saltbits) |
428 | { | 428 | { |
@@ -539,7 +539,7 @@ _des_do_des(u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, | |||
539 | return(0); | 539 | return(0); |
540 | } | 540 | } |
541 | 541 | ||
542 | int | 542 | static int |
543 | des_cipher(const char *in, char *out, int32_t salt, int count) | 543 | des_cipher(const char *in, char *out, int32_t salt, int count) |
544 | { | 544 | { |
545 | u_int32_t l_out, r_out, rawl, rawr, saltbits; | 545 | u_int32_t l_out, r_out, rawl, rawr, saltbits; |
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 | |||
59 | extern const u_char _des_bits8[8]; | ||
60 | extern const u_int32_t _des_bits32[32]; | ||
61 | extern int _des_initialised; | ||
62 | void _des_init(void); | ||
63 | u_int32_t _des_setup_salt(int32_t salt); | ||
64 | int _des_do_des(u_int32_t , u_int32_t , u_int32_t *, u_int32_t *, int, u_int32_t); | ||
65 | |||
66 | int | ||
67 | setkey(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 | |||
84 | int | ||
85 | encrypt(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 | } | ||