$treeview $search $mathjax $extrastylesheet
librsync
2.3.1
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 * 00003 * librsync -- the library for network deltas 00004 * 00005 * Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net> 00006 * Copyright (C) 1996 by Andrew Tridgell 00007 * Copyright (C) 1996 by Paul Mackerras 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU Lesser General Public License as published by 00011 * the Free Software Foundation; either version 2.1 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00022 */ 00023 00024 #include "config.h" 00025 #include "checksum.h" 00026 #include "blake2.h" 00027 00028 LIBRSYNC_EXPORT const int RS_MD4_SUM_LENGTH = 16; 00029 LIBRSYNC_EXPORT const int RS_BLAKE2_SUM_LENGTH = 32; 00030 00031 /** A simple 32bit checksum that can be incrementally updated. */ 00032 rs_weak_sum_t rs_calc_weak_sum(weaksum_kind_t kind, void const *buf, size_t len) 00033 { 00034 if (kind == RS_ROLLSUM) { 00035 Rollsum sum; 00036 RollsumInit(&sum); 00037 RollsumUpdate(&sum, buf, len); 00038 return RollsumDigest(&sum); 00039 } else { 00040 rabinkarp_t sum; 00041 rabinkarp_init(&sum); 00042 rabinkarp_update(&sum, buf, len); 00043 return rabinkarp_digest(&sum); 00044 } 00045 } 00046 00047 /** Calculate and store into SUM a strong checksum. 00048 * 00049 * In plain rsync, the checksum is perturbed by a seed value. This is used when 00050 * retrying a failed transmission: we've discovered that the hashes collided at 00051 * some point, so we're going to try again with different hashes to see if we 00052 * can get it right. (Check tridge's thesis for details and to see if that's 00053 * correct.) 00054 * 00055 * Since we can't retry I'm not sure if it's very useful for librsync, except 00056 * perhaps as protection against hash collision attacks. */ 00057 void rs_calc_strong_sum(strongsum_kind_t kind, void const *buf, size_t len, 00058 rs_strong_sum_t *sum) 00059 { 00060 if (kind == RS_MD4) { 00061 rs_mdfour((unsigned char *)sum, buf, len); 00062 } else { 00063 blake2b_state ctx; 00064 blake2b_init(&ctx, RS_MAX_STRONG_SUM_LENGTH); 00065 blake2b_update(&ctx, (const uint8_t *)buf, len); 00066 blake2b_final(&ctx, (uint8_t *)sum, RS_MAX_STRONG_SUM_LENGTH); 00067 } 00068 }