2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
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 *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A
2N/Avoid
2N/A_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)
2N/A{
2N/A/* EXPORT DELETE START */
2N/A int i, ii;
2N/A int t, j, k;
2N/A char t2;
2N/A
2N/A /*
2N/A * First, permute the bits in the input
2N/A */
2N/A for (j = 0; j < 64; j++)
2N/A L[j] = block[IP[j]-1];
2N/A /*
2N/A * Perform a decryption operation 16 times.
2N/A */
2N/A for (ii = 0; ii < 16; ii++) {
2N/A i = 15-ii;
2N/A /*
2N/A * Save the R array,
2N/A * which will be the new L.
2N/A */
2N/A for (j = 0; j < 32; j++)
2N/A tempL[j] = R[j];
2N/A /*
2N/A * Expand R to 48 bits using the E selector;
2N/A * exclusive-or with the current key bits.
2N/A */
2N/A for (j = 0; j < 48; j++)
2N/A preS[j] = R[E[j]-1] ^ KS[i][j];
2N/A /*
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 */
2N/A for (j = 0; j < 8; j++) {
2N/A t = 6*j;
2N/A k = S[j][(preS[t+0]<<5)+
2N/A (preS[t+1]<<3)+
2N/A (preS[t+2]<<2)+
2N/A (preS[t+3]<<1)+
2N/A (preS[t+4]<<0)+
2N/A (preS[t+5]<<4)];
2N/A t = 4*j;
2N/A f[t+0] = (k>>3)&01;
2N/A f[t+1] = (k>>2)&01;
2N/A f[t+2] = (k>>1)&01;
2N/A f[t+3] = (k>>0)&01;
2N/A }
2N/A /*
2N/A * The new R is L ^ f(R, K).
2N/A * The f here has to be permuted first, though.
2N/A */
2N/A for (j = 0; j < 32; j++)
2N/A R[j] = L[j] ^ f[P[j]-1];
2N/A /*
2N/A * Finally, the new L (the original R)
2N/A * is copied back.
2N/A */
2N/A for (j = 0; j < 32; j++)
2N/A L[j] = tempL[j];
2N/A }
2N/A /*
2N/A * The output L and R are reversed.
2N/A */
2N/A for (j = 0; j < 32; j++) {
2N/A t2 = L[j];
2N/A L[j] = R[j];
2N/A R[j] = t2;
2N/A }
2N/A /*
2N/A * The final output
2N/A * gets the inverse permutation of the very original.
2N/A */
2N/A for (j = 0; j < 64; j++)
2N/A block[j] = L[FP[j]-1];
2N/A/* EXPORT DELETE END */
2N/A}