Browse Source

Drobne poprawki

legacy
Marek 10 years ago
parent
commit
ea340e8f8e
  1. 10
      md5.cpp

10
md5.cpp

@ -6,7 +6,6 @@
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
#define STEP(f, a, b, c, d, x, t, s) \
(a) += f((b), (c), (d)) + (x) + (t); \
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
@ -75,7 +74,6 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size){
STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
@ -92,7 +90,6 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size){
STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
@ -109,7 +106,6 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size){
STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
@ -161,12 +157,10 @@ void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size){
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
ctx->hi++;
ctx->hi += size >> 29;
used = saved_lo & 0x3f;
if (used){
free = 64 - used;
if (size < free) {
memcpy(&ctx->buffer[used], data, size);
return;
@ -188,7 +182,6 @@ void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size){
void MD5_Final(unsigned char *result, MD5_CTX *ctx){
unsigned long used, free;
used = ctx->lo & 0x3f;
ctx->buffer[used++] = 0x80;
free = 64 - used;
@ -211,9 +204,7 @@ void MD5_Final(unsigned char *result, MD5_CTX *ctx){
ctx->buffer[61] = ctx->hi >> 8;
ctx->buffer[62] = ctx->hi >> 16;
ctx->buffer[63] = ctx->hi >> 24;
body(ctx, ctx->buffer, 64);
result[0] = ctx->a;
result[1] = ctx->a >> 8;
result[2] = ctx->a >> 16;
@ -230,7 +221,6 @@ void MD5_Final(unsigned char *result, MD5_CTX *ctx){
result[13] = ctx->d >> 8;
result[14] = ctx->d >> 16;
result[15] = ctx->d >> 24;
memset(ctx, 0, sizeof(*ctx));
}
#else

Loading…
Cancel
Save