5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1999 - 2006 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
23 /* General definitions for algorithms */
24 typedef unsigned char u1byte;
25 typedef SilcUInt32 u4byte;
26 typedef SilcUInt32 u32;
27 typedef SilcUInt32 uint_32t;
28 typedef SilcUInt8 uint_8t;
30 #define rotr(x, nr) (((x) >> ((int)(nr))) | ((x) << (32 - (int)(nr))))
31 #define rotl(x, nr) (((x) << ((int)(nr))) | ((x) >> (32 - (int)(nr))))
32 #define byte(x, nr) ((x) >> (nr * 8) & 255)
34 /* Byte key to words */
35 #define SILC_GET_WORD_KEY(s, d, len) \
38 for (_i = 0; _i < (len / 8) / 4; _i++) \
39 SILC_GET32_LSB(d[_i], s + (_i * 4)); \
42 /* CBC mode macros. */
44 #define SILC_CBC_GET_IV(d, s) \
46 SILC_GET32_LSB(d[0], &s[0]); \
47 SILC_GET32_LSB(d[1], &s[4]); \
48 SILC_GET32_LSB(d[2], &s[8]); \
49 SILC_GET32_LSB(d[3], &s[12]); \
52 #define SILC_CBC_PUT_IV(s, d) \
54 SILC_PUT32_LSB(s[0], &d[0]); \
55 SILC_PUT32_LSB(s[1], &d[4]); \
56 SILC_PUT32_LSB(s[2], &d[8]); \
57 SILC_PUT32_LSB(s[3], &d[12]); \
60 #define SILC_CBC_ENC_PRE(d, s) \
62 SILC_GET32_X_LSB(d[0], &s[0]); \
63 SILC_GET32_X_LSB(d[1], &s[4]); \
64 SILC_GET32_X_LSB(d[2], &s[8]); \
65 SILC_GET32_X_LSB(d[3], &s[12]); \
68 #define SILC_CBC_ENC_POST(s, d, t) \
70 SILC_PUT32_LSB(s[0], &d[0]); \
71 SILC_PUT32_LSB(s[1], &d[4]); \
72 SILC_PUT32_LSB(s[2], &d[8]); \
73 SILC_PUT32_LSB(s[3], &d[12]); \
79 #define SILC_CBC_DEC_PRE(d, s) \
81 SILC_GET32_LSB(d[0], &s[0]); \
82 SILC_GET32_LSB(d[1], &s[4]); \
83 SILC_GET32_LSB(d[2], &s[8]); \
84 SILC_GET32_LSB(d[3], &s[12]); \
87 #define SILC_CBC_DEC_POST(s, d, p, t, siv) \
94 SILC_PUT32_LSB(s[0], &d[0]); \
95 SILC_PUT32_LSB(s[1], &d[4]); \
96 SILC_PUT32_LSB(s[2], &d[8]); \
97 SILC_PUT32_LSB(s[3], &d[12]); \