1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "qemu/osdep.h"
22#include "qemu/bswap.h"
23#include "ivgen-plain.h"
24
25static int qcrypto_ivgen_plain_init(QCryptoIVGen *ivgen,
26 const uint8_t *key, size_t nkey,
27 Error **errp)
28{
29 return 0;
30}
31
32static int qcrypto_ivgen_plain_calculate(QCryptoIVGen *ivgen,
33 uint64_t sector,
34 uint8_t *iv, size_t niv,
35 Error **errp)
36{
37 size_t ivprefix;
38 uint32_t shortsector = cpu_to_le32((sector & 0xffffffff));
39 ivprefix = sizeof(shortsector);
40 if (ivprefix > niv) {
41 ivprefix = niv;
42 }
43 memcpy(iv, &shortsector, ivprefix);
44 if (ivprefix < niv) {
45 memset(iv + ivprefix, 0, niv - ivprefix);
46 }
47 return 0;
48}
49
50static void qcrypto_ivgen_plain_cleanup(QCryptoIVGen *ivgen)
51{
52}
53
54
55struct QCryptoIVGenDriver qcrypto_ivgen_plain = {
56 .init = qcrypto_ivgen_plain_init,
57 .calculate = qcrypto_ivgen_plain_calculate,
58 .cleanup = qcrypto_ivgen_plain_cleanup,
59};
60
61