$treeview $search $mathjax $extrastylesheet
librsync
2.0.2
$projectbrief
|
$projectbrief
|
$searchbox |
00001 # File formats {#page_formats} 00002 00003 ## Generalities 00004 00005 There are two file formats used by `librsync` and `rdiff`: the 00006 *signature* file, which summarizes a data file, and the *delta* file, 00007 which describes the edits from one data file to another. 00008 00009 librsync does not know or care about any formats in the data files. 00010 00011 All integers are big-endian. 00012 00013 ## Magic numbers 00014 00015 All librsync files start with a `uint32` magic number identifying them. These are declared in `librsync.h`: 00016 00017 ``` 00018 /** A delta file. At present, there's only one delta format. **/ 00019 RS_DELTA_MAGIC = 0x72730236, /* r s \2 6 */ 00020 00021 /** 00022 * A signature file with MD4 signatures. Backward compatible with 00023 * librsync < 1.0, but strongly deprecated because it creates a security 00024 * vulnerability on files containing partly untrusted data. See 00025 * <https://github.com/librsync/librsync/issues/5>. 00026 **/ 00027 RS_MD4_SIG_MAGIC = 0x72730136, /* r s \1 6 */ 00028 00029 /** 00030 * A signature file using the BLAKE2 hash. Supported from librsync 1.0. 00031 **/ 00032 RS_BLAKE2_SIG_MAGIC = 0x72730137 /* r s \1 7 */ 00033 ``` 00034 00035 ## Signatures 00036 00037 Signatures consist of a header followed by a number of block 00038 signatures. 00039 00040 Each block signature gives signature hashes for one block of 00041 `block_len` bytes from the input data file. The final data block 00042 may be shorter. The number of blocks in the signature is therefore 00043 00044 ceil(input_len/block_len) 00045 00046 The signature header is (see `rs_sig_s_header`): 00047 00048 u32 magic; // either RS_MD4_SIG_MAGIC or RS_BLAKE2_SIG_MAGIC 00049 u32 block_len; // bytes per block 00050 u32 strong_sum_len; // bytes per strong sum in each block 00051 00052 The block signature contains a rolling or weak checksum used to find 00053 moved data, and a strong hash used to check the match is correct. 00054 The weak checksum is computed as in `rollsum.c`. The strong hash is 00055 either MD4 or BLAKE2 depending on the magic number. 00056 00057 To make the signatures smaller at a cost of a greater chance of collisions, 00058 the `strong_sum_len` in the header can cause the strong sum to be truncated 00059 to the left after computation. 00060 00061 Each signature block format is (see `rs_sig_do_block`): 00062 00063 u32 weak_sum; 00064 u8[strong_sum_len] strong_sum; 00065 00066 ## Delta files 00067 00068 TODO(https://github.com/librsync/librsync/issues/46): Document delta format.