glusterfs
44 строки · 1.2 Кб
1/*
2Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
3This file is part of GlusterFS.
4
5This file is licensed to you under your choice of the GNU Lesser
6General Public License, version 3 or any later version (LGPLv3 or
7later), or the GNU General Public License, version 2 (GPLv2), in all
8cases as published by the Free Software Foundation.
9*/
10
11#include <openssl/md5.h>
12#include <openssl/sha.h>
13#include <zlib.h>
14#include <stdint.h>
15#include <string.h>
16
17/*
18* The "weak" checksum required for the rsync algorithm.
19*
20* Note: these functions are only called to compute checksums on
21* pathnames; they don't need to handle arbitrarily long strings of
22* data. Thus int32_t and uint32_t are sufficient
23*/
24uint32_t
25gf_rsync_weak_checksum(unsigned char *buf, size_t len)
26{
27return adler32(0, buf, len);
28}
29
30/*
31* The "strong" checksum required for the rsync algorithm.
32*/
33void
34gf_rsync_strong_checksum(unsigned char *data, size_t len,
35unsigned char *sha256_md)
36{
37SHA256((const unsigned char *)data, len, sha256_md);
38}
39
40void
41gf_rsync_md5_checksum(unsigned char *data, size_t len, unsigned char *md5)
42{
43MD5(data, len, md5);
44}
45