bug 496234 - use stdint types in md4 implementation r=mayhemer

Also removes some trailing whitespace.
This commit is contained in:
David Keeler 2015-06-25 12:00:49 -07:00
parent 992ed8e310
commit a24acafba5
2 changed files with 22 additions and 25 deletions

View File

@ -10,9 +10,6 @@
#include <string.h>
#include "md4.h"
typedef uint32_t Uint32;
typedef uint8_t Uint8;
/* the "conditional" function */
#define F(x,y,z) (((x) & (y)) | (~(x) & (z)))
@ -35,9 +32,9 @@ typedef uint8_t Uint8;
#define RD3(a,b,c,d,k,s) a += H(b,c,d) + X[k] + 0x6ED9EBA1; a = ROTL(a,s)
/* converts from word array to byte array, len is number of bytes */
static void w2b(Uint8 *out, const Uint32 *in, Uint32 len)
static void w2b(uint8_t *out, const uint32_t *in, uint32_t len)
{
Uint8 *bp; const Uint32 *wp, *wpend;
uint8_t *bp; const uint32_t *wp, *wpend;
bp = out;
wp = in;
@ -45,17 +42,17 @@ static void w2b(Uint8 *out, const Uint32 *in, Uint32 len)
for (; wp != wpend; ++wp, bp += 4)
{
bp[0] = (Uint8) ((*wp ) & 0xFF);
bp[1] = (Uint8) ((*wp >> 8) & 0xFF);
bp[2] = (Uint8) ((*wp >> 16) & 0xFF);
bp[3] = (Uint8) ((*wp >> 24) & 0xFF);
bp[0] = (uint8_t) ((*wp ) & 0xFF);
bp[1] = (uint8_t) ((*wp >> 8) & 0xFF);
bp[2] = (uint8_t) ((*wp >> 16) & 0xFF);
bp[3] = (uint8_t) ((*wp >> 24) & 0xFF);
}
}
/* converts from byte array to word array, len is number of bytes */
static void b2w(Uint32 *out, const Uint8 *in, Uint32 len)
static void b2w(uint32_t *out, const uint8_t *in, uint32_t len)
{
Uint32 *wp; const Uint8 *bp, *bpend;
uint32_t *wp; const uint8_t *bp, *bpend;
wp = out;
bp = in;
@ -63,17 +60,17 @@ static void b2w(Uint32 *out, const Uint8 *in, Uint32 len)
for (; bp != bpend; bp += 4, ++wp)
{
*wp = (Uint32) (bp[0] ) |
(Uint32) (bp[1] << 8) |
(Uint32) (bp[2] << 16) |
(Uint32) (bp[3] << 24);
*wp = (uint32_t) (bp[0] ) |
(uint32_t) (bp[1] << 8) |
(uint32_t) (bp[2] << 16) |
(uint32_t) (bp[3] << 24);
}
}
/* update state: data is 64 bytes in length */
static void md4step(Uint32 state[4], const Uint8 *data)
static void md4step(uint32_t state[4], const uint8_t *data)
{
Uint32 A, B, C, D, X[16];
uint32_t A, B, C, D, X[16];
b2w(X, data, 64);
@ -87,10 +84,10 @@ static void md4step(Uint32 state[4], const Uint8 *data)
RD1(A,B,C,D, 8,3); RD1(D,A,B,C, 9,7); RD1(C,D,A,B,10,11); RD1(B,C,D,A,11,19);
RD1(A,B,C,D,12,3); RD1(D,A,B,C,13,7); RD1(C,D,A,B,14,11); RD1(B,C,D,A,15,19);
RD2(A,B,C,D, 0,3); RD2(D,A,B,C, 4,5); RD2(C,D,A,B, 8, 9); RD2(B,C,D,A,12,13);
RD2(A,B,C,D, 1,3); RD2(D,A,B,C, 5,5); RD2(C,D,A,B, 9, 9); RD2(B,C,D,A,13,13);
RD2(A,B,C,D, 2,3); RD2(D,A,B,C, 6,5); RD2(C,D,A,B,10, 9); RD2(B,C,D,A,14,13);
RD2(A,B,C,D, 3,3); RD2(D,A,B,C, 7,5); RD2(C,D,A,B,11, 9); RD2(B,C,D,A,15,13);
RD2(A,B,C,D, 0,3); RD2(D,A,B,C, 4,5); RD2(C,D,A,B, 8, 9); RD2(B,C,D,A,12,13);
RD2(A,B,C,D, 1,3); RD2(D,A,B,C, 5,5); RD2(C,D,A,B, 9, 9); RD2(B,C,D,A,13,13);
RD2(A,B,C,D, 2,3); RD2(D,A,B,C, 6,5); RD2(C,D,A,B,10, 9); RD2(B,C,D,A,14,13);
RD2(A,B,C,D, 3,3); RD2(D,A,B,C, 7,5); RD2(C,D,A,B,11, 9); RD2(B,C,D,A,15,13);
RD3(A,B,C,D, 0,3); RD3(D,A,B,C, 8,9); RD3(C,D,A,B, 4,11); RD3(B,C,D,A,12,15);
RD3(A,B,C,D, 2,3); RD3(D,A,B,C,10,9); RD3(C,D,A,B, 6,11); RD3(B,C,D,A,14,15);
@ -103,10 +100,10 @@ static void md4step(Uint32 state[4], const Uint8 *data)
state[3] += D;
}
void md4sum(const Uint8 *input, Uint32 inputLen, Uint8 *result)
void md4sum(const uint8_t *input, uint32_t inputLen, uint8_t *result)
{
Uint8 final[128];
Uint32 i, n, m, state[4];
uint8_t final[128];
uint32_t i, n, m, state[4];
/* magic initial states */
state[0] = 0x67452301;

View File

@ -14,7 +14,7 @@ extern "C" {
/**
* md4sum - computes the MD4 sum over the input buffer per RFC 1320
*
*
* @param input
* buffer containing input data
* @param inputLen