version 1.1, 2012/02/17 15:09:30
|
version 1.1.1.2, 2021/03/17 00:32:36
|
Line 2
|
Line 2
|
* RFC 1321 compliant MD5 implementation |
* RFC 1321 compliant MD5 implementation |
* |
* |
* Copyright (C) 2001-2003 Christophe Devine |
* Copyright (C) 2001-2003 Christophe Devine |
|
* Copyright (C) 2007-2020 Wayne Davison |
* |
* |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
Line 19
|
Line 20
|
|
|
#include "rsync.h" |
#include "rsync.h" |
|
|
|
#ifndef USE_OPENSSL |
void md5_begin(md_context *ctx) |
void md5_begin(md_context *ctx) |
{ |
{ |
ctx->A = 0x67452301; |
ctx->A = 0x67452301; |
Line 146 static void md5_process(md_context *ctx, const uchar d
|
Line 148 static void md5_process(md_context *ctx, const uchar d
|
ctx->D += D; |
ctx->D += D; |
} |
} |
|
|
|
#if defined HAVE_ASM && CSUM_CHUNK == 64 |
|
extern void md5_process_asm(md_context *ctx, const void *data, size_t num); |
|
#endif |
|
|
void md5_update(md_context *ctx, const uchar *input, uint32 length) |
void md5_update(md_context *ctx, const uchar *input, uint32 length) |
{ |
{ |
uint32 left, fill; |
uint32 left, fill; |
Line 170 void md5_update(md_context *ctx, const uchar *input, u
|
Line 176 void md5_update(md_context *ctx, const uchar *input, u
|
left = 0; |
left = 0; |
} |
} |
|
|
|
#if defined HAVE_ASM && CSUM_CHUNK == 64 |
|
if (length >= CSUM_CHUNK) { |
|
uint32 chunks = length / CSUM_CHUNK; |
|
md5_process_asm(ctx, input, chunks); |
|
length -= chunks * CSUM_CHUNK; |
|
input += chunks * CSUM_CHUNK; |
|
} |
|
#else |
while (length >= CSUM_CHUNK) { |
while (length >= CSUM_CHUNK) { |
md5_process(ctx, input); |
md5_process(ctx, input); |
length -= CSUM_CHUNK; |
length -= CSUM_CHUNK; |
input += CSUM_CHUNK; |
input += CSUM_CHUNK; |
} |
} |
|
#endif |
|
|
if (length) |
if (length) |
memcpy(ctx->buffer + left, input, length); |
memcpy(ctx->buffer + left, input, length); |
Line 206 void md5_result(md_context *ctx, uchar digest[MD5_DIGE
|
Line 221 void md5_result(md_context *ctx, uchar digest[MD5_DIGE
|
SIVALu(digest, 8, ctx->C); |
SIVALu(digest, 8, ctx->C); |
SIVALu(digest, 12, ctx->D); |
SIVALu(digest, 12, ctx->D); |
} |
} |
|
#endif |
|
|
|
#ifdef TEST_MD5 |
|
|
void get_md5(uchar *out, const uchar *input, int n) |
void get_md5(uchar *out, const uchar *input, int n) |
{ |
{ |
md_context ctx; |
md_context ctx; |
Line 214 void get_md5(uchar *out, const uchar *input, int n)
|
Line 232 void get_md5(uchar *out, const uchar *input, int n)
|
md5_update(&ctx, input, n); |
md5_update(&ctx, input, n); |
md5_result(&ctx, out); |
md5_result(&ctx, out); |
} |
} |
|
|
#ifdef TEST_MD5 |
|
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |