xcrypt.c (7c478bd9) xcrypt.c (61961e0f)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *

--- 5 unchanged lines hidden (view full) ---

14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *

--- 5 unchanged lines hidden (view full) ---

14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
22/*
23/*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28/* All Rights Reserved */
29
30/*
31 * Portions of this source code were derived from Berkeley 4.3 BSD

--- 4 unchanged lines hidden (view full) ---

36
37/*
38 * xcrypt.c: Hex encryption/decryption and utility routines
39 */
40
41#include <stdio.h>
42#include <stdlib.h>
43#include <sys/types.h>
25 * Use is subject to license terms.
26 */
27
28/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29/* All Rights Reserved */
30
31/*
32 * Portions of this source code were derived from Berkeley 4.3 BSD

--- 4 unchanged lines hidden (view full) ---

37
38/*
39 * xcrypt.c: Hex encryption/decryption and utility routines
40 */
41
42#include <stdio.h>
43#include <stdlib.h>
44#include <sys/types.h>
44#include <rpc/trace.h>
45#include <rpc/rpc.h>
46#include <rpc/key_prot.h> /* for KEYCHECKSUMSIZE */
47#include <rpc/des_crypt.h>
48#include <string.h>
49#include <rpcsvc/nis_dhext.h>
50#include <md5.h>
51
52#define MD5HEXSIZE 32

--- 33 unchanged lines hidden (view full) ---

