Differences From Artifact [ae5d03b1b4]:
- File
src/OFHashes.m
— part of check-in
[9759533b97]
at
2008-10-28 18:19:15
on branch trunk
— Add #undefs in OFHashes.
Just to be sure that we won't get any conflicts when someone addes new
hashes. (user: js, size: 11171) [annotate] [blame] [check-ins using]
To Artifact [ee4f52853e]:
- File src/OFHashes.m — part of check-in [fa2d377c18] at 2008-11-01 17:08:59 on branch trunk — Move some macros to OFMacros.h. (user: js, size: 10913) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
11 12 13 14 15 16 17 | #import "config.h" #import <string.h> #import <stdint.h> #import "OFHashes.h" | | < < < < < < < < < < < < < < < < < < | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #import "config.h" #import <string.h> #import <stdint.h> #import "OFHashes.h" #import "OFMacros.h" /******* * MD5 * *******/ /* The four MD5 core functions - F1 is optimized somewhat */ #define F1(x, y, z) (z ^ (x & (y ^ z))) |
︙ | ︙ | |||
179 180 181 182 183 184 185 | if (size < t) { memcpy(p, buffer, size); return self; } memcpy(p, buffer, t); | | | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | if (size < t) { memcpy(p, buffer, size); return self; } memcpy(p, buffer, t); OF_BSWAP_V(in, 16); md5_transform(buf, (uint32_t*)in); buffer += t; size -= t; } /* Process data in 64-byte chunks */ while (size >= 64) { memcpy(in, buffer, 64); OF_BSWAP_V(in, 16); md5_transform(buf, (uint32_t*)in); buffer += 64; size -= 64; } /* Handle any remaining bytes of data. */ |
︙ | ︙ | |||
227 228 229 230 231 232 233 | /* Bytes of padding needed to make 64 bytes */ count = 64 - 1 - count; /* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); | | | | | | | | | | | | | | | | | | | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | /* Bytes of padding needed to make 64 bytes */ count = 64 - 1 - count; /* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); OF_BSWAP_V(in, 16); md5_transform(buf, (uint32_t*)in); /* Now fill the next block with 56 bytes */ memset(in, 0, 56); } else { /* Pad block to 56 bytes */ memset(p, 0, count - 8); } OF_BSWAP_V(in, 14); /* Append length in bits and transform */ ((uint32_t*)in)[14] = bits[0]; ((uint32_t*)in)[15] = bits[1]; md5_transform(buf, (uint32_t*)in); OF_BSWAP_V((uint8_t*)buf, 4); calculated = YES; return (uint8_t*)buf; } @end #undef F1 #undef F2 #undef F3 #undef F4 #undef MD5STEP /******** * SHA1 * ********/ /* blk0() and blk() perform the initial expand. */ #ifndef OF_BIG_ENDIAN #define blk0(i) \ (block->l[i] = (OF_ROL(block->l[i], 24) & 0xFF00FF00) | \ (OF_ROL(block->l[i], 8) & 0x00FF00FF)) #else #define blk0(i) block->l[i] #endif #define blk(i) \ (block->l[i & 15] = OF_ROL(block->l[(i + 13) & 15] ^ \ block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ \ block->l[i & 15], 1)) /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ #define R0(v, w, x, y, z, i) \ z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + OF_ROL(v, 5); \ w = OF_ROL(w, 30); #define R1(v, w, x, y, z, i) \ z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + OF_ROL(v, 5); \ w = OF_ROL(w, 30); #define R2(v, w, x, y, z, i) \ z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + OF_ROL(v, 5); \ w = OF_ROL(w, 30); #define R3(v, w, x, y, z, i) \ z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + OF_ROL(v, 5); \ w = OF_ROL(w, 30); #define R4(v, w, x, y, z, i) \ z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + OF_ROL(v, 5); \ w = OF_ROL(w, 30); typedef union { uint8_t c[64]; uint32_t l[16]; } sha1_c64l16_t; inline void |
︙ | ︙ |