summaryrefslogtreecommitdiff
path: root/cipher/md4.c
diff options
context:
space:
mode:
Diffstat (limited to 'cipher/md4.c')
-rw-r--r--cipher/md4.c37
1 files changed, 7 insertions, 30 deletions
diff --git a/cipher/md4.c b/cipher/md4.c
index 2de530cc..e2d096ce 100644
--- a/cipher/md4.c
+++ b/cipher/md4.c
@@ -56,6 +56,7 @@
#include "cipher.h"
#include "bithelp.h"
+#include "bufhelp.h"
#include "hash-common.h"
@@ -100,23 +101,10 @@ transform ( void *c, const unsigned char *data )
register u32 B = ctx->B;
register u32 C = ctx->C;
register u32 D = ctx->D;
+ int i;
-#ifdef WORDS_BIGENDIAN
- {
- int i;
- byte *p2;
- const byte *p1;
- for(i=0, p1=data, p2=(byte*)in; i < 16; i++, p2 += 4 )
- {
- p2[3] = *p1++;
- p2[2] = *p1++;
- p2[1] = *p1++;
- p2[0] = *p1++;
- }
- }
-#else
- memcpy (in, data, 64);
-#endif
+ for ( i = 0; i < 16; i++ )
+ in[i] = buf_get_le32(data + i * 4);
/* Round 1. */
#define function(a,b,c,d,k,s) a=rol(a+F(b,c,d)+in[k],s);
@@ -238,24 +226,13 @@ md4_final( void *context )
memset(hd->bctx.buf, 0, 56 ); /* fill next block with zeroes */
}
/* append the 64 bit count */
- hd->bctx.buf[56] = lsb ;
- hd->bctx.buf[57] = lsb >> 8;
- hd->bctx.buf[58] = lsb >> 16;
- hd->bctx.buf[59] = lsb >> 24;
- hd->bctx.buf[60] = msb ;
- hd->bctx.buf[61] = msb >> 8;
- hd->bctx.buf[62] = msb >> 16;
- hd->bctx.buf[63] = msb >> 24;
+ buf_put_le32(hd->bctx.buf + 56, lsb);
+ buf_put_le32(hd->bctx.buf + 60, msb);
burn = transform( hd, hd->bctx.buf );
_gcry_burn_stack (burn);
p = hd->bctx.buf;
-#ifdef WORDS_BIGENDIAN
-#define X(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \
- *p++ = hd->a >> 16; *p++ = hd->a >> 24; } while(0)
-#else /* little endian */
-#define X(a) do { *(u32*)p = (*hd).a ; p += 4; } while(0)
-#endif
+#define X(a) do { *(u32*)p = le_bswap32((*hd).a) ; p += 4; } while(0)
X(A);
X(B);
X(C);