comparison sha.c @ 993:f8db9a2bae05 libavutil

Add av_ prefix to bswap macros
author mru
date Sat, 10 Jul 2010 22:12:30 +0000
parents a13125b5be3a
children
comparison
equal deleted inserted replaced
992:a13125b5be3a 993:f8db9a2bae05
41 const int av_sha_size = sizeof(AVSHA); 41 const int av_sha_size = sizeof(AVSHA);
42 42
43 #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) 43 #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
44 44
45 /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ 45 /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
46 #define blk0(i) (block[i] = be2ne_32(((const uint32_t*)buffer)[i])) 46 #define blk0(i) (block[i] = av_be2ne32(((const uint32_t*)buffer)[i]))
47 #define blk(i) (block[i] = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1)) 47 #define blk(i) (block[i] = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1))
48 48
49 #define R0(v,w,x,y,z,i) z += ((w&(x^y))^y) + blk0(i) + 0x5A827999 + rol(v, 5); w = rol(w, 30); 49 #define R0(v,w,x,y,z,i) z += ((w&(x^y))^y) + blk0(i) + 0x5A827999 + rol(v, 5); w = rol(w, 30);
50 #define R1(v,w,x,y,z,i) z += ((w&(x^y))^y) + blk (i) + 0x5A827999 + rol(v, 5); w = rol(w, 30); 50 #define R1(v,w,x,y,z,i) z += ((w&(x^y))^y) + blk (i) + 0x5A827999 + rol(v, 5); w = rol(w, 30);
51 #define R2(v,w,x,y,z,i) z += ( w^x ^y) + blk (i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30); 51 #define R2(v,w,x,y,z,i) z += ( w^x ^y) + blk (i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30);
66 e = state[4]; 66 e = state[4];
67 #if CONFIG_SMALL 67 #if CONFIG_SMALL
68 for (i = 0; i < 80; i++) { 68 for (i = 0; i < 80; i++) {
69 int t; 69 int t;
70 if (i < 16) 70 if (i < 16)
71 t = be2ne_32(((uint32_t*)buffer)[i]); 71 t = av_be2ne32(((uint32_t*)buffer)[i]);
72 else 72 else
73 t = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1); 73 t = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1);
74 block[i] = t; 74 block[i] = t;
75 t += e + rol(a, 5); 75 t += e + rol(a, 5);
76 if (i < 40) { 76 if (i < 40) {
312 } 312 }
313 313
314 void av_sha_final(AVSHA* ctx, uint8_t *digest) 314 void av_sha_final(AVSHA* ctx, uint8_t *digest)
315 { 315 {
316 int i; 316 int i;
317 uint64_t finalcount = be2ne_64(ctx->count << 3); 317 uint64_t finalcount = av_be2ne64(ctx->count << 3);
318 318
319 av_sha_update(ctx, "\200", 1); 319 av_sha_update(ctx, "\200", 1);
320 while ((ctx->count & 63) != 56) 320 while ((ctx->count & 63) != 56)
321 av_sha_update(ctx, "", 1); 321 av_sha_update(ctx, "", 1);
322 av_sha_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform() */ 322 av_sha_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform() */