86{
87/* EXPORT DELETE START */
88 char key[8];
89 char ivec[8];
90 char *buf;
91 int err;
92 int len;
93
45#include <rpc/rpc.h>
46#include <rpc/key_prot.h> /* for KEYCHECKSUMSIZE */
47#include <rpc/des_crypt.h>
48#include <string.h>
49#include <rpcsvc/nis_dhext.h>
50#include <md5.h>
51
52#define MD5HEXSIZE 32

--- 33 unchanged lines hidden (view full) ---

86{
87/* EXPORT DELETE START */
88 char key[8];
89 char ivec[8];
90 char *buf;
91 int err;
92 int len;
93
94 trace1(TR_xencrypt, 0);
95 len = (int)strlen(secret) / 2;
94 len = (int)strlen(secret) / 2;
96 if (len > MAX_KEY_CRYPT_LEN) {
97 trace1(TR_xencrypt, 1);
95 if (len > MAX_KEY_CRYPT_LEN)
98 return (0);
96 return (0);
99 }
100 buf = malloc((unsigned)len);
101 (void) hex2bin(len, secret, buf);
102 (void) passwd2des(passwd, key);
103 (void) memset(ivec, 0, 8);
104
105 err = cbc_crypt(key, buf, len, DES_ENCRYPT | DES_HW, ivec);
106 if (DES_FAILED(err)) {
107 free(buf);
97 buf = malloc((unsigned)len);
98 (void) hex2bin(len, secret, buf);
99 (void) passwd2des(passwd, key);
100 (void) memset(ivec, 0, 8);
101
102 err = cbc_crypt(key, buf, len, DES_ENCRYPT | DES_HW, ivec);
103 if (DES_FAILED(err)) {
104 free(buf);
108 trace1(TR_xencrypt, 1);
109 return (0);
110 }
111 (void) bin2hex(len, (unsigned char *) buf, secret);
112 free(buf);
105 return (0);
106 }
107 (void) bin2hex(len, (unsigned char *) buf, secret);
108 free(buf);
113 trace1(TR_xencrypt, 1);
114 return (1);
115#if 0
116/* EXPORT DELETE END */
109 return (1);
110#if 0
111/* EXPORT DELETE END */
117 trace1(TR_xencrypt, 1);
118 return (0);
119/* EXPORT DELETE START */
120#endif
121/* EXPORT DELETE END */
122}
123
124/*
125 * Decrypt secret key using passwd

--- 7 unchanged lines hidden (view full) ---

133{
134/* EXPORT DELETE START */
135 char key[8];
136 char ivec[8];
137 char *buf;
138 int err;
139 int len;
140
112 return (0);
113/* EXPORT DELETE START */
114#endif
115/* EXPORT DELETE END */
116}
117
118/*
119 * Decrypt secret key using passwd

--- 7 unchanged lines hidden (view full) ---

127{
128/* EXPORT DELETE START */
129 char key[8];
130 char ivec[8];
131 char *buf;
132 int err;
133 int len;
134
141 trace1(TR_xdecrypt, 0);
142 len = (int)strlen(secret) / 2;
135 len = (int)strlen(secret) / 2;
143 if (len > MAX_KEY_CRYPT_LEN) {
144 trace1(TR_xdecrypt, 1);
136 if (len > MAX_KEY_CRYPT_LEN)
145 return (0);
137 return (0);
146 }
147 buf = malloc((unsigned)len);
148
149 (void) hex2bin(len, secret, buf);
150 (void) passwd2des(passwd, key);
151 (void) memset(ivec, 0, 8);
152
153 err = cbc_crypt(key, buf, len, DES_DECRYPT | DES_HW, ivec);
154 if (DES_FAILED(err)) {
155 free(buf);
138 buf = malloc((unsigned)len);
139
140 (void) hex2bin(len, secret, buf);
141 (void) passwd2des(passwd, key);
142 (void) memset(ivec, 0, 8);
143
144 err = cbc_crypt(key, buf, len, DES_DECRYPT | DES_HW, ivec);
145 if (DES_FAILED(err)) {
146 free(buf);
156 trace1(TR_xdecrypt, 1);
157 return (0);
158 }
159 (void) bin2hex(len, (unsigned char *) buf, secret);
160 free(buf);
147 return (0);
148 }
149 (void) bin2hex(len, (unsigned char *) buf, secret);
150 free(buf);
161 trace1(TR_xdecrypt, 1);
162 return (1);
163#if 0
164/* EXPORT DELETE END */
151 return (1);
152#if 0
153/* EXPORT DELETE END */
165 trace1(TR_xdecrypt, 1);
166 return (0);
167/* EXPORT DELETE START */
168#endif
169/* EXPORT DELETE END */
170}
171
172/*
173 * Turn password into DES key
174 */
175int
176passwd2des(pw, key)
177 char *pw;
178 char *key;
179{
180 int i;
181
154 return (0);
155/* EXPORT DELETE START */
156#endif
157/* EXPORT DELETE END */
158}
159
160/*
161 * Turn password into DES key
162 */
163int
164passwd2des(pw, key)
165 char *pw;
166 char *key;
167{
168 int i;
169
182 trace1(TR_passwd2des, 0);
183 (void) memset(key, 0, 8);
184 for (i = 0; *pw; i = (i+1) % 8) {
185 key[i] ^= *pw++ << 1;
186 }
187 des_setparity(key);
170 (void) memset(key, 0, 8);
171 for (i = 0; *pw; i = (i+1) % 8) {
172 key[i] ^= *pw++ << 1;
173 }
174 des_setparity(key);
188 trace1(TR_passwd2des, 1);
189 return (1);
190}
191
192
193/*
194 * Hex to binary conversion
195 */
196int
197hex2bin(len, hexnum, binnum)
198 int len;
199 char *hexnum;
200 char *binnum;
201{
202 int i;
203
175 return (1);
176}
177
178
179/*
180 * Hex to binary conversion
181 */
182int
183hex2bin(len, hexnum, binnum)
184 int len;
185 char *hexnum;
186 char *binnum;
187{
188 int i;
189
204 trace2(TR_hex2bin, 0, len);
205 for (i = 0; i < len; i++) {
206 *binnum++ = 16 * hexval(hexnum[2 * i]) +
207 hexval(hexnum[2 * i + 1]);
208 }
190 for (i = 0; i < len; i++) {
191 *binnum++ = 16 * hexval(hexnum[2 * i]) +
192 hexval(hexnum[2 * i + 1]);
193 }
209 trace1(TR_hex2bin, 1);
210 return (1);
211}
212
213/*
214 * Binary to hex conversion
215 */
216int
217bin2hex(len, binnum, hexnum)
218 int len;
219 unsigned char *binnum;
220 char *hexnum;
221{
222 int i;
223 unsigned val;
224
194 return (1);
195}
196
197/*
198 * Binary to hex conversion
199 */
200int
201bin2hex(len, binnum, hexnum)
202 int len;
203 unsigned char *binnum;
204 char *hexnum;
205{
206 int i;
207 unsigned val;
208
225 trace2(TR_bin2hex, 0, len);
226 for (i = 0; i < len; i++) {
227 val = binnum[i];
228 hexnum[i*2] = hex[val >> 4];
229 hexnum[i*2+1] = hex[val & 0xf];
230 }
231 hexnum[len*2] = 0;
209 for (i = 0; i < len; i++) {
210 val = binnum[i];
211 hexnum[i*2] = hex[val >> 4];
212 hexnum[i*2+1] = hex[val & 0xf];
213 }
214 hexnum[len*2] = 0;
232 trace1(TR_bin2hex, 1);
233 return (1);
234}
235
236static char hex[16] = {
237 '0', '1', '2', '3', '4', '5', '6', '7',
238 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
239};
240
241static char
242hexval(c)
243 char c;
244{
215 return (1);
216}
217
218static char hex[16] = {
219 '0', '1', '2', '3', '4', '5', '6', '7',
220 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
221};
222
223static char
224hexval(c)
225 char c;
226{
245 trace1(TR_hexval, 0);
246 if (c >= '0' && c <= '9') {
227 if (c >= '0' && c <= '9') {
247 trace1(TR_hexval, 1);
248 return (c - '0');
249 } else if (c >= 'a' && c <= 'z') {
228 return (c - '0');
229 } else if (c >= 'a' && c <= 'z') {
250 trace1(TR_hexval, 1);
251 return (c - 'a' + 10);
252 } else if (c >= 'A' && c <= 'Z') {
230 return (c - 'a' + 10);
231 } else if (c >= 'A' && c <= 'Z') {
253 trace1(TR_hexval, 1);
254 return (c - 'A' + 10);
255 } else {
232 return (c - 'A' + 10);
233 } else {
256 trace1(TR_hexval, 1);
257 return (-1);
258 }
259}
260
261/*
262 * Generic key length/algorithm version of xencrypt().
263 *
264 * Encrypt a secret key given passwd.

--- 30 unchanged lines hidden (view full) ---

295 const int hexkeybytes = BITS2NIBBLES(keylen);
296 const int keychecksumsize = classic_des ? KEYCHECKSUMSIZE : MD5HEXSIZE;
297 const int binkeybytes = do_chksum ? keylen/8 + keychecksumsize/2 :
298 keylen/8;
299 const int bufsize = do_chksum ? hexkeybytes + keychecksumsize + 1 :
300 hexkeybytes + 1;
301 char *hexkeybuf;
302
234 return (-1);
235 }
236}
237
238/*
239 * Generic key length/algorithm version of xencrypt().
240 *
241 * Encrypt a secret key given passwd.

--- 30 unchanged lines hidden (view full) ---

272 const int hexkeybytes = BITS2NIBBLES(keylen);
273 const int keychecksumsize = classic_des ? KEYCHECKSUMSIZE : MD5HEXSIZE;
274 const int binkeybytes = do_chksum ? keylen/8 + keychecksumsize/2 :
275 keylen/8;
276 const int bufsize = do_chksum ? hexkeybytes + keychecksumsize + 1 :
277 hexkeybytes + 1;
278 char *hexkeybuf;
279
303 trace1(TR_xencrypt_g, 0);
304
305 if (!secret || !keylen || !passwd || !encrypted_secret) {
306 trace1(TR_xencrypt_g, 1);
280 if (!secret || !keylen || !passwd || !encrypted_secret)
307 return (0);
281 return (0);
308 }
309
310 if ((hexkeybuf = malloc(bufsize)) == 0)
311 return (0);
312
313 (void) memcpy(hexkeybuf, secret, hexkeybytes);
314 if (do_chksum)
315 if (classic_des) {
316 (void) memcpy(hexkeybuf + hexkeybytes, secret,

--- 14 unchanged lines hidden (view full) ---

331 /* append the hex md5 string to the end of the key */
332 (void) memcpy(hexkeybuf + hexkeybytes,
333 (void *)md5hexbuf, MD5HEXSIZE);
334 }
335 hexkeybuf[bufsize - 1] = 0;
336
337 if (binkeybytes > MAX_KEY_CRYPT_LEN) {
338 free(hexkeybuf);
282
283 if ((hexkeybuf = malloc(bufsize)) == 0)
284 return (0);
285
286 (void) memcpy(hexkeybuf, secret, hexkeybytes);
287 if (do_chksum)
288 if (classic_des) {
289 (void) memcpy(hexkeybuf + hexkeybytes, secret,

--- 14 unchanged lines hidden (view full) ---

304 /* append the hex md5 string to the end of the key */
305 (void) memcpy(hexkeybuf + hexkeybytes,
306 (void *)md5hexbuf, MD5HEXSIZE);
307 }
308 hexkeybuf[bufsize - 1] = 0;
309
310 if (binkeybytes > MAX_KEY_CRYPT_LEN) {
311 free(hexkeybuf);
339 trace1(TR_xencrypt_g, 1);
340 return (0);
341 }
342 if ((binkeybuf = malloc((unsigned)binkeybytes)) == 0) {
343 free(hexkeybuf);
344 return (0);
345 }
346
347 (void) hex2bin(binkeybytes, hexkeybuf, binkeybuf);

--- 10 unchanged lines hidden (view full) ---

358
359 (void) memset(ivec, 0, 8);
360
361 err = cbc_crypt(key.c, binkeybuf, binkeybytes, DES_ENCRYPT | DES_HW,
362 ivec);
363 if (DES_FAILED(err)) {
364 free(hexkeybuf);
365 free(binkeybuf);
312 return (0);
313 }
314 if ((binkeybuf = malloc((unsigned)binkeybytes)) == 0) {
315 free(hexkeybuf);
316 return (0);
317 }
318
319 (void) hex2bin(binkeybytes, hexkeybuf, binkeybuf);

--- 10 unchanged lines hidden (view full) ---

330
331 (void) memset(ivec, 0, 8);
332
333 err = cbc_crypt(key.c, binkeybuf, binkeybytes, DES_ENCRYPT | DES_HW,
334 ivec);
335 if (DES_FAILED(err)) {
336 free(hexkeybuf);
337 free(binkeybuf);
366 trace1(TR_xencrypt_g, 1);
367 return (0);
368 }
369 (void) bin2hex(binkeybytes, (unsigned char *) binkeybuf, hexkeybuf);
370 free(binkeybuf);
371 *encrypted_secret = hexkeybuf;
338 return (0);
339 }
340 (void) bin2hex(binkeybytes, (unsigned char *) binkeybuf, hexkeybuf);
341 free(binkeybuf);
342 *encrypted_secret = hexkeybuf;
372 trace1(TR_xencrypt_g, 1);
373 return (1);
374#if 0
375/* EXPORT DELETE END */
343 return (1);
344#if 0
345/* EXPORT DELETE END */
376 trace1(TR_xencrypt_g, 1);
377 return (0);
378/* EXPORT DELETE START */
379#endif
380/* EXPORT DELETE END */
381}
382
383/*
384 * Generic key len and alg type for version of xdecrypt.

--- 25 unchanged lines hidden (view full) ---

410 char ivec[8];
411 char *buf;
412 int err;
413 int len;
414 const int classic_des = keylen == 192 && algtype == 0;
415 const int hexkeybytes = BITS2NIBBLES(keylen);
416 const int keychecksumsize = classic_des ? KEYCHECKSUMSIZE : MD5HEXSIZE;
417
346 return (0);
347/* EXPORT DELETE START */
348#endif
349/* EXPORT DELETE END */
350}
351
352/*
353 * Generic key len and alg type for version of xdecrypt.

--- 25 unchanged lines hidden (view full) ---

379 char ivec[8];
380 char *buf;
381 int err;
382 int len;
383 const int classic_des = keylen == 192 && algtype == 0;
384 const int hexkeybytes = BITS2NIBBLES(keylen);
385 const int keychecksumsize = classic_des ? KEYCHECKSUMSIZE : MD5HEXSIZE;
386
418 trace1(TR_xdecrypt_g, 0);
419 len = (int)strlen(secret) / 2;
387 len = (int)strlen(secret) / 2;
420 if (len > MAX_KEY_CRYPT_LEN) {
421 trace1(TR_xdecrypt_g, 1);
388 if (len > MAX_KEY_CRYPT_LEN)
422 return (0);
389 return (0);
423 }
424 if ((buf = malloc((unsigned)len)) == 0)
425 return (0);
426
427 (void) hex2bin(len, secret, buf);
428 if (classic_des)
429 (void) passwd2des((char *)passwd, key.c);
430 else
431 if (netname)
432 (void) passwd2des_g(passwd, netname,
433 (int)strlen(netname), &key, FALSE);
434 else {
435 free(buf);
390 if ((buf = malloc((unsigned)len)) == 0)
391 return (0);
392
393 (void) hex2bin(len, secret, buf);
394 if (classic_des)
395 (void) passwd2des((char *)passwd, key.c);
396 else
397 if (netname)
398 (void) passwd2des_g(passwd, netname,
399 (int)strlen(netname), &key, FALSE);
400 else {
401 free(buf);
436 trace1(TR_xdecrypt_g, 1);
437 return (0);
438 }
439 (void) memset(ivec, 0, 8);
440
441 err = cbc_crypt(key.c, buf, len, DES_DECRYPT | DES_HW, ivec);
442 if (DES_FAILED(err)) {
443 free(buf);
402 return (0);
403 }
404 (void) memset(ivec, 0, 8);
405
406 err = cbc_crypt(key.c, buf, len, DES_DECRYPT | DES_HW, ivec);
407 if (DES_FAILED(err)) {
408 free(buf);
444 trace1(TR_xdecrypt_g, 1);
445 return (0);
446 }
447 (void) bin2hex(len, (unsigned char *) buf, secret);
448 free(buf);
449
450 if (do_chksum)
451 if (classic_des) {
452 if (memcmp(secret, &(secret[hexkeybytes]),
453 keychecksumsize) != 0) {
454 secret[0] = 0;
409 return (0);
410 }
411 (void) bin2hex(len, (unsigned char *) buf, secret);
412 free(buf);
413
414 if (do_chksum)
415 if (classic_des) {
416 if (memcmp(secret, &(secret[hexkeybytes]),
417 keychecksumsize) != 0) {
418 secret[0] = 0;
455 trace1(TR_xdecrypt_g, 1);
456 return (0);
457 }
458 } else {
459 MD5_CTX md5_ctx;
460 char md5hexbuf[MD5HEXSIZE + 1] = {0};
461 uint8_t digest[MD5HEXSIZE/2];
462
463 MD5Init(&md5_ctx);
464 MD5Update(&md5_ctx, (unsigned char *)secret,
465 hexkeybytes);
466 MD5Final(digest, &md5_ctx);
467
468 /* convert md5 binary digest to hex */
469 (void) bin2hex(MD5HEXSIZE/2, digest, md5hexbuf);
470
471 /* does the digest match the appended one? */
472 if (memcmp(&(secret[hexkeybytes]),
419 return (0);
420 }
421 } else {
422 MD5_CTX md5_ctx;
423 char md5hexbuf[MD5HEXSIZE + 1] = {0};
424 uint8_t digest[MD5HEXSIZE/2];
425
426 MD5Init(&md5_ctx);
427 MD5Update(&md5_ctx, (unsigned char *)secret,
428 hexkeybytes);
429 MD5Final(digest, &md5_ctx);
430
431 /* convert md5 binary digest to hex */
432 (void) bin2hex(MD5HEXSIZE/2, digest, md5hexbuf);
433
434 /* does the digest match the appended one? */
435 if (memcmp(&(secret[hexkeybytes]),
473 (void *)md5hexbuf, MD5HEXSIZE) != 0) {
436 md5hexbuf, MD5HEXSIZE) != 0) {
474 secret[0] = 0;
437 secret[0] = 0;
475 trace1(TR_xdecrypt_g, 1);
476 return (0);
477 }
478 }
479
480 secret[hexkeybytes] = '\0';
481
438 return (0);
439 }
440 }
441
442 secret[hexkeybytes] = '\0';
443
482 trace1(TR_xdecrypt_g, 1);
483 return (1);
484#if 0
485/* EXPORT DELETE END */
444 return (1);
445#if 0
446/* EXPORT DELETE END */
486 trace1(TR_xdecrypt_g, 1);
487 return (0);
488/* EXPORT DELETE START */
489#endif
490/* EXPORT DELETE END */
491}
492
493
494/*

--- 13 unchanged lines hidden (view full) ---

508 bool_t altalg)
509{
510
511 int i, j, incr = 1;
512 des_block ivec, tkey;
513 char *text;
514 int plen, tlen;
515
447 return (0);
448/* EXPORT DELETE START */
449#endif
450/* EXPORT DELETE END */
451}
452
453
454/*

--- 13 unchanged lines hidden (view full) ---

468 bool_t altalg)
469{
470
471 int i, j, incr = 1;
472 des_block ivec, tkey;
473 char *text;
474 int plen, tlen;
475
516 trace1(TR_passwd2des, 0);
517 (void) memset(tkey.c, 0, 8);
518 (void) memset(ivec.c, 0, 8);
519
520
521/*
522 * Concatentate the password and the mix-in string, fan-fold and XOR them
523 * to the required eight byte initial DES key. Since passwords can be
524 * expected to use mostly seven bit ASCII, left shift the password one
525 * bit in order to preserve as much key space as possible.
526 */
527
528#define KEYLEN sizeof (tkey.c)
529 plen = strlen(pw);
530 tlen = ((plen + len + (KEYLEN-1))/KEYLEN)*KEYLEN;
476 (void) memset(tkey.c, 0, 8);
477 (void) memset(ivec.c, 0, 8);
478
479
480/*
481 * Concatentate the password and the mix-in string, fan-fold and XOR them
482 * to the required eight byte initial DES key. Since passwords can be
483 * expected to use mostly seven bit ASCII, left shift the password one
484 * bit in order to preserve as much key space as possible.
485 */
486
487#define KEYLEN sizeof (tkey.c)
488 plen = strlen(pw);
489 tlen = ((plen + len + (KEYLEN-1))/KEYLEN)*KEYLEN;
531 if ((text = (char *)malloc(tlen)) == NULL) {
490 if ((text = malloc(tlen)) == NULL) {
532 return (0);
533 }
534
535 (void) memset(text, 0, tlen);
536
491 return (0);
492 }
493
494 (void) memset(text, 0, tlen);
495
537 if (! altalg) {
496 if (!altalg) {
538
539/*
540 * Concatenate the password and the mix-in string, fan-fold and XOR them
541 * to the required eight byte initial DES key. Since passwords can be
542 * expected to use mostly seven bit ASCII, left shift the password one
543 * bit in order to preserve as much key space as possible.
544 */
545 (void) memcpy(text, pw, plen);

--- 65 unchanged lines hidden (view full) ---

611 /*
612 * XORing with 0xf0 preserves parity, so no need to check
613 * that again.
614 */
615 }
616
617 (void) memcpy((*key).c, ivec.c, sizeof (ivec.c));
618
497
498/*
499 * Concatenate the password and the mix-in string, fan-fold and XOR them
500 * to the required eight byte initial DES key. Since passwords can be
501 * expected to use mostly seven bit ASCII, left shift the password one
502 * bit in order to preserve as much key space as possible.
503 */
504 (void) memcpy(text, pw, plen);

--- 65 unchanged lines hidden (view full) ---

570 /*
571 * XORing with 0xf0 preserves parity, so no need to check
572 * that again.
573 */
574 }
575
576 (void) memcpy((*key).c, ivec.c, sizeof (ivec.c));
577
619 trace1(TR_passwd2des_g, 1);
620 return (1);
621
622}
623
624struct DESkey {
625 uint32_t h1;
626 uint32_t h2;
627};

--- 23 unchanged lines hidden (view full) ---

651 {0xfee0fee0, 0xfef1fef1}
652};
653
654static int
655weak_DES_key(des_block db)
656{
657 int i;
658
578 return (1);
579
580}
581
582struct DESkey {
583 uint32_t h1;
584 uint32_t h2;
585};

--- 23 unchanged lines hidden (view full) ---

609 {0xfee0fee0, 0xfef1fef1}
610};
611
612static int
613weak_DES_key(des_block db)
614{
615 int i;
616
659 trace1(TR_weak_DES_key, 0);
660 for (i = 0; i < sizeof (weakDESkeys)/sizeof (struct DESkey); i++) {
661 if (weakDESkeys[i].h1 == db.key.high &&
617 for (i = 0; i < sizeof (weakDESkeys)/sizeof (struct DESkey); i++) {
618 if (weakDESkeys[i].h1 == db.key.high &&
662 weakDESkeys[i].h2 == db.key.low) {
663 trace1(TR_weak_DES_key, 1);
619 weakDESkeys[i].h2 == db.key.low)
664 return (1);
620 return (1);
665 }
666 }
667
621 }
622
668 trace1(TR_weak_DES_key, 1);
669 return (0);
670}
623 return (0);
624}