xref: /freebsd/lib/libc/rpc/des_soft.c (revision 8a16b7a18f5d0b031f09832fd7752fba717e2a97)
12e322d37SHiroki Sato /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
42e322d37SHiroki Sato  * Copyright (c) 2009, Sun Microsystems, Inc.
52e322d37SHiroki Sato  * All rights reserved.
6e8636dfdSBill Paul  *
72e322d37SHiroki Sato  * Redistribution and use in source and binary forms, with or without
82e322d37SHiroki Sato  * modification, are permitted provided that the following conditions are met:
92e322d37SHiroki Sato  * - Redistributions of source code must retain the above copyright notice,
102e322d37SHiroki Sato  *   this list of conditions and the following disclaimer.
112e322d37SHiroki Sato  * - Redistributions in binary form must reproduce the above copyright notice,
122e322d37SHiroki Sato  *   this list of conditions and the following disclaimer in the documentation
132e322d37SHiroki Sato  *   and/or other materials provided with the distribution.
142e322d37SHiroki Sato  * - Neither the name of Sun Microsystems, Inc. nor the names of its
152e322d37SHiroki Sato  *   contributors may be used to endorse or promote products derived
162e322d37SHiroki Sato  *   from this software without specific prior written permission.
17e8636dfdSBill Paul  *
182e322d37SHiroki Sato  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
192e322d37SHiroki Sato  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202e322d37SHiroki Sato  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212e322d37SHiroki Sato  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
222e322d37SHiroki Sato  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
232e322d37SHiroki Sato  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
242e322d37SHiroki Sato  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
252e322d37SHiroki Sato  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
262e322d37SHiroki Sato  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
272e322d37SHiroki Sato  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
282e322d37SHiroki Sato  * POSSIBILITY OF SUCH DAMAGE.
29e8636dfdSBill Paul  */
30a986ef57SDavid E. O'Brien 
31a986ef57SDavid E. O'Brien #if defined(LIBC_SCCS) && !defined(lint)
32a986ef57SDavid E. O'Brien static char sccsid[] = "@(#)des_soft.c	2.2 88/08/10 4.0 RPCSRC; from 1.13 88/02/08 SMI";
33a986ef57SDavid E. O'Brien #endif
34a986ef57SDavid E. O'Brien #include <sys/cdefs.h>
35a986ef57SDavid E. O'Brien __FBSDID("$FreeBSD$");
36a986ef57SDavid E. O'Brien 
37e8636dfdSBill Paul /*
38e8636dfdSBill Paul  * Table giving odd parity in the low bit for ASCII characters
39e8636dfdSBill Paul  */
40e8636dfdSBill Paul static char partab[128] = {
41e8636dfdSBill Paul 	0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x07, 0x07,
42e8636dfdSBill Paul 	0x08, 0x08, 0x0b, 0x0b, 0x0d, 0x0d, 0x0e, 0x0e,
43e8636dfdSBill Paul 	0x10, 0x10, 0x13, 0x13, 0x15, 0x15, 0x16, 0x16,
44e8636dfdSBill Paul 	0x19, 0x19, 0x1a, 0x1a, 0x1c, 0x1c, 0x1f, 0x1f,
45e8636dfdSBill Paul 	0x20, 0x20, 0x23, 0x23, 0x25, 0x25, 0x26, 0x26,
46e8636dfdSBill Paul 	0x29, 0x29, 0x2a, 0x2a, 0x2c, 0x2c, 0x2f, 0x2f,
47e8636dfdSBill Paul 	0x31, 0x31, 0x32, 0x32, 0x34, 0x34, 0x37, 0x37,
48e8636dfdSBill Paul 	0x38, 0x38, 0x3b, 0x3b, 0x3d, 0x3d, 0x3e, 0x3e,
49e8636dfdSBill Paul 	0x40, 0x40, 0x43, 0x43, 0x45, 0x45, 0x46, 0x46,
50e8636dfdSBill Paul 	0x49, 0x49, 0x4a, 0x4a, 0x4c, 0x4c, 0x4f, 0x4f,
51e8636dfdSBill Paul 	0x51, 0x51, 0x52, 0x52, 0x54, 0x54, 0x57, 0x57,
52e8636dfdSBill Paul 	0x58, 0x58, 0x5b, 0x5b, 0x5d, 0x5d, 0x5e, 0x5e,
53e8636dfdSBill Paul 	0x61, 0x61, 0x62, 0x62, 0x64, 0x64, 0x67, 0x67,
54e8636dfdSBill Paul 	0x68, 0x68, 0x6b, 0x6b, 0x6d, 0x6d, 0x6e, 0x6e,
55e8636dfdSBill Paul 	0x70, 0x70, 0x73, 0x73, 0x75, 0x75, 0x76, 0x76,
56e8636dfdSBill Paul 	0x79, 0x79, 0x7a, 0x7a, 0x7c, 0x7c, 0x7f, 0x7f,
57e8636dfdSBill Paul };
58e8636dfdSBill Paul 
59e8636dfdSBill Paul /*
60e8636dfdSBill Paul  * Add odd parity to low bit of 8 byte key
61e8636dfdSBill Paul  */
62e8636dfdSBill Paul void
6368895e38SCraig Rodrigues des_setparity(char *p)
64e8636dfdSBill Paul {
65e8636dfdSBill Paul 	int i;
66e8636dfdSBill Paul 
67e8636dfdSBill Paul 	for (i = 0; i < 8; i++) {
68e8636dfdSBill Paul 		*p = partab[*p & 0x7f];
69e8636dfdSBill Paul 		p++;
70e8636dfdSBill Paul 	}
71e8636dfdSBill Paul }
72