Print this page
first pass
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libcrypt/common/des_decrypt.c
+++ new/usr/src/lib/libcrypt/common/des_decrypt.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /* Copyright (c) 1988 AT&T */
23 23 /* All Rights Reserved */
24 24
25 25
26 26 /*
27 27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
29 29 */
30 30
31 31 #pragma ident "%Z%%M% %I% %E% SMI"
32 32 /*LINTLIBRARY*/
33 33
34 34 #include <sys/types.h>
35 35
36 36 void
37 37 _des_decrypt1(char *block, char *L, char *IP, char *R, char *preS, char *E, char KS[][48], char S[][64], char *f, char *tempL, char *P, char *FP)
38 38 {
39 -/* EXPORT DELETE START */
40 39 int i, ii;
41 40 int t, j, k;
42 41 char t2;
43 42
44 43 /*
45 44 * First, permute the bits in the input
46 45 */
47 46 for (j = 0; j < 64; j++)
48 47 L[j] = block[IP[j]-1];
49 48 /*
50 49 * Perform a decryption operation 16 times.
51 50 */
52 51 for (ii = 0; ii < 16; ii++) {
53 52 i = 15-ii;
54 53 /*
55 54 * Save the R array,
56 55 * which will be the new L.
57 56 */
58 57 for (j = 0; j < 32; j++)
59 58 tempL[j] = R[j];
60 59 /*
61 60 * Expand R to 48 bits using the E selector;
62 61 * exclusive-or with the current key bits.
63 62 */
64 63 for (j = 0; j < 48; j++)
65 64 preS[j] = R[E[j]-1] ^ KS[i][j];
66 65 /*
67 66 * The pre-select bits are now considered
68 67 * in 8 groups of 6 bits each.
69 68 * The 8 selection functions map these
70 69 * 6-bit quantities into 4-bit quantities
71 70 * and the results permuted
72 71 * to make an f(R, K).
73 72 * The indexing into the selection functions
74 73 * is peculiar; it could be simplified by
75 74 * rewriting the tables.
76 75 */
77 76 for (j = 0; j < 8; j++) {
78 77 t = 6*j;
79 78 k = S[j][(preS[t+0]<<5)+
80 79 (preS[t+1]<<3)+
81 80 (preS[t+2]<<2)+
82 81 (preS[t+3]<<1)+
83 82 (preS[t+4]<<0)+
84 83 (preS[t+5]<<4)];
85 84 t = 4*j;
86 85 f[t+0] = (k>>3)&01;
87 86 f[t+1] = (k>>2)&01;
88 87 f[t+2] = (k>>1)&01;
89 88 f[t+3] = (k>>0)&01;
90 89 }
91 90 /*
92 91 * The new R is L ^ f(R, K).
93 92 * The f here has to be permuted first, though.
94 93 */
95 94 for (j = 0; j < 32; j++)
96 95 R[j] = L[j] ^ f[P[j]-1];
97 96 /*
98 97 * Finally, the new L (the original R)
99 98 * is copied back.
100 99 */
101 100 for (j = 0; j < 32; j++)
102 101 L[j] = tempL[j];
103 102 }
104 103 /*
105 104 * The output L and R are reversed.
106 105 */
107 106 for (j = 0; j < 32; j++) {
↓ open down ↓ |
58 lines elided |
↑ open up ↑ |
108 107 t2 = L[j];
109 108 L[j] = R[j];
110 109 R[j] = t2;
111 110 }
112 111 /*
113 112 * The final output
114 113 * gets the inverse permutation of the very original.
115 114 */
116 115 for (j = 0; j < 64; j++)
117 116 block[j] = L[FP[j]-1];
118 -/* EXPORT DELETE END */
119 117 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX