]> git.proxmox.com Git - proxmox-backup.git/blame - src/backup/file_formats.rs
log rotate: do NOT overwrite file with possible writers
[proxmox-backup.git] / src / backup / file_formats.rs
CommitLineData
ba01828d
DM
1use endian_trait::Endian;
2
991abfa8
DM
3// WARNING: PLEASE DO NOT MODIFY THOSE MAGIC VALUES
4
c74c074b
DM
5// openssl::sha::sha256(b"Proxmox Backup Catalog file v1.0")[0..8]
6pub const PROXMOX_CATALOG_FILE_MAGIC_1_0: [u8; 8] = [145, 253, 96, 249, 196, 103, 88, 213];
7
991abfa8 8// openssl::sha::sha256(b"Proxmox Backup uncompressed blob v1.0")[0..8]
1cbdfd19 9pub const UNCOMPRESSED_BLOB_MAGIC_1_0: [u8; 8] = [66, 171, 56, 7, 190, 131, 112, 161];
991abfa8
DM
10
11//openssl::sha::sha256(b"Proxmox Backup zstd compressed blob v1.0")[0..8]
1cbdfd19 12pub const COMPRESSED_BLOB_MAGIC_1_0: [u8; 8] = [49, 185, 88, 66, 111, 182, 163, 127];
991abfa8
DM
13
14// openssl::sha::sha256(b"Proxmox Backup encrypted blob v1.0")[0..8]
1cbdfd19 15pub const ENCRYPTED_BLOB_MAGIC_1_0: [u8; 8] = [123, 103, 133, 190, 34, 45, 76, 240];
991abfa8
DM
16
17// openssl::sha::sha256(b"Proxmox Backup zstd compressed encrypted blob v1.0")[0..8]
1cbdfd19 18pub const ENCR_COMPR_BLOB_MAGIC_1_0: [u8; 8] = [230, 89, 27, 191, 11, 191, 216, 11];
991abfa8
DM
19
20// openssl::sha::sha256(b"Proxmox Backup fixed sized chunk index v1.0")[0..8]
1cbdfd19 21pub const FIXED_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [47, 127, 65, 237, 145, 253, 15, 205];
991abfa8
DM
22
23// openssl::sha::sha256(b"Proxmox Backup dynamic sized chunk index v1.0")[0..8]
1cbdfd19 24pub const DYNAMIC_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [28, 145, 78, 165, 25, 186, 179, 205];
991abfa8 25
27042ce6
DM
26/// Data blob binary storage format
27///
28/// The format start with a 8 byte magic number to identify the type,
29/// followed by a 4 byte CRC. This CRC is used on the server side to
30/// detect file corruption (computed when upload data), so there is
31/// usually no need to compute it on the client side.
32///
33/// Unencrypted blobs simply contain the CRC, followed by the
34/// (compressed) data.
35///
36/// (MAGIC || CRC32 || Data)
37///
38/// This is basically the same format we use for chunks, but
39/// with other magic numbers so that we can distinguish them.
ba01828d 40#[derive(Endian)]
991abfa8
DM
41#[repr(C,packed)]
42pub struct DataBlobHeader {
43 pub magic: [u8; 8],
44 pub crc: [u8; 4],
45}
46
27042ce6
DM
47/// Encrypted data blob binary storage format
48///
49/// The ``DataBlobHeader`` for encrypted blobs additionally contains
50/// a 16 byte IV, followed by a 16 byte Authenticated Encyrypten (AE)
51/// tag, followed by the encrypted data:
52///
53/// (MAGIC || CRC32 || IV || TAG || EncryptedData).
ba01828d 54#[derive(Endian)]
991abfa8
DM
55#[repr(C,packed)]
56pub struct EncryptedDataBlobHeader {
57 pub head: DataBlobHeader,
58 pub iv: [u8; 16],
59 pub tag: [u8; 16],
60}
61
c638542b
DM
62/// Header size for different file types
63///
64/// Panics on unknown magic numbers.
65pub fn header_size(magic: &[u8; 8]) -> usize {
66 match magic {
c638542b
DM
67 &UNCOMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
68 &COMPRESSED_BLOB_MAGIC_1_0 => std::mem::size_of::<DataBlobHeader>(),
69 &ENCRYPTED_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
70 &ENCR_COMPR_BLOB_MAGIC_1_0 => std::mem::size_of::<EncryptedDataBlobHeader>(),
c638542b
DM
71 _ => panic!("unknown blob magic"),
72 }
73}