use hash.h; fixes for crays

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5693 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1999-03-22 19:17:24 +00:00
parent 4652e1f3ca
commit ac8b54ada2
3 changed files with 31 additions and 68 deletions

View File

@@ -42,15 +42,9 @@
RCSID("$Id$"); RCSID("$Id$");
#endif #endif
#include <stdlib.h> #include "hash.h"
#include <string.h>
#include "md4.h" #include "md4.h"
#ifndef min
#define min(a,b) (((a)>(b))?(b):(a))
#endif
#define A m->counter[0] #define A m->counter[0]
#define B m->counter[1] #define B m->counter[1]
#define C m->counter[2] #define C m->counter[2]
@@ -68,13 +62,7 @@ md4_init (struct md4 *m)
A = 0x67452301; A = 0x67452301;
} }
static inline u_int32_t #define F(x,y,z) CRAYFIX((x & y) | (~x & z))
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 & y) | (x & z) | (y & z)) #define G(x,y,z) ((x & y) | (x & z) | (y & z))
#define H(x,y,z) (x ^ 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) swap_u_int32_t (u_int32_t t)
{ {
#if defined(WORDS_BIGENDIAN) #if defined(WORDS_BIGENDIAN)
#define ROL(x,n) ((x)<<(n))|((x)>>(32-(n)))
u_int32_t temp1, temp2; u_int32_t temp1, temp2;
temp1 = ROL(t,16); temp1 = cshift(t, 16);
temp2 = temp1 >> 8; temp2 = temp1 >> 8;
temp1 &= 0x00ff00ff; temp1 &= 0x00ff00ff;
temp2 &= 0x00ff00ff; temp2 &= 0x00ff00ff;
@@ -197,30 +184,30 @@ struct x32{
void void
md4_update (struct md4 *m, const void *v, size_t len) md4_update (struct md4 *m, const void *v, size_t len)
{ {
const unsigned char *p = v; const unsigned char *p = v;
m->sz += len; m->sz += len;
while(len > 0){ while(len > 0){
size_t l = min(len, 64 - m->offset); size_t l = min(len, 64 - m->offset);
memcpy(m->save + m->offset, p, l); memcpy(m->save + m->offset, p, l);
m->offset += l; m->offset += l;
p += l; p += l;
len -= l; len -= l;
if(m->offset == 64){ if(m->offset == 64){
#if defined(WORDS_BIGENDIAN) #if defined(WORDS_BIGENDIAN)
int i; int i;
u_int32_t current[16]; u_int32_t current[16];
struct x32 *u = (struct x32*)m->save; struct x32 *u = (struct x32*)m->save;
for(i = 0; i < 8; i++){ for(i = 0; i < 8; i++){
current[2*i+0] = swap_u_int32_t(u[i].a); current[2*i+0] = swap_u_int32_t(u[i].a);
current[2*i+1] = swap_u_int32_t(u[i].b); current[2*i+1] = swap_u_int32_t(u[i].b);
} }
calc(m, current); calc(m, current);
#else #else
calc(m, (u_int32_t*)m->save); calc(m, (u_int32_t*)m->save);
#endif #endif
m->offset = 0; m->offset = 0;
}
} }
}
} }
void void

View File

@@ -42,15 +42,9 @@
RCSID("$Id$"); RCSID("$Id$");
#endif #endif
#include <stdlib.h> #include "hash.h"
#include <string.h>
#include "md5.h" #include "md5.h"
#ifndef min
#define min(a,b) (((a)>(b))?(b):(a))
#endif
#define A m->counter[0] #define A m->counter[0]
#define B m->counter[1] #define B m->counter[1]
#define C m->counter[2] #define C m->counter[2]
@@ -68,16 +62,10 @@ md5_init (struct md5 *m)
A = 0x67452301; A = 0x67452301;
} }
static inline u_int32_t #define F(x,y,z) CRAYFIX((x & y) | (~x & z))
cshift (u_int32_t x, unsigned int n) #define G(x,y,z) CRAYFIX((x & z) | (y & ~z))
{
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 H(x,y,z) (x ^ 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) \ #define DOIT(a,b,c,d,k,s,i,OP) \
a = b + cshift(a + OP(b,c,d) + X[k] + (i), s) 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) swap_u_int32_t (u_int32_t t)
{ {
#if defined(WORDS_BIGENDIAN) #if defined(WORDS_BIGENDIAN)
#define ROL(x,n) ((x)<<(n))|((x)>>(32-(n)))
u_int32_t temp1, temp2; u_int32_t temp1, temp2;
temp1 = ROL(t,16); temp1 = cshift(t, 16);
temp2 = temp1 >> 8; temp2 = temp1 >> 8;
temp1 &= 0x00ff00ff; temp1 &= 0x00ff00ff;
temp2 &= 0x00ff00ff; temp2 &= 0x00ff00ff;

View File

@@ -42,15 +42,9 @@
RCSID("$Id$"); RCSID("$Id$");
#endif #endif
#include <stdlib.h> #include "hash.h"
#include <string.h>
#include "sha.h" #include "sha.h"
#ifndef min
#define min(a,b) (((a)>(b))?(b):(a))
#endif
#define A m->counter[0] #define A m->counter[0]
#define B m->counter[1] #define B m->counter[1]
#define C m->counter[2] #define C m->counter[2]
@@ -70,13 +64,8 @@ sha_init (struct sha *m)
E = 0xc3d2e1f0; 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 F1(x,y,z) (x ^ y ^ z)
#define F2(x,y,z) ((x & y) | (x & z) | (y & z)) #define F2(x,y,z) ((x & y) | (x & z) | (y & z))
#define F3(x,y,z) F1(x,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))) #define ROL(x,n) ((x)<<(n))|((x)>>(32-(n)))
u_int32_t temp1, temp2; u_int32_t temp1, temp2;
temp1 = ROL(t,16); temp1 = cshift(t, 16);
temp2 = temp1 >> 8; temp2 = temp1 >> 8;
temp1 &= 0x00ff00ff; temp1 &= 0x00ff00ff;
temp2 &= 0x00ff00ff; temp2 &= 0x00ff00ff;