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
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
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]
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
33 #include <sys/types.h>
36 _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
)
43 * First, permute the bits in the input
45 for (j
= 0; j
< 64; j
++)
46 L
[j
] = block
[IP
[j
]-1];
48 * Perform a decryption operation 16 times.
50 for (ii
= 0; ii
< 16; ii
++) {
54 * which will be the new L.
56 for (j
= 0; j
< 32; j
++)
59 * Expand R to 48 bits using the E selector;
60 * exclusive-or with the current key bits.
62 for (j
= 0; j
< 48; j
++)
63 preS
[j
] = R
[E
[j
]-1] ^ KS
[i
][j
];
65 * The pre-select bits are now considered
66 * in 8 groups of 6 bits each.
67 * The 8 selection functions map these
68 * 6-bit quantities into 4-bit quantities
69 * and the results permuted
71 * The indexing into the selection functions
72 * is peculiar; it could be simplified by
73 * rewriting the tables.
75 for (j
= 0; j
< 8; j
++) {
77 k
= S
[j
][(preS
[t
+0]<<5)+
90 * The new R is L ^ f(R, K).
91 * The f here has to be permuted first, though.
93 for (j
= 0; j
< 32; j
++)
94 R
[j
] = L
[j
] ^ f
[P
[j
]-1];
96 * Finally, the new L (the original R)
99 for (j
= 0; j
< 32; j
++)
103 * The output L and R are reversed.
105 for (j
= 0; j
< 32; j
++) {
112 * gets the inverse permutation of the very original.
114 for (j
= 0; j
< 64; j
++)
115 block
[j
] = L
[FP
[j
]-1];