5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2001 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 #define GET_WORD(cp) ((uint32)(uint8)(cp)[0]) << 24 \
24 | ((uint32)(uint8)(cp)[1] << 16) \
25 | ((uint32)(uint8)(cp)[2] << 8) \
26 | ((uint32)(uint8)(cp)[3])
28 /* Returns eight 8-bit bytes, most significant bytes first. */
29 #define SILC_GET64_MSB(l, cp) \
30 (l) = ((((uint64)GET_WORD((cp))) << 32) | \
31 ((uint64)GET_WORD((cp) + 4)))
32 #define SILC_PUT64_MSB(l, cp) \
34 SILC_PUT32_MSB((uint32)((uint64)(l) >> 32), (cp)); \
35 SILC_PUT32_MSB((uint32)(l), (cp) + 4); \
39 /* Returns four 8-bit bytes, most significant bytes first. */
40 #define SILC_GET32_MSB(l, cp) \
41 (l) = ((uint32)(uint8)(cp)[0]) << 24 \
42 | ((uint32)(uint8)(cp)[1] << 16) \
43 | ((uint32)(uint8)(cp)[2] << 8) \
44 | ((uint32)(uint8)(cp)[3])
45 #define SILC_PUT32_MSB(l, cp) \
52 /* Returns four 8-bit bytes, less significant bytes first. */
53 #define SILC_GET32_LSB(l, cp) \
54 (l) = ((uint32)(uint8)(cp)[0]) \
55 | ((uint32)(uint8)(cp)[1] << 8) \
56 | ((uint32)(uint8)(cp)[2] << 16) \
57 | ((uint32)(uint8)(cp)[3] << 24)
58 /* same as upper but XOR the result always */
59 #define SILC_GET32_X_LSB(l, cp) \
60 (l) ^= ((uint32)(uint8)(cp)[0]) \
61 | ((uint32)(uint8)(cp)[1] << 8) \
62 | ((uint32)(uint8)(cp)[2] << 16) \
63 | ((uint32)(uint8)(cp)[3] << 24)
64 #define SILC_PUT32_LSB(l, cp) \
71 /* Returns two 8-bit bytes, most significant bytes first. */
72 #define SILC_GET16_MSB(l, cp) \
73 (l) = ((uint32)(uint8)(cp)[0] << 8) \
74 | ((uint32)(uint8)(cp)[1])
75 #define SILC_PUT16_MSB(l, cp) \
79 /* Returns two 8-bit bytes, less significant bytes first. */
80 #define SILC_GET16_LSB(l, cp) \
81 (l) = ((uint32)(uint8)(cp)[0]) \
82 | ((uint32)(uint8)(cp)[1] << 8)
83 #define SILC_PUT16_LSB(l, cp) \