2 * QEMU Crypto block device encryption
4 * Copyright (c) 2015-2016 Red Hat, Inc.
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.1 of the License, or (at your option) any later version.
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.
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/>.
21 #ifndef QCRYPTO_BLOCKPRIV_H
22 #define QCRYPTO_BLOCKPRIV_H
24 #include "crypto/block.h"
25 #include "qemu/thread.h"
27 typedef struct QCryptoBlockDriver QCryptoBlockDriver
;
30 QCryptoBlockFormat format
;
32 const QCryptoBlockDriver
*driver
;
35 QCryptoCipher
**ciphers
;
37 size_t n_free_ciphers
;
41 QCryptoHashAlgorithm kdfhash
;
43 uint64_t payload_offset
; /* In bytes */
44 uint64_t sector_size
; /* In bytes */
46 bool detached_header
; /* True if disk has a detached LUKS header */
49 struct QCryptoBlockDriver
{
50 int (*open
)(QCryptoBlock
*block
,
51 QCryptoBlockOpenOptions
*options
,
52 const char *optprefix
,
53 QCryptoBlockReadFunc readfunc
,
59 int (*create
)(QCryptoBlock
*block
,
60 QCryptoBlockCreateOptions
*options
,
61 const char *optprefix
,
62 QCryptoBlockInitFunc initfunc
,
63 QCryptoBlockWriteFunc writefunc
,
67 int (*amend
)(QCryptoBlock
*block
,
68 QCryptoBlockReadFunc readfunc
,
69 QCryptoBlockWriteFunc writefunc
,
71 QCryptoBlockAmendOptions
*options
,
75 int (*get_info
)(QCryptoBlock
*block
,
76 QCryptoBlockInfo
*info
,
79 void (*cleanup
)(QCryptoBlock
*block
);
81 int (*encrypt
)(QCryptoBlock
*block
,
86 int (*decrypt
)(QCryptoBlock
*block
,
92 bool (*has_format
)(const uint8_t *buf
,
97 int qcrypto_block_cipher_decrypt_helper(QCryptoCipher
*cipher
,
106 int qcrypto_block_cipher_encrypt_helper(QCryptoCipher
*cipher
,
115 int qcrypto_block_decrypt_helper(QCryptoBlock
*block
,
122 int qcrypto_block_encrypt_helper(QCryptoBlock
*block
,
129 int qcrypto_block_init_cipher(QCryptoBlock
*block
,
130 QCryptoCipherAlgorithm alg
,
131 QCryptoCipherMode mode
,
132 const uint8_t *key
, size_t nkey
,
133 size_t n_threads
, Error
**errp
);
135 void qcrypto_block_free_cipher(QCryptoBlock
*block
);
137 #endif /* QCRYPTO_BLOCKPRIV_H */