des_soft.c revision 258578
1185377Ssam/*- 2187831Ssam * Copyright (c) 2009, Sun Microsystems, Inc. 3185377Ssam * All rights reserved. 4185377Ssam * 5185377Ssam * Redistribution and use in source and binary forms, with or without 6185377Ssam * modification, are permitted provided that the following conditions are met: 7185377Ssam * - Redistributions of source code must retain the above copyright notice, 8185377Ssam * this list of conditions and the following disclaimer. 9185377Ssam * - Redistributions in binary form must reproduce the above copyright notice, 10185377Ssam * this list of conditions and the following disclaimer in the documentation 11185377Ssam * and/or other materials provided with the distribution. 12185377Ssam * - Neither the name of Sun Microsystems, Inc. nor the names of its 13185377Ssam * contributors may be used to endorse or promote products derived 14185377Ssam * from this software without specific prior written permission. 15185377Ssam * 16185377Ssam * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17185377Ssam * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18187345Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19185377Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20185377Ssam * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21185377Ssam * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22185377Ssam * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23187831Ssam * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24187831Ssam * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25187831Ssam * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26187831Ssam * POSSIBILITY OF SUCH DAMAGE. 27185377Ssam */ 28185377Ssam 29185377Ssam#if defined(LIBC_SCCS) && !defined(lint) 30185377Ssamstatic char sccsid[] = "@(#)des_soft.c 2.2 88/08/10 4.0 RPCSRC; from 1.13 88/02/08 SMI"; 31185377Ssam#endif 32185377Ssam#include <sys/cdefs.h> 33185377Ssam__FBSDID("$FreeBSD: head/lib/libc/rpc/des_soft.c 258578 2013-11-25 19:04:36Z hrs $"); 34185377Ssam 35185377Ssam/* 36185377Ssam * Table giving odd parity in the low bit for ASCII characters 37185377Ssam */ 38185377Ssamstatic char partab[128] = { 39185377Ssam 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x07, 0x07, 40185377Ssam 0x08, 0x08, 0x0b, 0x0b, 0x0d, 0x0d, 0x0e, 0x0e, 41185377Ssam 0x10, 0x10, 0x13, 0x13, 0x15, 0x15, 0x16, 0x16, 42185380Ssam 0x19, 0x19, 0x1a, 0x1a, 0x1c, 0x1c, 0x1f, 0x1f, 43185380Ssam 0x20, 0x20, 0x23, 0x23, 0x25, 0x25, 0x26, 0x26, 44185380Ssam 0x29, 0x29, 0x2a, 0x2a, 0x2c, 0x2c, 0x2f, 0x2f, 45185380Ssam 0x31, 0x31, 0x32, 0x32, 0x34, 0x34, 0x37, 0x37, 46185377Ssam 0x38, 0x38, 0x3b, 0x3b, 0x3d, 0x3d, 0x3e, 0x3e, 47185380Ssam 0x40, 0x40, 0x43, 0x43, 0x45, 0x45, 0x46, 0x46, 48185380Ssam 0x49, 0x49, 0x4a, 0x4a, 0x4c, 0x4c, 0x4f, 0x4f, 49185377Ssam 0x51, 0x51, 0x52, 0x52, 0x54, 0x54, 0x57, 0x57, 50185380Ssam 0x58, 0x58, 0x5b, 0x5b, 0x5d, 0x5d, 0x5e, 0x5e, 51185380Ssam 0x61, 0x61, 0x62, 0x62, 0x64, 0x64, 0x67, 0x67, 52185380Ssam 0x68, 0x68, 0x6b, 0x6b, 0x6d, 0x6d, 0x6e, 0x6e, 53185380Ssam 0x70, 0x70, 0x73, 0x73, 0x75, 0x75, 0x76, 0x76, 54185380Ssam 0x79, 0x79, 0x7a, 0x7a, 0x7c, 0x7c, 0x7f, 0x7f, 55185380Ssam}; 56185380Ssam 57185380Ssam/* 58185380Ssam * Add odd parity to low bit of 8 byte key 59185380Ssam */ 60185380Ssamvoid 61185380Ssamdes_setparity(p) 62185380Ssam char *p; 63185380Ssam{ 64185380Ssam int i; 65185380Ssam 66185380Ssam for (i = 0; i < 8; i++) { 67185380Ssam *p = partab[*p & 0x7f]; 68185380Ssam p++; 69185380Ssam } 70185380Ssam} 71185380Ssam