]> git.proxmox.com Git - mirror_qemu.git/blame - crypto/blockpriv.h
Drop Emacs local variables lists redundant with .dir-locals.el
[mirror_qemu.git] / crypto / blockpriv.h
CommitLineData
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
21#ifndef QCRYPTO_BLOCK_PRIV_H__
22#define QCRYPTO_BLOCK_PRIV_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; /* In bytes */
39};
40
41struct QCryptoBlockDriver {
42 int (*open)(QCryptoBlock *block,
43 QCryptoBlockOpenOptions *options,
44 QCryptoBlockReadFunc readfunc,
45 void *opaque,
46 unsigned int flags,
47 Error **errp);
48
49 int (*create)(QCryptoBlock *block,
50 QCryptoBlockCreateOptions *options,
51 QCryptoBlockInitFunc initfunc,
52 QCryptoBlockWriteFunc writefunc,
53 void *opaque,
54 Error **errp);
55
56 void (*cleanup)(QCryptoBlock *block);
57
58 int (*encrypt)(QCryptoBlock *block,
59 uint64_t startsector,
60 uint8_t *buf,
61 size_t len,
62 Error **errp);
63 int (*decrypt)(QCryptoBlock *block,
64 uint64_t startsector,
65 uint8_t *buf,
66 size_t len,
67 Error **errp);
68
69 bool (*has_format)(const uint8_t *buf,
70 size_t buflen);
71};
72
73
74int qcrypto_block_decrypt_helper(QCryptoCipher *cipher,
75 size_t niv,
76 QCryptoIVGen *ivgen,
77 int sectorsize,
78 uint64_t startsector,
79 uint8_t *buf,
80 size_t len,
81 Error **errp);
82
83int qcrypto_block_encrypt_helper(QCryptoCipher *cipher,
84 size_t niv,
85 QCryptoIVGen *ivgen,
86 int sectorsize,
87 uint64_t startsector,
88 uint8_t *buf,
89 size_t len,
90 Error **errp);
91
92#endif /* QCRYPTO_BLOCK_PRIV_H__ */