des_encrypt.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A/* Copyright (c) 1988 AT&T */ 2N/A/* All Rights Reserved */ 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A char KS[][
48],
char S[][
64],
char *f,
char *
tempL,
char *P,
char *
FP)
2N/A/* EXPORT DELETE START */ 2N/A * First, permute the bits in the input 2N/A for (j = 0; j <
64; j++)
2N/A * Perform an encryption operation 16 times. 2N/A for (i = 0; i <
16; i++) {
2N/A * which will be the new L. 2N/A for (j = 0; j <
32; j++)
2N/A * Expand R to 48 bits using the E selector; 2N/A * exclusive-or with the current key bits. 2N/A for (j = 0; j <
48; j++)
2N/A * The pre-select bits are now considered 2N/A * in 8 groups of 6 bits each. 2N/A * The 8 selection functions map these 2N/A * 6-bit quantities into 4-bit quantities 2N/A * and the results permuted 2N/A * to make an f(R, K). 2N/A * The indexing into the selection functions 2N/A * is peculiar; it could be simplified by 2N/A * rewriting the tables. 2N/A for (j = 0; j <
8; j++) {
2N/A * The new R is L ^ f(R, K). 2N/A * The f here has to be permuted first, though. 2N/A for (j = 0; j <
32; j++)
2N/A R[j] = L[j] ^ f[P[j]-
1];
2N/A * Finally, the new L (the original R) 2N/A for (j = 0; j <
32; j++)
2N/A * The output L and R are reversed. 2N/A for (j = 0; j <
32; j++) {
2N/A * gets the inverse permutation of the very original. 2N/A for (j = 0; j <
64; j++)
2N/A/* EXPORT DELETE END */