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 "qapi/error.h"
24 #include "crypto/ivgenpriv.h"
25 #include "crypto/ivgen-plain.h"
26 #include "crypto/ivgen-plain64.h"
27 #include "crypto/ivgen-essiv.h"
30 QCryptoIVGen *qcrypto_ivgen_new(QCryptoIVGenAlgorithm alg,
31 QCryptoCipherAlgorithm cipheralg,
32 QCryptoHashAlgorithm hash,
33 const uint8_t *key, size_t nkey,
36 QCryptoIVGen *ivgen = g_new0(QCryptoIVGen, 1);
38 ivgen->algorithm = alg;
39 ivgen->cipher = cipheralg;
43 case QCRYPTO_IVGEN_ALG_PLAIN:
44 ivgen->driver = &qcrypto_ivgen_plain;
46 case QCRYPTO_IVGEN_ALG_PLAIN64:
47 ivgen->driver = &qcrypto_ivgen_plain64;
49 case QCRYPTO_IVGEN_ALG_ESSIV:
50 ivgen->driver = &qcrypto_ivgen_essiv;
53 error_setg(errp, "Unknown block IV generator algorithm %d", alg);
58 if (ivgen->driver->init(ivgen, key, nkey, errp) < 0) {
67 int qcrypto_ivgen_calculate(QCryptoIVGen *ivgen,
69 uint8_t *iv, size_t niv,
72 return ivgen->driver->calculate(ivgen, sector, iv, niv, errp);
76 QCryptoIVGenAlgorithm qcrypto_ivgen_get_algorithm(QCryptoIVGen *ivgen)
78 return ivgen->algorithm;
82 QCryptoCipherAlgorithm qcrypto_ivgen_get_cipher(QCryptoIVGen *ivgen)
88 QCryptoHashAlgorithm qcrypto_ivgen_get_hash(QCryptoIVGen *ivgen)
94 void qcrypto_ivgen_free(QCryptoIVGen *ivgen)
99 ivgen->driver->cleanup(ivgen);