xref: /dragonfly/lib/libc/rpc/des_soft.c (revision 67640b13)
1 
2 /*-
3  * Copyright (c) 2009, Sun Microsystems, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * - Redistributions of source code must retain the above copyright notice,
9  *   this list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright notice,
11  *   this list of conditions and the following disclaimer in the documentation
12  *   and/or other materials provided with the distribution.
13  * - Neither the name of Sun Microsystems, Inc. nor the names of its
14  *   contributors may be used to endorse or promote products derived
15  *   from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $DragonFly: src/lib/libc/rpc/des_soft.c,v 1.2 2005/11/13 12:27:04 swildner Exp $
30  */
31 /*
32  * Table giving odd parity in the low bit for ASCII characters
33  */
34 static char partab[128] = {
35 	0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x07, 0x07,
36 	0x08, 0x08, 0x0b, 0x0b, 0x0d, 0x0d, 0x0e, 0x0e,
37 	0x10, 0x10, 0x13, 0x13, 0x15, 0x15, 0x16, 0x16,
38 	0x19, 0x19, 0x1a, 0x1a, 0x1c, 0x1c, 0x1f, 0x1f,
39 	0x20, 0x20, 0x23, 0x23, 0x25, 0x25, 0x26, 0x26,
40 	0x29, 0x29, 0x2a, 0x2a, 0x2c, 0x2c, 0x2f, 0x2f,
41 	0x31, 0x31, 0x32, 0x32, 0x34, 0x34, 0x37, 0x37,
42 	0x38, 0x38, 0x3b, 0x3b, 0x3d, 0x3d, 0x3e, 0x3e,
43 	0x40, 0x40, 0x43, 0x43, 0x45, 0x45, 0x46, 0x46,
44 	0x49, 0x49, 0x4a, 0x4a, 0x4c, 0x4c, 0x4f, 0x4f,
45 	0x51, 0x51, 0x52, 0x52, 0x54, 0x54, 0x57, 0x57,
46 	0x58, 0x58, 0x5b, 0x5b, 0x5d, 0x5d, 0x5e, 0x5e,
47 	0x61, 0x61, 0x62, 0x62, 0x64, 0x64, 0x67, 0x67,
48 	0x68, 0x68, 0x6b, 0x6b, 0x6d, 0x6d, 0x6e, 0x6e,
49 	0x70, 0x70, 0x73, 0x73, 0x75, 0x75, 0x76, 0x76,
50 	0x79, 0x79, 0x7a, 0x7a, 0x7c, 0x7c, 0x7f, 0x7f,
51 };
52 
53 /*
54  * Add odd parity to low bit of 8 byte key
55  */
56 void
57 des_setparity(char *p)
58 {
59 	int i;
60 
61 	for (i = 0; i < 8; i++) {
62 		*p = partab[*p & 0x7f];
63 		p++;
64 	}
65 }
66