librsync  2.3.4
Data Structures | Typedefs | Enumerations | Functions
checksum.h File Reference

Abstract wrappers around different weaksum and strongsum implementations. More...

Include dependency graph for checksum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  weaksum
 Abstract wrapper around weaksum implementations. More...
 

Typedefs

typedef struct weaksum weaksum_t
 Abstract wrapper around weaksum implementations. More...
 

Enumerations

enum  weaksum_kind_t { RS_ROLLSUM , RS_RABINKARP }
 Weaksum implementations. More...
 
enum  strongsum_kind_t { RS_MD4 , RS_BLAKE2 }
 Strongsum implementations. More...
 

Functions

static void weaksum_reset (weaksum_t *sum)
 
static void weaksum_init (weaksum_t *sum, weaksum_kind_t kind)
 
static size_t weaksum_count (weaksum_t *sum)
 
static void weaksum_update (weaksum_t *sum, const unsigned char *buf, size_t len)
 
static void weaksum_rotate (weaksum_t *sum, unsigned char out, unsigned char in)
 
static void weaksum_rollin (weaksum_t *sum, unsigned char in)
 
static void weaksum_rollout (weaksum_t *sum, unsigned char out)
 
static rs_weak_sum_t weaksum_digest (weaksum_t *sum)
 
rs_weak_sum_t rs_calc_weak_sum (weaksum_kind_t kind, void const *buf, size_t len)
 Calculate a weaksum. More...
 
void rs_calc_strong_sum (strongsum_kind_t kind, void const *buf, size_t len, rs_strong_sum_t *sum)
 Calculate a strongsum. More...
 

Detailed Description

Abstract wrappers around different weaksum and strongsum implementations.

Definition in file checksum.h.

Typedef Documentation

◆ weaksum_t

typedef struct weaksum weaksum_t

Abstract wrapper around weaksum implementations.

This is a polymorphic interface to the different rollsum implementations.

Historically rollsum methods were implemented as static inline functions because they were small and needed to be fast. Now that we need to call different methods for different rollsum implementations, they are getting more complicated. Is it better to delegate calls to the right implementation using static inline switch statements, or stop inlining them and use virtual method pointers? Tests suggest inlined switch statements is faster.

Enumeration Type Documentation

◆ weaksum_kind_t

Weaksum implementations.

Definition at line 35 of file checksum.h.

◆ strongsum_kind_t

Strongsum implementations.

Definition at line 41 of file checksum.h.

Function Documentation

◆ weaksum_reset()

static void weaksum_reset ( weaksum_t sum)
inlinestatic

Definition at line 64 of file checksum.h.

◆ weaksum_init()

static void weaksum_init ( weaksum_t sum,
weaksum_kind_t  kind 
)
inlinestatic

Definition at line 72 of file checksum.h.

◆ weaksum_count()

static size_t weaksum_count ( weaksum_t sum)
inlinestatic

Definition at line 79 of file checksum.h.

◆ weaksum_update()

static void weaksum_update ( weaksum_t sum,
const unsigned char *  buf,
size_t  len 
)
inlinestatic

Definition at line 85 of file checksum.h.

◆ weaksum_rotate()

static void weaksum_rotate ( weaksum_t sum,
unsigned char  out,
unsigned char  in 
)
inlinestatic

Definition at line 94 of file checksum.h.

◆ weaksum_rollin()

static void weaksum_rollin ( weaksum_t sum,
unsigned char  in 
)
inlinestatic

Definition at line 103 of file checksum.h.

◆ weaksum_rollout()

static void weaksum_rollout ( weaksum_t sum,
unsigned char  out 
)
inlinestatic

Definition at line 111 of file checksum.h.

◆ weaksum_digest()

static rs_weak_sum_t weaksum_digest ( weaksum_t sum)
inlinestatic

Definition at line 119 of file checksum.h.

◆ rs_calc_weak_sum()

rs_weak_sum_t rs_calc_weak_sum ( weaksum_kind_t  kind,
void const *  buf,
size_t  len 
)

Calculate a weaksum.

Note this does not apply mix32() to rollsum digests, unlike weaksum_digest(). This is because rollsums are stored raw without mix32() applied for backwards-compatibility, but we apply mix32() when adding them into a signature and when getting the digest for calculating deltas.

Calculate a weaksum.

Definition at line 34 of file checksum.c.

◆ rs_calc_strong_sum()

void rs_calc_strong_sum ( strongsum_kind_t  kind,
void const *  buf,
size_t  len,
rs_strong_sum_t *  sum 
)

Calculate a strongsum.

Calculate a strongsum.

In plain rsync, the checksum is perturbed by a seed value. This is used when retrying a failed transmission: we've discovered that the hashes collided at some point, so we're going to try again with different hashes to see if we can get it right. (Check tridge's thesis for details and to see if that's correct.)

Since we can't retry I'm not sure if it's very useful for librsync, except perhaps as protection against hash collision attacks.

Definition at line 59 of file checksum.c.