File indexing completed on 2025-01-18 10:02:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #ifndef NETTLE_MACROS_H_INCLUDED
0033 #define NETTLE_MACROS_H_INCLUDED
0034
0035
0036 #define READ_UINT64(p) \
0037 ( (((uint64_t) (p)[0]) << 56) \
0038 | (((uint64_t) (p)[1]) << 48) \
0039 | (((uint64_t) (p)[2]) << 40) \
0040 | (((uint64_t) (p)[3]) << 32) \
0041 | (((uint64_t) (p)[4]) << 24) \
0042 | (((uint64_t) (p)[5]) << 16) \
0043 | (((uint64_t) (p)[6]) << 8) \
0044 | ((uint64_t) (p)[7]))
0045
0046 #define WRITE_UINT64(p, i) \
0047 do { \
0048 (p)[0] = ((i) >> 56) & 0xff; \
0049 (p)[1] = ((i) >> 48) & 0xff; \
0050 (p)[2] = ((i) >> 40) & 0xff; \
0051 (p)[3] = ((i) >> 32) & 0xff; \
0052 (p)[4] = ((i) >> 24) & 0xff; \
0053 (p)[5] = ((i) >> 16) & 0xff; \
0054 (p)[6] = ((i) >> 8) & 0xff; \
0055 (p)[7] = (i) & 0xff; \
0056 } while(0)
0057
0058
0059 #define READ_UINT32(p) \
0060 ( (((uint32_t) (p)[0]) << 24) \
0061 | (((uint32_t) (p)[1]) << 16) \
0062 | (((uint32_t) (p)[2]) << 8) \
0063 | ((uint32_t) (p)[3]))
0064
0065 #define WRITE_UINT32(p, i) \
0066 do { \
0067 (p)[0] = ((i) >> 24) & 0xff; \
0068 (p)[1] = ((i) >> 16) & 0xff; \
0069 (p)[2] = ((i) >> 8) & 0xff; \
0070 (p)[3] = (i) & 0xff; \
0071 } while(0)
0072
0073
0074 #define READ_UINT24(p) \
0075 ( (((uint32_t) (p)[0]) << 16) \
0076 | (((uint32_t) (p)[1]) << 8) \
0077 | ((uint32_t) (p)[2]))
0078
0079 #define WRITE_UINT24(p, i) \
0080 do { \
0081 (p)[0] = ((i) >> 16) & 0xff; \
0082 (p)[1] = ((i) >> 8) & 0xff; \
0083 (p)[2] = (i) & 0xff; \
0084 } while(0)
0085
0086 #define READ_UINT16(p) \
0087 ( (((uint32_t) (p)[0]) << 8) \
0088 | ((uint32_t) (p)[1]))
0089
0090 #define WRITE_UINT16(p, i) \
0091 do { \
0092 (p)[0] = ((i) >> 8) & 0xff; \
0093 (p)[1] = (i) & 0xff; \
0094 } while(0)
0095
0096
0097 #define LE_READ_UINT64(p) \
0098 ( (((uint64_t) (p)[7]) << 56) \
0099 | (((uint64_t) (p)[6]) << 48) \
0100 | (((uint64_t) (p)[5]) << 40) \
0101 | (((uint64_t) (p)[4]) << 32) \
0102 | (((uint64_t) (p)[3]) << 24) \
0103 | (((uint64_t) (p)[2]) << 16) \
0104 | (((uint64_t) (p)[1]) << 8) \
0105 | ((uint64_t) (p)[0]))
0106
0107 #define LE_WRITE_UINT64(p, i) \
0108 do { \
0109 (p)[7] = ((i) >> 56) & 0xff; \
0110 (p)[6] = ((i) >> 48) & 0xff; \
0111 (p)[5] = ((i) >> 40) & 0xff; \
0112 (p)[4] = ((i) >> 32) & 0xff; \
0113 (p)[3] = ((i) >> 24) & 0xff; \
0114 (p)[2] = ((i) >> 16) & 0xff; \
0115 (p)[1] = ((i) >> 8) & 0xff; \
0116 (p)[0] = (i) & 0xff; \
0117 } while (0)
0118
0119 #define LE_READ_UINT32(p) \
0120 ( (((uint32_t) (p)[3]) << 24) \
0121 | (((uint32_t) (p)[2]) << 16) \
0122 | (((uint32_t) (p)[1]) << 8) \
0123 | ((uint32_t) (p)[0]))
0124
0125 #define LE_WRITE_UINT32(p, i) \
0126 do { \
0127 (p)[3] = ((i) >> 24) & 0xff; \
0128 (p)[2] = ((i) >> 16) & 0xff; \
0129 (p)[1] = ((i) >> 8) & 0xff; \
0130 (p)[0] = (i) & 0xff; \
0131 } while(0)
0132
0133
0134 #define LE_READ_UINT16(p) \
0135 ( (((uint32_t) (p)[1]) << 8) \
0136 | ((uint32_t) (p)[0]))
0137
0138 #define LE_WRITE_UINT16(p, i) \
0139 do { \
0140 (p)[1] = ((i) >> 8) & 0xff; \
0141 (p)[0] = (i) & 0xff; \
0142 } while(0)
0143
0144
0145 #define FOR_BLOCKS(length, dst, src, blocksize) \
0146 assert( !((length) % (blocksize))); \
0147 for (; (length); ((length) -= (blocksize), \
0148 (dst) += (blocksize), \
0149 (src) += (blocksize)) )
0150
0151
0152
0153
0154 #define ROTL32(n,x) (((x)<<(n)) | ((x)>>((-(n)&31))))
0155
0156 #define ROTL64(n,x) (((x)<<(n)) | ((x)>>((-(n))&63)))
0157
0158
0159 #define INCREMENT(size, ctr) \
0160 do { \
0161 unsigned increment_i = (size) - 1; \
0162 if (++(ctr)[increment_i] == 0) \
0163 while (increment_i > 0 \
0164 && ++(ctr)[--increment_i] == 0 ) \
0165 ; \
0166 } while (0)
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 #define MD_INCR(ctx) ((ctx)->count_high += !++(ctx)->count_low)
0178
0179
0180
0181 #define MD_UPDATE(ctx, length, data, f, incr) \
0182 do { \
0183 if ((ctx)->index) \
0184 { \
0185 \
0186 unsigned __md_left = sizeof((ctx)->block) - (ctx)->index; \
0187 if ((length) < __md_left) \
0188 { \
0189 memcpy((ctx)->block + (ctx)->index, (data), (length)); \
0190 (ctx)->index += (length); \
0191 goto __md_done; \
0192 } \
0193 else \
0194 { \
0195 memcpy((ctx)->block + (ctx)->index, (data), __md_left); \
0196 \
0197 f((ctx), (ctx)->block); \
0198 (incr); \
0199 \
0200 (data) += __md_left; \
0201 (length) -= __md_left; \
0202 } \
0203 } \
0204 while ((length) >= sizeof((ctx)->block)) \
0205 { \
0206 f((ctx), (data)); \
0207 (incr); \
0208 \
0209 (data) += sizeof((ctx)->block); \
0210 (length) -= sizeof((ctx)->block); \
0211 } \
0212 memcpy ((ctx)->block, (data), (length)); \
0213 (ctx)->index = (length); \
0214 __md_done: \
0215 ; \
0216 } while (0)
0217
0218
0219
0220
0221 #define MD_PAD(ctx, size, f) \
0222 do { \
0223 unsigned __md_i; \
0224 __md_i = (ctx)->index; \
0225 \
0226
0227 \
0228 \
0229 assert(__md_i < sizeof((ctx)->block)); \
0230 (ctx)->block[__md_i++] = 0x80; \
0231 \
0232 if (__md_i > (sizeof((ctx)->block) - (size))) \
0233 {
0234 \
0235 memset((ctx)->block + __md_i, 0, sizeof((ctx)->block) - __md_i); \
0236 \
0237 f((ctx), (ctx)->block); \
0238 __md_i = 0; \
0239 } \
0240 memset((ctx)->block + __md_i, 0, \
0241 sizeof((ctx)->block) - (size) - __md_i); \
0242 \
0243 } while (0)
0244
0245 #endif