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 const char *optprefix,
45 QCryptoBlockReadFunc readfunc,
46 void *opaque,
47 unsigned int flags,
48 Error **errp);
49
50 int (*create)(QCryptoBlock *block,
51 QCryptoBlockCreateOptions *options,
52 const char *optprefix,
53 QCryptoBlockInitFunc initfunc,
54 QCryptoBlockWriteFunc writefunc,
55 void *opaque,
56 Error **errp);
57
58 int (*get_info)(QCryptoBlock *block,
59 QCryptoBlockInfo *info,
60 Error **errp);
61
62 void (*cleanup)(QCryptoBlock *block);
63
64 int (*encrypt)(QCryptoBlock *block,
65 uint64_t startsector,
66 uint8_t *buf,
67 size_t len,
68 Error **errp);
69 int (*decrypt)(QCryptoBlock *block,
70 uint64_t startsector,
71 uint8_t *buf,
72 size_t len,
73 Error **errp);
74
75 bool (*has_format)(const uint8_t *buf,
76 size_t buflen);
77};
78
79
80int qcrypto_block_decrypt_helper(QCryptoCipher *cipher,
81 size_t niv,
82 QCryptoIVGen *ivgen,
83 int sectorsize,
84 uint64_t startsector,
85 uint8_t *buf,
86 size_t len,
87 Error **errp);
88
89int qcrypto_block_encrypt_helper(QCryptoCipher *cipher,
90 size_t niv,
91 QCryptoIVGen *ivgen,
92 int sectorsize,
93 uint64_t startsector,
94 uint8_t *buf,
95 size_t len,
96 Error **errp);
97
98#endif
99