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) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * Portions of this source code were derived from Berkeley 4.3 BSD 2N/A * under license from the Regents of the University of California. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * Warning! Things are arranged very carefully in this file to 2N/A * allow read-only data to be moved to the text segment. The 2N/A * various DES tables must appear before any function definitions 2N/A * (this is arranged by including them immediately below) and partab 2N/A * must also appear before and function definitions 2N/A * This arrangement allows all data up through the first text to 2N/A#
define CRYPT /* cannot configure out of user-level code */ 2N/A * Fast (?) software implementation of DES 2N/A * Works on a VAX too. 2N/A * Won't work without 8 bit chars and 32 bit longs 2N/A#
define btst(k, b) (k[b >>
3] & (
0x80 >> (b & 0
7)))
2N/A#
endif /* def CRYPT */ 2N/A * Table giving odd parity in the low bit for ASCII characters 2N/A 0x01,
0x01,
0x02,
0x02,
0x04,
0x04,
0x07,
0x07,
2N/A 0x08,
0x08,
0x0b,
0x0b,
0x0d,
0x0d,
0x0e,
0x0e,
2N/A 0x10,
0x10,
0x13,
0x13,
0x15,
0x15,
0x16,
0x16,
2N/A 0x19,
0x19,
0x1a,
0x1a,
0x1c,
0x1c,
0x1f,
0x1f,
2N/A 0x20,
0x20,
0x23,
0x23,
0x25,
0x25,
0x26,
0x26,
2N/A 0x29,
0x29,
0x2a,
0x2a,
0x2c,
0x2c,
0x2f,
0x2f,
2N/A 0x31,
0x31,
0x32,
0x32,
0x34,
0x34,
0x37,
0x37,
2N/A 0x38,
0x38,
0x3b,
0x3b,
0x3d,
0x3d,
0x3e,
0x3e,
2N/A 0x40,
0x40,
0x43,
0x43,
0x45,
0x45,
0x46,
0x46,
2N/A 0x49,
0x49,
0x4a,
0x4a,
0x4c,
0x4c,
0x4f,
0x4f,
2N/A 0x51,
0x51,
0x52,
0x52,
0x54,
0x54,
0x57,
0x57,
2N/A 0x58,
0x58,
0x5b,
0x5b,
0x5d,
0x5d,
0x5e,
0x5e,
2N/A 0x61,
0x61,
0x62,
0x62,
0x64,
0x64,
0x67,
0x67,
2N/A 0x68,
0x68,
0x6b,
0x6b,
0x6d,
0x6d,
0x6e,
0x6e,
2N/A 0x70,
0x70,
0x73,
0x73,
0x75,
0x75,
0x76,
0x76,
2N/A 0x79,
0x79,
0x7a,
0x7a,
0x7c,
0x7c,
0x7f,
0x7f,
2N/A * Add odd parity to low bit of 8 byte key 2N/A for (i = 0; i <
8; i++) {
2N/A#
endif /* def _KERNEL */ 2N/A * Software encrypt or decrypt a block of data (multiple of 8 bytes) 2N/A * Do the CBC ourselves if needed. 2N/A/* EXPORT DELETE START */ 2N/A for (i = 0; i <
8; i++)
2N/A for (i = 0; i <
8; i++)
2N/A for (i = 0; i <
8; i++)
2N/A for (i = 0; i <
8; i++) {
2N/A/* EXPORT DELETE END */ 2N/A * Set the key and direction for an encryption operation 2N/A * We build the 16 key entries here 2N/A/* EXPORT DELETE START */ 2N/A * First, generate C and D by permuting 2N/A * the key. The low order bit of each 2N/A * 8-bit char is not used, so C and D are only 28 2N/A for (i = 0; i <
28; i++) {
2N/A * To generate Ki, rotate C and D according 2N/A * to schedule and pick up a permutation 2N/A for (i = 0; i <
16; i++) {
2N/A * Do the "left shift" (rotate) 2N/A * We know we always rotate by either 1 or 2 bits 2N/A * the shifts table tells us if its 2 2N/A * get Ki. Note C and D are concatenated. 2N/A for (j = 0; j <
4; j++) {
2N/A for (k = 0; k <
6; k++) {
2N/A/* EXPORT DELETE END */ 2N/A * Do an encryption operation 2N/A * Much pain is taken (with preprocessor) to avoid loops so the compiler 2N/A * can do address arithmetic instead of doing it at runtime. 2N/A * Note that the byte-to-chunk conversion is necessary to guarantee 2N/A * processor byte-order independence. 2N/A/* EXPORT DELETE START */ 2N/A * Initial permutation 2N/A * and byte to chunk conversion 2N/A * Expand 8 bits of 32 bit R to 48 bit R 2N/A * Inner part of the algorithm: 2N/A * Expand R from 32 to 48 bits; xor key value; 2N/A * apply S boxes; permute 32 bits of output 2N/A * Apply inner part; do xor and exchange of 32 bit parts 2N/A * Apply the 16 ciphering steps 2N/A * and chunk to byte conversion 2N/A/* EXPORT DELETE END */ 2N/A#
endif /* def CRYPT */