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#include "qemu/thread.h"
26
27typedef struct QCryptoBlockDriver QCryptoBlockDriver;
28
29struct QCryptoBlock {
30 QCryptoBlockFormat format;
31
32 const QCryptoBlockDriver *driver;
33 void *opaque;
34
35 QCryptoCipher **ciphers;
36 size_t n_ciphers;
37 size_t n_free_ciphers;
38 QCryptoIVGen *ivgen;
39 QemuMutex mutex;
40
41 QCryptoHashAlgorithm kdfhash;
42 size_t niv;
43 uint64_t payload_offset;
44 uint64_t sector_size;
45};
46
47struct QCryptoBlockDriver {
48 int (*open)(QCryptoBlock *block,
49 QCryptoBlockOpenOptions *options,
50 const char *optprefix,
51 QCryptoBlockReadFunc readfunc,
52 void *opaque,
53 unsigned int flags,
54 size_t n_threads,
55 Error **errp);
56
57 int (*create)(QCryptoBlock *block,
58 QCryptoBlockCreateOptions *options,
59 const char *optprefix,
60 QCryptoBlockInitFunc initfunc,
61 QCryptoBlockWriteFunc writefunc,
62 void *opaque,
63 Error **errp);
64
65 int (*get_info)(QCryptoBlock *block,
66 QCryptoBlockInfo *info,
67 Error **errp);
68
69 void (*cleanup)(QCryptoBlock *block);
70
71 int (*encrypt)(QCryptoBlock *block,
72 uint64_t startsector,
73 uint8_t *buf,
74 size_t len,
75 Error **errp);
76 int (*decrypt)(QCryptoBlock *block,
77 uint64_t startsector,
78 uint8_t *buf,
79 size_t len,
80 Error **errp);
81
82 bool (*has_format)(const uint8_t *buf,
83 size_t buflen);
84};
85
86
87int qcrypto_block_cipher_decrypt_helper(QCryptoCipher *cipher,
88 size_t niv,
89 QCryptoIVGen *ivgen,
90 int sectorsize,
91 uint64_t offset,
92 uint8_t *buf,
93 size_t len,
94 Error **errp);
95
96int qcrypto_block_cipher_encrypt_helper(QCryptoCipher *cipher,
97 size_t niv,
98 QCryptoIVGen *ivgen,
99 int sectorsize,
100 uint64_t offset,
101 uint8_t *buf,
102 size_t len,
103 Error **errp);
104
105int qcrypto_block_decrypt_helper(QCryptoBlock *block,
106 int sectorsize,
107 uint64_t offset,
108 uint8_t *buf,
109 size_t len,
110 Error **errp);
111
112int qcrypto_block_encrypt_helper(QCryptoBlock *block,
113 int sectorsize,
114 uint64_t offset,
115 uint8_t *buf,
116 size_t len,
117 Error **errp);
118
119int qcrypto_block_init_cipher(QCryptoBlock *block,
120 QCryptoCipherAlgorithm alg,
121 QCryptoCipherMode mode,
122 const uint8_t *key, size_t nkey,
123 size_t n_threads, Error **errp);
124
125void qcrypto_block_free_cipher(QCryptoBlock *block);
126
127#endif
128