2 * QEMU Crypto block IV generator
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 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 #include "qemu/osdep.h"
22 #include "crypto/ivgenpriv.h"
23 #include "crypto/ivgen-plain.h"
24 #include "crypto/ivgen-plain64.h"
25 #include "crypto/ivgen-essiv.h"
28 QCryptoIVGen
*qcrypto_ivgen_new(QCryptoIVGenAlgorithm alg
,
29 QCryptoCipherAlgorithm cipheralg
,
30 QCryptoHashAlgorithm hash
,
31 const uint8_t *key
, size_t nkey
,
34 QCryptoIVGen
*ivgen
= g_new0(QCryptoIVGen
, 1);
36 ivgen
->algorithm
= alg
;
37 ivgen
->cipher
= cipheralg
;
41 case QCRYPTO_IVGEN_ALG_PLAIN
:
42 ivgen
->driver
= &qcrypto_ivgen_plain
;
44 case QCRYPTO_IVGEN_ALG_PLAIN64
:
45 ivgen
->driver
= &qcrypto_ivgen_plain64
;
47 case QCRYPTO_IVGEN_ALG_ESSIV
:
48 ivgen
->driver
= &qcrypto_ivgen_essiv
;
51 error_setg(errp
, "Unknown block IV generator algorithm %d", alg
);
56 if (ivgen
->driver
->init(ivgen
, key
, nkey
, errp
) < 0) {
65 int qcrypto_ivgen_calculate(QCryptoIVGen
*ivgen
,
67 uint8_t *iv
, size_t niv
,
70 return ivgen
->driver
->calculate(ivgen
, sector
, iv
, niv
, errp
);
74 QCryptoIVGenAlgorithm
qcrypto_ivgen_get_algorithm(QCryptoIVGen
*ivgen
)
76 return ivgen
->algorithm
;
80 QCryptoCipherAlgorithm
qcrypto_ivgen_get_cipher(QCryptoIVGen
*ivgen
)
86 QCryptoHashAlgorithm
qcrypto_ivgen_get_hash(QCryptoIVGen
*ivgen
)
92 void qcrypto_ivgen_free(QCryptoIVGen
*ivgen
)
97 ivgen
->driver
->cleanup(ivgen
);