"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/libglusterfs/src/checksum.c" (16 Sep 2020, 1178 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "checksum.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2   Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
    3   This file is part of GlusterFS.
    4 
    5   This file is licensed to you under your choice of the GNU Lesser
    6   General Public License, version 3 or any later version (LGPLv3 or
    7   later), or the GNU General Public License, version 2 (GPLv2), in all
    8   cases 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  */
   24 uint32_t
   25 gf_rsync_weak_checksum(unsigned char *buf, size_t len)
   26 {
   27     return adler32(0, buf, len);
   28 }
   29 
   30 /*
   31  * The "strong" checksum required for the rsync algorithm.
   32  */
   33 void
   34 gf_rsync_strong_checksum(unsigned char *data, size_t len,
   35                          unsigned char *sha256_md)
   36 {
   37     SHA256((const unsigned char *)data, len, sha256_md);
   38 }
   39 
   40 void
   41 gf_rsync_md5_checksum(unsigned char *data, size_t len, unsigned char *md5)
   42 {
   43     MD5(data, len, md5);
   44 }