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 (*amend)(QCryptoBlock *block,
66 QCryptoBlockReadFunc readfunc,
67 QCryptoBlockWriteFunc writefunc,
68 void *opaque,
69 QCryptoBlockAmendOptions *options,
70 bool force,
71 Error **errp);
72
73 int (*get_info)(QCryptoBlock *block,
74 QCryptoBlockInfo *info,
75 Error **errp);
76
77 void (*cleanup)(QCryptoBlock *block);
78
79 int (*encrypt)(QCryptoBlock *block,
80 uint64_t startsector,
81 uint8_t *buf,
82 size_t len,
83 Error **errp);
84 int (*decrypt)(QCryptoBlock *block,
85 uint64_t startsector,
86 uint8_t *buf,
87 size_t len,
88 Error **errp);
89
90 bool (*has_format)(const uint8_t *buf,
91 size_t buflen);
92};
93
94
95int qcrypto_block_cipher_decrypt_helper(QCryptoCipher *cipher,
96 size_t niv,
97 QCryptoIVGen *ivgen,
98 int sectorsize,
99 uint64_t offset,
100 uint8_t *buf,
101 size_t len,
102 Error **errp);
103
104int qcrypto_block_cipher_encrypt_helper(QCryptoCipher *cipher,
105 size_t niv,
106 QCryptoIVGen *ivgen,
107 int sectorsize,
108 uint64_t offset,
109 uint8_t *buf,
110 size_t len,
111 Error **errp);
112
113int qcrypto_block_decrypt_helper(QCryptoBlock *block,
114 int sectorsize,
115 uint64_t offset,
116 uint8_t *buf,
117 size_t len,
118 Error **errp);
119
120int qcrypto_block_encrypt_helper(QCryptoBlock *block,
121 int sectorsize,
122 uint64_t offset,
123 uint8_t *buf,
124 size_t len,
125 Error **errp);
126
127int qcrypto_block_init_cipher(QCryptoBlock *block,
128 QCryptoCipherAlgorithm alg,
129 QCryptoCipherMode mode,
130 const uint8_t *key, size_t nkey,
131 size_t n_threads, Error **errp);
132
133void qcrypto_block_free_cipher(QCryptoBlock *block);
134
135#endif
136