103 if ((lsb += count) < t)
113 ibuffer[count++] = 0x80;
115 ibuffer[count++] = 0;
119 ibuffer[count++] = 0x80;
121 ibuffer[count++] = 0;
123 memset(ibuffer, 0, 56 );
127 ibuffer[57] = lsb >> 8;
128 ibuffer[58] = lsb >> 16;
129 ibuffer[59] = lsb >> 24;
131 ibuffer[61] = msb >> 8;
132 ibuffer[62] = msb >> 16;
133 ibuffer[63] = msb >> 24;
138 #if (LIBXCKS_BYTE_ORDER == LIBXCKS_BIG_ENDIAN)
139 #define X(a) do { *p++ = a ; *p++ = a >> 8; \
140 *p++ = a >> 16; *p++ = a >> 24; } while(0)
142 #define X(a) do { *(uint32_t*)p = a ; p += 4; } while(0)
156 void MD4::update(
const uint8_t* buf,
size_t len)
170 for (; len && count < 64; len--)
171 ibuffer[count++] = *buf++;
180 uint8_t tmpBuf[
sizeof(uint32_t) * 16];
181 memcpy(tmpBuf, buf,
sizeof(uint32_t) * 16);
188 for(; len && count < 64; len--)
189 ibuffer[count++] = *buf++;
197 void MD4::transform(uint8_t* data)
200 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
201 #define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
202 #define H(x, y, z) ((x) ^ (y) ^ (z))
205 uint32_t A = this->A;
206 uint32_t B = this->B;
207 uint32_t C = this->C;
208 uint32_t D = this->D;
210 #if (LIBXCKS_BYTE_ORDER == LIBXCKS_BIG_ENDIAN)
214 for(i = 0, p1 = data, p2 = (uint8_t*)in; i < 16; i++, p2 += 4)
223 memcpy(in, data, 64);
227 #define function(a,b,c,d,k,s) a=rol(a+F(b,c,d)+in[k],s);
228 function(A,B,C,D, 0, 3);
229 function(D,A,B,C, 1, 7);
230 function(C,D,A,B, 2,11);
231 function(B,C,D,A, 3,19);
232 function(A,B,C,D, 4, 3);
233 function(D,A,B,C, 5, 7);
234 function(C,D,A,B, 6,11);
235 function(B,C,D,A, 7,19);
236 function(A,B,C,D, 8, 3);
237 function(D,A,B,C, 9, 7);
238 function(C,D,A,B,10,11);
239 function(B,C,D,A,11,19);
240 function(A,B,C,D,12, 3);
241 function(D,A,B,C,13, 7);
242 function(C,D,A,B,14,11);
243 function(B,C,D,A,15,19);
248 #define function(a,b,c,d,k,s) a=rol(a+G(b,c,d)+in[k]+0x5a827999,s);
250 function(A,B,C,D, 0, 3);
251 function(D,A,B,C, 4, 5);
252 function(C,D,A,B, 8, 9);
253 function(B,C,D,A,12,13);
254 function(A,B,C,D, 1, 3);
255 function(D,A,B,C, 5, 5);
256 function(C,D,A,B, 9, 9);
257 function(B,C,D,A,13,13);
258 function(A,B,C,D, 2, 3);
259 function(D,A,B,C, 6, 5);
260 function(C,D,A,B,10, 9);
261 function(B,C,D,A,14,13);
262 function(A,B,C,D, 3, 3);
263 function(D,A,B,C, 7, 5);
264 function(C,D,A,B,11, 9);
265 function(B,C,D,A,15,13);
270 #define function(a,b,c,d,k,s) a=rol(a+H(b,c,d)+in[k]+0x6ed9eba1,s);
272 function(A,B,C,D, 0, 3);
273 function(D,A,B,C, 8, 9);
274 function(C,D,A,B, 4,11);
275 function(B,C,D,A,12,15);
276 function(A,B,C,D, 2, 3);
277 function(D,A,B,C,10, 9);
278 function(C,D,A,B, 6,11);
279 function(B,C,D,A,14,15);
280 function(A,B,C,D, 1, 3);
281 function(D,A,B,C, 9, 9);
282 function(C,D,A,B, 5,11);
283 function(B,C,D,A,13,15);
284 function(A,B,C,D, 3, 3);
285 function(D,A,B,C,11, 9);
286 function(C,D,A,B, 7,11);
287 function(B,C,D,A,15,15);
302 uint8_t* MD4::getValue(uint8_t* buffer)
const
307 memcpy(buffer, md4.
ibuffer, getSize());
Computes the MD4 hash from a byte stream.
void finish()
Process the remaining bytes in the internal buffer and the usual prolog according to the standard.
uint8_t ibuffer[64]
Input buffer.
#define X(a)
Helper function for MD4's computing.