Rsync源码——md5

这个博客详细介绍了Rsync源码中用于计算MD5的实现过程,包括md5_begin、md5_process、md5_update和md5_result等关键函数的代码实现,以及一个简单的测试用例,验证了MD5的正确性。
摘要由CSDN通过智能技术生成
/*
 * RFC 1321 compliant MD5 implementation
 *
 * Copyright (C) 2001-2003 Christophe Devine
 *
 * 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
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, visit the http://fsf.org website.
 */

#include "rsync.h"

void md5_begin(md_context *ctx)
{
	ctx->A = 0x67452301;
	ctx->B = 0xEFCDAB89;
	ctx->C = 0x98BADCFE;
	ctx->D = 0x10325476;

	ctx->totalN = ctx->totalN2 = 0;
}

static void md5_process(md_context *ctx, const uchar data[CSUM_CHUNK])
{
	uint32 X[16], A, B, C, D;

	A = ctx->A;
	B = ctx->B;
	C = ctx->C;
	D = ctx->D;

	X[0] = IVALu(data, 0);
	X[1] = IVALu(data, 4);
	X[2] = IVALu(data, 8);
	X[3] = IVALu(data, 12);
	X[4] = IVALu(data, 16);
	X[5] = IVALu(data, 20);
	X[6] = IVALu(data, 24);
	X[7] = IVALu(data, 28);
	X[8] = IVALu(data, 32);
	X[9] = IVALu(data, 36);
	X[10] = IVALu(data, 40);
	X[11] = IVALu(data, 44);
	X[12] = IVALu(data, 48);
	X[13] = IVALu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值