1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef QCRYPTO_BLOCKPRIV_H
22#define QCRYPTO_BLOCKPRIV_H
23
24#include "crypto/block.h"
25
26typedef struct QCryptoBlockDriver QCryptoBlockDriver;
27
28struct QCryptoBlock {
29 QCryptoBlockFormat format;
30
31 const QCryptoBlockDriver *driver;
32 void *opaque;
33
34 QCryptoCipher *cipher;
35 QCryptoIVGen *ivgen;
36 QCryptoHashAlgorithm kdfhash;
37 size_t niv;
38 uint64_t payload_offset;
39};
40
41struct QCryptoBlockDriver {
42 int (*open)(QCryptoBlock *block,
43 QCryptoBlockOpenOptions *options,
44 QCryptoBlockReadFunc readfunc,
45 void *opaque,
46 unsigned int flags,
47 Error **errp);
48
49 int (*create)(QCryptoBlock *block,
50 QCryptoBlockCreateOptions *options,
51 QCryptoBlockInitFunc initfunc,
52 QCryptoBlockWriteFunc writefunc,
53 void *opaque,
54 Error **errp);
55
56 int (*get_info)(QCryptoBlock *block,
57 QCryptoBlockInfo *info,
58 Error **errp);
59
60 void (*cleanup)(QCryptoBlock *block);
61
62 int (*encrypt)(QCryptoBlock *block,
63 uint64_t startsector,
64 uint8_t *buf,
65 size_t len,
66 Error **errp);
67 int (*decrypt)(QCryptoBlock *block,
68 uint64_t startsector,
69 uint8_t *buf,
70 size_t len,
71 Error **errp);
72
73 bool (*has_format)(const uint8_t *buf,
74 size_t buflen);
75};
76
77
78int qcrypto_block_decrypt_helper(QCryptoCipher *cipher,
79 size_t niv,
80 QCryptoIVGen *ivgen,
81 int sectorsize,
82 uint64_t startsector,
83 uint8_t *buf,
84 size_t len,
85 Error **errp);
86
87int qcrypto_block_encrypt_helper(QCryptoCipher *cipher,
88 size_t niv,
89 QCryptoIVGen *ivgen,
90 int sectorsize,
91 uint64_t startsector,
92 uint8_t *buf,
93 size_t len,
94 Error **errp);
95
96#endif
97