Index: sha1.h =================================================================== --- sha1.h (révision 8386) +++ sha1.h (copie de travail) @@ -1,10 +1,15 @@ #ifndef AV_SHA1_H #define AV_SHA1_H -extern const int av_sha1_size; +#define AV_SHA1_SIZE 20 -struct AVSHA1; +typedef struct AVSHA1 { + uint64_t count; + uint8_t buffer[64]; + uint32_t state[5]; +} AVSHA1; + void av_sha1_init(struct AVSHA1* context); void av_sha1_update(struct AVSHA1* context, uint8_t* data, unsigned int len); void av_sha1_final(struct AVSHA1* context, uint8_t digest[20]); Index: Makefile =================================================================== --- Makefile (révision 8386) +++ Makefile (copie de travail) @@ -15,10 +15,12 @@ random.o \ aes.o \ base64.o \ + sha1.o \ + oaep.o \ HEADERS = avutil.h common.h mathematics.h integer.h rational.h \ intfloat_readwrite.h md5.h adler32.h log.h fifo.h lzo.h \ - random.h mem.h + random.h mem.h sha1.h oaep.h NAME=avutil LIBVERSION=$(LAVUVERSION) Index: intreadwrite.h =================================================================== --- intreadwrite.h (révision 8386) +++ intreadwrite.h (copie de travail) @@ -69,7 +69,17 @@ ((uint8_t*)(p))[2] = (d)>>8; \ ((uint8_t*)(p))[1] = (d)>>16; \ ((uint8_t*)(p))[0] = (d)>>24; } +#define AV_WB64(p, d) { \ + ((uint8_t*)(p))[7] = (d); \ + ((uint8_t*)(p))[6] = (d)>>8; \ + ((uint8_t*)(p))[5] = (d)>>16; \ + ((uint8_t*)(p))[4] = (d)>>24; \ + ((uint8_t*)(p))[3] = (d)>>32; \ + ((uint8_t*)(p))[2] = (d)>>40; \ + ((uint8_t*)(p))[1] = (d)>>48; \ + ((uint8_t*)(p))[0] = (d)>>56; } + #define AV_RL8(x) AV_RB8(x) #define AV_WL8(p, d) AV_WB8(p, d) Index: sha1.c =================================================================== --- sha1.c (révision 8386) +++ sha1.c (copie de travail) @@ -4,17 +4,11 @@ #include "common.h" #include "sha1.h" - -typedef struct AVSHA1 { - uint64_t count; - uint8_t buffer[64]; - uint32_t state[5]; -} AVSHA1; - +#include "intreadwrite.h" #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define blk0(i) (block[i] = be2me_32(((uint32_t*)buffer)[i])) +#define blk0(i) (block[i] = AV_RB32(&((uint32_t*)buffer)[i])) #define blk(i) (block[i] = rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1)) #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); @@ -37,7 +31,7 @@ #ifdef CONFIG_SMALL for(i=0; i<80; i++){ int t; - if(i<16) t= be2me_32(((uint32_t*)buffer)[i]); + if(i<16) t= AV_RB32(((uint32_t*)buffer)[i]); else t= rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1); block[i]= t; t+= e+rol(a,5); @@ -114,7 +108,8 @@ void av_sha1_final(AVSHA1* ctx, uint8_t digest[20]){ int i; - uint64_t finalcount= be2me_64(ctx->count<<3); + uint64_t finalcount; + AV_WB64(&finalcount,(ctx->count<<3)); av_sha1_update(ctx, "\200", 1); while ((ctx->count & 63) != 56) { @@ -122,7 +117,7 @@ } av_sha1_update(ctx, &finalcount, 8); /* Should cause a transform() */ for(i=0; i<5; i++) - ((uint32_t*)digest)[i]= be2me_32(ctx->state[i]); + AV_WB32(&((uint32_t*)digest)[i],(ctx->state[i])); } // use the following to test