2 * QEMU Crypto cipher algorithms
4 * Copyright (c) 2015 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 "crypto/cipher.h"
24 static size_t alg_key_len[QCRYPTO_CIPHER_ALG_LAST] = {
25 [QCRYPTO_CIPHER_ALG_AES_128] = 16,
26 [QCRYPTO_CIPHER_ALG_AES_192] = 24,
27 [QCRYPTO_CIPHER_ALG_AES_256] = 32,
28 [QCRYPTO_CIPHER_ALG_DES_RFB] = 8,
32 qcrypto_cipher_validate_key_length(QCryptoCipherAlgorithm alg,
36 if ((unsigned)alg >= QCRYPTO_CIPHER_ALG_LAST) {
37 error_setg(errp, "Cipher algorithm %d out of range",
42 if (alg_key_len[alg] != nkey) {
43 error_setg(errp, "Cipher key length %zu should be %zu",
44 alg_key_len[alg], nkey);
50 #if defined(CONFIG_GNUTLS_GCRYPT) || defined(CONFIG_GNUTLS_NETTLE)
52 qcrypto_cipher_munge_des_rfb_key(const uint8_t *key,
55 uint8_t *ret = g_new0(uint8_t, nkey);
57 for (i = 0; i < nkey; i++) {
59 r = (r & 0xf0) >> 4 | (r & 0x0f) << 4;
60 r = (r & 0xcc) >> 2 | (r & 0x33) << 2;
61 r = (r & 0xaa) >> 1 | (r & 0x55) << 1;
66 #endif /* CONFIG_GNUTLS_GCRYPT || CONFIG_GNUTLS_NETTLE */
68 #ifdef CONFIG_GNUTLS_GCRYPT
69 #include "crypto/cipher-gcrypt.c"
70 #elif defined CONFIG_GNUTLS_NETTLE
71 #include "crypto/cipher-nettle.c"
73 #include "crypto/cipher-builtin.c"