5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1999 - 2000 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;
28 #define rotr(x, nr) (((x) >> ((int)(nr))) | ((x) << (32 - (int)(nr))))
29 #define rotl(x, nr) (((x) << ((int)(nr))) | ((x) >> (32 - (int)(nr))))
30 #define byte(x, nr) ((x) >> (nr * 8) & 255)
32 /* Byte key to words */
33 #define SILC_GET_WORD_KEY(s, d, len) \
36 for (_i = 0; _i < (len / 8) / 4; _i++) \
37 SILC_GET32_LSB(d[_i], s + (_i * 4)); \
40 /* CBC mode macros. */
42 #define SILC_CBC_GET_IV(d, s) \
44 SILC_GET32_LSB(d[0], &s[0]); \
45 SILC_GET32_LSB(d[1], &s[4]); \
46 SILC_GET32_LSB(d[2], &s[8]); \
47 SILC_GET32_LSB(d[3], &s[12]); \
50 #define SILC_CBC_PUT_IV(s, d) \
52 SILC_PUT32_LSB(s[0], &d[0]); \
53 SILC_PUT32_LSB(s[1], &d[4]); \
54 SILC_PUT32_LSB(s[2], &d[8]); \
55 SILC_PUT32_LSB(s[3], &d[12]); \
58 #define SILC_CBC_ENC_PRE(d, s) \
60 SILC_GET32_X_LSB(d[0], &s[0]); \
61 SILC_GET32_X_LSB(d[1], &s[4]); \
62 SILC_GET32_X_LSB(d[2], &s[8]); \
63 SILC_GET32_X_LSB(d[3], &s[12]); \
66 #define SILC_CBC_ENC_POST(s, d, t) \
68 SILC_PUT32_LSB(s[0], &d[0]); \
69 SILC_PUT32_LSB(s[1], &d[4]); \
70 SILC_PUT32_LSB(s[2], &d[8]); \
71 SILC_PUT32_LSB(s[3], &d[12]); \
77 #define SILC_CBC_DEC_PRE(d, s) \
79 SILC_GET32_LSB(d[0], &s[0]); \
80 SILC_GET32_LSB(d[1], &s[4]); \
81 SILC_GET32_LSB(d[2], &s[8]); \
82 SILC_GET32_LSB(d[3], &s[12]); \
85 #define SILC_CBC_DEC_POST(s, d, p, t, siv) \
92 SILC_PUT32_LSB(s[0], &d[0]); \
93 SILC_PUT32_LSB(s[1], &d[4]); \
94 SILC_PUT32_LSB(s[2], &d[8]); \
95 SILC_PUT32_LSB(s[3], &d[12]); \