]>
Commit | Line | Data |
---|---|---|
7d969014 DB |
1 | /* |
2 | * QEMU Crypto block device encryption | |
3 | * | |
4 | * Copyright (c) 2015-2016 Red Hat, Inc. | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | * | |
19 | */ | |
20 | ||
121d0712 MA |
21 | #ifndef QCRYPTO_BLOCKPRIV_H |
22 | #define QCRYPTO_BLOCKPRIV_H | |
7d969014 DB |
23 | |
24 | #include "crypto/block.h" | |
25 | ||
26 | typedef struct QCryptoBlockDriver QCryptoBlockDriver; | |
27 | ||
28 | struct 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; /* In bytes */ | |
850f49de | 39 | uint64_t sector_size; /* In bytes */ |
7d969014 DB |
40 | }; |
41 | ||
42 | struct QCryptoBlockDriver { | |
43 | int (*open)(QCryptoBlock *block, | |
44 | QCryptoBlockOpenOptions *options, | |
1cd9a787 | 45 | const char *optprefix, |
7d969014 DB |
46 | QCryptoBlockReadFunc readfunc, |
47 | void *opaque, | |
48 | unsigned int flags, | |
49 | Error **errp); | |
50 | ||
51 | int (*create)(QCryptoBlock *block, | |
52 | QCryptoBlockCreateOptions *options, | |
1cd9a787 | 53 | const char *optprefix, |
7d969014 DB |
54 | QCryptoBlockInitFunc initfunc, |
55 | QCryptoBlockWriteFunc writefunc, | |
56 | void *opaque, | |
57 | Error **errp); | |
58 | ||
40c85028 DB |
59 | int (*get_info)(QCryptoBlock *block, |
60 | QCryptoBlockInfo *info, | |
61 | Error **errp); | |
62 | ||
7d969014 DB |
63 | void (*cleanup)(QCryptoBlock *block); |
64 | ||
65 | int (*encrypt)(QCryptoBlock *block, | |
66 | uint64_t startsector, | |
67 | uint8_t *buf, | |
68 | size_t len, | |
69 | Error **errp); | |
70 | int (*decrypt)(QCryptoBlock *block, | |
71 | uint64_t startsector, | |
72 | uint8_t *buf, | |
73 | size_t len, | |
74 | Error **errp); | |
75 | ||
76 | bool (*has_format)(const uint8_t *buf, | |
77 | size_t buflen); | |
78 | }; | |
79 | ||
80 | ||
81 | int qcrypto_block_decrypt_helper(QCryptoCipher *cipher, | |
82 | size_t niv, | |
83 | QCryptoIVGen *ivgen, | |
84 | int sectorsize, | |
4609742a | 85 | uint64_t offset, |
7d969014 DB |
86 | uint8_t *buf, |
87 | size_t len, | |
88 | Error **errp); | |
89 | ||
90 | int qcrypto_block_encrypt_helper(QCryptoCipher *cipher, | |
91 | size_t niv, | |
92 | QCryptoIVGen *ivgen, | |
93 | int sectorsize, | |
4609742a | 94 | uint64_t offset, |
7d969014 DB |
95 | uint8_t *buf, |
96 | size_t len, | |
97 | Error **errp); | |
98 | ||
121d0712 | 99 | #endif /* QCRYPTO_BLOCKPRIV_H */ |