5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
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; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
24 /* General definitions for algorithms */
25 typedef unsigned char u1byte;
26 typedef uint32 u4byte;
29 #define rotr(x, nr) (((x) >> ((int)(nr))) | ((x) << (32 - (int)(nr))))
30 #define rotl(x, nr) (((x) << ((int)(nr))) | ((x) >> (32 - (int)(nr))))
31 #define byte(x, nr) ((x) >> (nr * 8) & 255)
33 /* Byte key to words */
34 #define SILC_GET_WORD_KEY(s, d, len) \
37 for (_i = 0; _i < (len / 8) / 4; _i++) \
38 SILC_GET32_LSB(d[_i], s + (_i * 4)); \
41 /* CBC mode macros. */
43 #define SILC_CBC_GET_IV(d, s) \
45 SILC_GET32_LSB(d[0], &s[0]); \
46 SILC_GET32_LSB(d[1], &s[4]); \
47 SILC_GET32_LSB(d[2], &s[8]); \
48 SILC_GET32_LSB(d[3], &s[12]); \
51 #define SILC_CBC_PUT_IV(s, d) \
53 SILC_PUT32_LSB(s[0], &d[0]); \
54 SILC_PUT32_LSB(s[1], &d[4]); \
55 SILC_PUT32_LSB(s[2], &d[8]); \
56 SILC_PUT32_LSB(s[3], &d[12]); \
59 #define SILC_CBC_ENC_PRE(d, s) \
61 SILC_GET32_X_LSB(d[0], &s[0]); \
62 SILC_GET32_X_LSB(d[1], &s[4]); \
63 SILC_GET32_X_LSB(d[2], &s[8]); \
64 SILC_GET32_X_LSB(d[3], &s[12]); \
67 #define SILC_CBC_ENC_POST(s, d, t) \
69 SILC_PUT32_LSB(s[0], &d[0]); \
70 SILC_PUT32_LSB(s[1], &d[4]); \
71 SILC_PUT32_LSB(s[2], &d[8]); \
72 SILC_PUT32_LSB(s[3], &d[12]); \
78 #define SILC_CBC_DEC_PRE(d, s) \
80 SILC_GET32_LSB(d[0], &s[0]); \
81 SILC_GET32_LSB(d[1], &s[4]); \
82 SILC_GET32_LSB(d[2], &s[8]); \
83 SILC_GET32_LSB(d[3], &s[12]); \
86 #define SILC_CBC_DEC_POST(s, d, p, t, iv) \
93 SILC_PUT32_LSB(s[0], &d[0]); \
94 SILC_PUT32_LSB(s[1], &d[4]); \
95 SILC_PUT32_LSB(s[2], &d[8]); \
96 SILC_PUT32_LSB(s[3], &d[12]); \