Merge from vendor branch GCC:
[dragonfly.git] / sys / crypto / cast128 / cast128_subkey.h
1 /*      $FreeBSD: src/sys/crypto/cast128/cast128_subkey.h,v 1.1.2.1 2000/07/15 07:14:21 kris Exp $      */
2 /*      $DragonFly: src/sys/crypto/cast128/cast128_subkey.h,v 1.2 2003/06/17 04:28:20 dillon Exp $      */
3 /*      $KAME: cast128_subkey.h,v 1.3 2000/03/27 04:36:30 sumikawa Exp $        */
4
5 /*
6  * heavily modified by Tomomi Suzuki <suzuki@grelot.elec.ryukoku.ac.jp>
7  */
8 /*
9  * The CAST-128 Encryption Algorithm (RFC 2144)
10  *
11  * original implementation <Hideo "Sir MaNMOS" Morisita>
12  * 1997/08/21
13  */
14 /*
15  * Copyright (C) 1997 Hideo "Sir MANMOS" Morishita
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
21  * 1. Redistributions of source code must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must reproduce the above copyright
24  *    notice, this list of conditions and the following disclaimer in the
25  *    documentation and/or other materials provided with the distribution.
26  *
27  * THIS SOFTWARE IS PROVIDED BY Hideo "Sir MaNMOS" Morishita ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL Hideo "Sir MaNMOS" Morishita BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  */
39
40 #ifndef RFC2144_CAST_128_SUBKEY_H
41 #define RFC2144_CAST_128_SUBKEY_H
42
43 #define x0x1x2x3 buf[0]
44 #define x4x5x6x7 buf[1]
45 #define x8x9xAxB buf[2]
46 #define xCxDxExF buf[3]
47 #define z0z1z2z3 buf[4]
48 #define z4z5z6z7 buf[5]
49 #define z8z9zAzB buf[6]
50 #define zCzDzEzF buf[7]
51
52 #define byte0(x) (((x) >> 24))
53 #define byte1(x) (((x) >> 16) & 0xff)
54 #define byte2(x) (((x) >> 8) & 0xff)
55 #define byte3(x) (((x)) & 0xff)
56
57 #define x0 byte0(buf[0])
58 #define x1 byte1(buf[0])
59 #define x2 byte2(buf[0])
60 #define x3 byte3(buf[0])
61 #define x4 byte0(buf[1])
62 #define x5 byte1(buf[1])
63 #define x6 byte2(buf[1])
64 #define x7 byte3(buf[1])
65 #define x8 byte0(buf[2])
66 #define x9 byte1(buf[2])
67 #define xA byte2(buf[2])
68 #define xB byte3(buf[2])
69 #define xC byte0(buf[3])
70 #define xD byte1(buf[3])
71 #define xE byte2(buf[3])
72 #define xF byte3(buf[3])
73 #define z0 byte0(buf[4])
74 #define z1 byte1(buf[4])
75 #define z2 byte2(buf[4])
76 #define z3 byte3(buf[4])
77 #define z4 byte0(buf[5])
78 #define z5 byte1(buf[5])
79 #define z6 byte2(buf[5])
80 #define z7 byte3(buf[5])
81 #define z8 byte0(buf[6])
82 #define z9 byte1(buf[6])
83 #define zA byte2(buf[6])
84 #define zB byte3(buf[6])
85 #define zC byte0(buf[7])
86 #define zD byte1(buf[7])
87 #define zE byte2(buf[7])
88 #define zF byte3(buf[7])
89
90 #define circular_leftshift(x, y) ( ((x) << (y)) | ((x) >> (32-(y))) )
91
92 #endif
93