diff --git a/lib/des/md4.c b/lib/des/md4.c index 75b5983af..73a10519a 100644 --- a/lib/des/md4.c +++ b/lib/des/md4.c @@ -42,15 +42,9 @@ RCSID("$Id$"); #endif -#include -#include - +#include "hash.h" #include "md4.h" -#ifndef min -#define min(a,b) (((a)>(b))?(b):(a)) -#endif - #define A m->counter[0] #define B m->counter[1] #define C m->counter[2] @@ -68,13 +62,7 @@ md4_init (struct md4 *m) A = 0x67452301; } -static inline u_int32_t -cshift (u_int32_t x, unsigned int n) -{ - return (x << n) | (x >> (32 - n)); -} - -#define F(x,y,z) ((x & y) | (~x & z)) +#define F(x,y,z) CRAYFIX((x & y) | (~x & z)) #define G(x,y,z) ((x & y) | (x & z) | (y & z)) #define H(x,y,z) (x ^ y ^ z) @@ -175,10 +163,9 @@ static inline u_int32_t swap_u_int32_t (u_int32_t t) { #if defined(WORDS_BIGENDIAN) -#define ROL(x,n) ((x)<<(n))|((x)>>(32-(n))) u_int32_t temp1, temp2; - temp1 = ROL(t,16); + temp1 = cshift(t, 16); temp2 = temp1 >> 8; temp1 &= 0x00ff00ff; temp2 &= 0x00ff00ff; @@ -197,30 +184,30 @@ struct x32{ void md4_update (struct md4 *m, const void *v, size_t len) { - const unsigned char *p = v; - m->sz += len; - while(len > 0){ - size_t l = min(len, 64 - m->offset); - memcpy(m->save + m->offset, p, l); - m->offset += l; - p += l; - len -= l; - if(m->offset == 64){ + const unsigned char *p = v; + m->sz += len; + while(len > 0){ + size_t l = min(len, 64 - m->offset); + memcpy(m->save + m->offset, p, l); + m->offset += l; + p += l; + len -= l; + if(m->offset == 64){ #if defined(WORDS_BIGENDIAN) - int i; - u_int32_t current[16]; - struct x32 *u = (struct x32*)m->save; - for(i = 0; i < 8; i++){ - current[2*i+0] = swap_u_int32_t(u[i].a); - current[2*i+1] = swap_u_int32_t(u[i].b); - } - calc(m, current); + int i; + u_int32_t current[16]; + struct x32 *u = (struct x32*)m->save; + for(i = 0; i < 8; i++){ + current[2*i+0] = swap_u_int32_t(u[i].a); + current[2*i+1] = swap_u_int32_t(u[i].b); + } + calc(m, current); #else - calc(m, (u_int32_t*)m->save); + calc(m, (u_int32_t*)m->save); #endif - m->offset = 0; + m->offset = 0; + } } - } } void diff --git a/lib/des/md5.c b/lib/des/md5.c index 78e0853a7..ea73f24cc 100644 --- a/lib/des/md5.c +++ b/lib/des/md5.c @@ -42,15 +42,9 @@ RCSID("$Id$"); #endif -#include -#include - +#include "hash.h" #include "md5.h" -#ifndef min -#define min(a,b) (((a)>(b))?(b):(a)) -#endif - #define A m->counter[0] #define B m->counter[1] #define C m->counter[2] @@ -68,16 +62,10 @@ md5_init (struct md5 *m) A = 0x67452301; } -static inline u_int32_t -cshift (u_int32_t x, unsigned int n) -{ - return (x << n) | (x >> (32 - n)); -} - -#define F(x,y,z) ((x & y) | (~x & z)) -#define G(x,y,z) ((x & z) | (y & ~z)) +#define F(x,y,z) CRAYFIX((x & y) | (~x & z)) +#define G(x,y,z) CRAYFIX((x & z) | (y & ~z)) #define H(x,y,z) (x ^ y ^ z) -#define I(x,y,z) (y ^ (x | ~z)) +#define I(x,y,z) CRAYFIX(y ^ (x | ~z)) #define DOIT(a,b,c,d,k,s,i,OP) \ a = b + cshift(a + OP(b,c,d) + X[k] + (i), s) @@ -199,10 +187,9 @@ static inline u_int32_t swap_u_int32_t (u_int32_t t) { #if defined(WORDS_BIGENDIAN) -#define ROL(x,n) ((x)<<(n))|((x)>>(32-(n))) u_int32_t temp1, temp2; - temp1 = ROL(t,16); + temp1 = cshift(t, 16); temp2 = temp1 >> 8; temp1 &= 0x00ff00ff; temp2 &= 0x00ff00ff; diff --git a/lib/des/sha.c b/lib/des/sha.c index 0b5668078..f0dcbe3ef 100644 --- a/lib/des/sha.c +++ b/lib/des/sha.c @@ -42,15 +42,9 @@ RCSID("$Id$"); #endif -#include -#include - +#include "hash.h" #include "sha.h" -#ifndef min -#define min(a,b) (((a)>(b))?(b):(a)) -#endif - #define A m->counter[0] #define B m->counter[1] #define C m->counter[2] @@ -70,13 +64,8 @@ sha_init (struct sha *m) E = 0xc3d2e1f0; } -static inline u_int32_t -cshift (u_int32_t x, unsigned int n) -{ - return (x << n) | (x >> (32 - n)); -} -#define F0(x,y,z) ((x & y) | (~x & z)) +#define F0(x,y,z) CRAYFIX((x & y) | (~x & z)) #define F1(x,y,z) (x ^ y ^ z) #define F2(x,y,z) ((x & y) | (x & z) | (y & z)) #define F3(x,y,z) F1(x,y,z) @@ -226,7 +215,7 @@ swap_u_int32_t (u_int32_t t) #define ROL(x,n) ((x)<<(n))|((x)>>(32-(n))) u_int32_t temp1, temp2; - temp1 = ROL(t,16); + temp1 = cshift(t, 16); temp2 = temp1 >> 8; temp1 &= 0x00ff00ff; temp2 &= 0x00ff00ff;