2 * QEMU Crypto cipher nettle 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.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 #ifdef CONFIG_QEMU_PRIVATE_XTS
22 #include "crypto/xts.h"
25 #include <nettle/nettle-types.h>
26 #include <nettle/aes.h>
27 #include <nettle/des.h>
28 #include <nettle/cbc.h>
29 #include <nettle/cast128.h>
30 #include <nettle/serpent.h>
31 #include <nettle/twofish.h>
32 #include <nettle/ctr.h>
33 #ifndef CONFIG_QEMU_PRIVATE_XTS
34 #include <nettle/xts.h>
37 static inline bool qcrypto_length_check(size_t len, size_t blocksize,
40 if (unlikely(len & (blocksize - 1))) {
41 error_setg(errp, "Length %zu must be a multiple of block size %zu",
49 static void qcrypto_cipher_ctx_free(QCryptoCipher *ctx)
54 static int qcrypto_cipher_no_setiv(QCryptoCipher *cipher,
55 const uint8_t *iv, size_t niv,
58 error_setg(errp, "Setting IV is not supported");
63 #define DEFINE_SETIV(NAME, TYPE, BLEN) \
64 static int NAME##_setiv(QCryptoCipher *cipher, const uint8_t *iv, \
65 size_t niv, Error **errp) \
67 TYPE *ctx = container_of(cipher, TYPE, base); \
69 error_setg(errp, "Expected IV size %d not %zu", BLEN, niv); \
72 memcpy(ctx->iv, iv, niv); \
77 #define DEFINE_ECB(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
78 static int NAME##_encrypt_ecb(QCryptoCipher *cipher, const void *in, \
79 void *out, size_t len, Error **errp) \
81 TYPE *ctx = container_of(cipher, TYPE, base); \
82 if (!qcrypto_length_check(len, BLEN, errp)) { \
85 ENCRYPT(&ctx->key, len, out, in); \
88 static int NAME##_decrypt_ecb(QCryptoCipher *cipher, const void *in, \
89 void *out, size_t len, Error **errp) \
91 TYPE *ctx = container_of(cipher, TYPE, base); \
92 if (!qcrypto_length_check(len, BLEN, errp)) { \
95 DECRYPT(&ctx->key, len, out, in); \
98 static const struct QCryptoCipherDriver NAME##_driver_ecb = { \
99 .cipher_encrypt = NAME##_encrypt_ecb, \
100 .cipher_decrypt = NAME##_decrypt_ecb, \
101 .cipher_setiv = qcrypto_cipher_no_setiv, \
102 .cipher_free = qcrypto_cipher_ctx_free, \
106 #define DEFINE_CBC(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
107 static int NAME##_encrypt_cbc(QCryptoCipher *cipher, const void *in, \
108 void *out, size_t len, Error **errp) \
110 TYPE *ctx = container_of(cipher, TYPE, base); \
111 if (!qcrypto_length_check(len, BLEN, errp)) { \
114 cbc_encrypt(&ctx->key, ENCRYPT, BLEN, ctx->iv, len, out, in); \
117 static int NAME##_decrypt_cbc(QCryptoCipher *cipher, const void *in, \
118 void *out, size_t len, Error **errp) \
120 TYPE *ctx = container_of(cipher, TYPE, base); \
121 if (!qcrypto_length_check(len, BLEN, errp)) { \
124 cbc_decrypt(&ctx->key, DECRYPT, BLEN, ctx->iv, len, out, in); \
127 static const struct QCryptoCipherDriver NAME##_driver_cbc = { \
128 .cipher_encrypt = NAME##_encrypt_cbc, \
129 .cipher_decrypt = NAME##_decrypt_cbc, \
130 .cipher_setiv = NAME##_setiv, \
131 .cipher_free = qcrypto_cipher_ctx_free, \
135 #define DEFINE_CTR(NAME, TYPE, BLEN, ENCRYPT) \
136 static int NAME##_encrypt_ctr(QCryptoCipher *cipher, const void *in, \
137 void *out, size_t len, Error **errp) \
139 TYPE *ctx = container_of(cipher, TYPE, base); \
140 if (!qcrypto_length_check(len, BLEN, errp)) { \
143 ctr_crypt(&ctx->key, ENCRYPT, BLEN, ctx->iv, len, out, in); \
146 static const struct QCryptoCipherDriver NAME##_driver_ctr = { \
147 .cipher_encrypt = NAME##_encrypt_ctr, \
148 .cipher_decrypt = NAME##_encrypt_ctr, \
149 .cipher_setiv = NAME##_setiv, \
150 .cipher_free = qcrypto_cipher_ctx_free, \
154 #ifdef CONFIG_QEMU_PRIVATE_XTS
155 #define DEFINE__XTS(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
156 static void NAME##_xts_wrape(const void *ctx, size_t length, \
157 uint8_t *dst, const uint8_t *src) \
159 ENCRYPT((const void *)ctx, length, dst, src); \
161 static void NAME##_xts_wrapd(const void *ctx, size_t length, \
162 uint8_t *dst, const uint8_t *src) \
164 DECRYPT((const void *)ctx, length, dst, src); \
166 static int NAME##_encrypt_xts(QCryptoCipher *cipher, const void *in, \
167 void *out, size_t len, Error **errp) \
169 TYPE *ctx = container_of(cipher, TYPE, base); \
170 if (!qcrypto_length_check(len, BLEN, errp)) { \
173 xts_encrypt(&ctx->key, &ctx->key_xts, \
174 NAME##_xts_wrape, NAME##_xts_wrapd, \
175 ctx->iv, len, out, in); \
178 static int NAME##_decrypt_xts(QCryptoCipher *cipher, const void *in, \
179 void *out, size_t len, Error **errp) \
181 TYPE *ctx = container_of(cipher, TYPE, base); \
182 if (!qcrypto_length_check(len, BLEN, errp)) { \
185 xts_decrypt(&ctx->key, &ctx->key_xts, \
186 NAME##_xts_wrape, NAME##_xts_wrapd, \
187 ctx->iv, len, out, in); \
191 #define DEFINE__XTS(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
192 static int NAME##_encrypt_xts(QCryptoCipher *cipher, const void *in, \
193 void *out, size_t len, Error **errp) \
195 TYPE *ctx = container_of(cipher, TYPE, base); \
196 if (!qcrypto_length_check(len, BLEN, errp)) { \
199 xts_encrypt_message(&ctx->key, &ctx->key_xts, ENCRYPT, \
200 ctx->iv, len, out, in); \
203 static int NAME##_decrypt_xts(QCryptoCipher *cipher, const void *in, \
204 void *out, size_t len, Error **errp) \
206 TYPE *ctx = container_of(cipher, TYPE, base); \
207 if (!qcrypto_length_check(len, BLEN, errp)) { \
210 xts_decrypt_message(&ctx->key, &ctx->key_xts, DECRYPT, ENCRYPT, \
211 ctx->iv, len, out, in); \
216 #define DEFINE_XTS(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
217 QEMU_BUILD_BUG_ON(BLEN != XTS_BLOCK_SIZE); \
218 DEFINE__XTS(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
219 static const struct QCryptoCipherDriver NAME##_driver_xts = { \
220 .cipher_encrypt = NAME##_encrypt_xts, \
221 .cipher_decrypt = NAME##_decrypt_xts, \
222 .cipher_setiv = NAME##_setiv, \
223 .cipher_free = qcrypto_cipher_ctx_free, \
227 #define DEFINE_ECB_CBC_CTR(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
228 DEFINE_SETIV(NAME, TYPE, BLEN) \
229 DEFINE_ECB(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
230 DEFINE_CBC(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
231 DEFINE_CTR(NAME, TYPE, BLEN, ENCRYPT)
233 #define DEFINE_ECB_CBC_CTR_XTS(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
234 DEFINE_ECB_CBC_CTR(NAME, TYPE, BLEN, ENCRYPT, DECRYPT) \
235 DEFINE_XTS(NAME, TYPE, BLEN, ENCRYPT, DECRYPT)
238 typedef struct QCryptoNettleDES {
241 uint8_t iv[DES_BLOCK_SIZE];
244 static void des_encrypt_native(const void *ctx, size_t length,
245 uint8_t *dst, const uint8_t *src)
247 des_encrypt(ctx, length, dst, src);
250 static void des_decrypt_native(const void *ctx, size_t length,
251 uint8_t *dst, const uint8_t *src)
253 des_decrypt(ctx, length, dst, src);
256 DEFINE_ECB_CBC_CTR(qcrypto_nettle_des, QCryptoNettleDES,
257 DES_BLOCK_SIZE, des_encrypt_native, des_decrypt_native)
260 typedef struct QCryptoNettleDES3 {
263 uint8_t iv[DES3_BLOCK_SIZE];
266 static void des3_encrypt_native(const void *ctx, size_t length,
267 uint8_t *dst, const uint8_t *src)
269 des3_encrypt(ctx, length, dst, src);
272 static void des3_decrypt_native(const void *ctx, size_t length,
273 uint8_t *dst, const uint8_t *src)
275 des3_decrypt(ctx, length, dst, src);
278 DEFINE_ECB_CBC_CTR(qcrypto_nettle_des3, QCryptoNettleDES3, DES3_BLOCK_SIZE,
279 des3_encrypt_native, des3_decrypt_native)
282 typedef struct QCryptoNettleAES128 {
284 uint8_t iv[AES_BLOCK_SIZE];
285 /* First key from pair is encode, second key is decode. */
286 struct aes128_ctx key[2], key_xts[2];
287 } QCryptoNettleAES128;
289 static void aes128_encrypt_native(const void *ctx, size_t length,
290 uint8_t *dst, const uint8_t *src)
292 const struct aes128_ctx *keys = ctx;
293 aes128_encrypt(&keys[0], length, dst, src);
296 static void aes128_decrypt_native(const void *ctx, size_t length,
297 uint8_t *dst, const uint8_t *src)
299 const struct aes128_ctx *keys = ctx;
300 aes128_decrypt(&keys[1], length, dst, src);
303 DEFINE_ECB_CBC_CTR_XTS(qcrypto_nettle_aes128,
304 QCryptoNettleAES128, AES_BLOCK_SIZE,
305 aes128_encrypt_native, aes128_decrypt_native)
308 typedef struct QCryptoNettleAES192 {
310 uint8_t iv[AES_BLOCK_SIZE];
311 /* First key from pair is encode, second key is decode. */
312 struct aes192_ctx key[2], key_xts[2];
313 } QCryptoNettleAES192;
315 static void aes192_encrypt_native(const void *ctx, size_t length,
316 uint8_t *dst, const uint8_t *src)
318 const struct aes192_ctx *keys = ctx;
319 aes192_encrypt(&keys[0], length, dst, src);
322 static void aes192_decrypt_native(const void *ctx, size_t length,
323 uint8_t *dst, const uint8_t *src)
325 const struct aes192_ctx *keys = ctx;
326 aes192_decrypt(&keys[1], length, dst, src);
329 DEFINE_ECB_CBC_CTR_XTS(qcrypto_nettle_aes192,
330 QCryptoNettleAES192, AES_BLOCK_SIZE,
331 aes192_encrypt_native, aes192_decrypt_native)
334 typedef struct QCryptoNettleAES256 {
336 uint8_t iv[AES_BLOCK_SIZE];
337 /* First key from pair is encode, second key is decode. */
338 struct aes256_ctx key[2], key_xts[2];
339 } QCryptoNettleAES256;
341 static void aes256_encrypt_native(const void *ctx, size_t length,
342 uint8_t *dst, const uint8_t *src)
344 const struct aes256_ctx *keys = ctx;
345 aes256_encrypt(&keys[0], length, dst, src);
348 static void aes256_decrypt_native(const void *ctx, size_t length,
349 uint8_t *dst, const uint8_t *src)
351 const struct aes256_ctx *keys = ctx;
352 aes256_decrypt(&keys[1], length, dst, src);
355 DEFINE_ECB_CBC_CTR_XTS(qcrypto_nettle_aes256,
356 QCryptoNettleAES256, AES_BLOCK_SIZE,
357 aes256_encrypt_native, aes256_decrypt_native)
360 typedef struct QCryptoNettleCAST128 {
362 uint8_t iv[CAST128_BLOCK_SIZE];
363 struct cast128_ctx key, key_xts;
364 } QCryptoNettleCAST128;
366 static void cast128_encrypt_native(const void *ctx, size_t length,
367 uint8_t *dst, const uint8_t *src)
369 cast128_encrypt(ctx, length, dst, src);
372 static void cast128_decrypt_native(const void *ctx, size_t length,
373 uint8_t *dst, const uint8_t *src)
375 cast128_decrypt(ctx, length, dst, src);
378 DEFINE_ECB_CBC_CTR(qcrypto_nettle_cast128,
379 QCryptoNettleCAST128, CAST128_BLOCK_SIZE,
380 cast128_encrypt_native, cast128_decrypt_native)
383 typedef struct QCryptoNettleSerpent {
385 uint8_t iv[SERPENT_BLOCK_SIZE];
386 struct serpent_ctx key, key_xts;
387 } QCryptoNettleSerpent;
390 static void serpent_encrypt_native(const void *ctx, size_t length,
391 uint8_t *dst, const uint8_t *src)
393 serpent_encrypt(ctx, length, dst, src);
396 static void serpent_decrypt_native(const void *ctx, size_t length,
397 uint8_t *dst, const uint8_t *src)
399 serpent_decrypt(ctx, length, dst, src);
402 DEFINE_ECB_CBC_CTR_XTS(qcrypto_nettle_serpent,
403 QCryptoNettleSerpent, SERPENT_BLOCK_SIZE,
404 serpent_encrypt_native, serpent_decrypt_native)
407 typedef struct QCryptoNettleTwofish {
409 uint8_t iv[TWOFISH_BLOCK_SIZE];
410 struct twofish_ctx key, key_xts;
411 } QCryptoNettleTwofish;
413 static void twofish_encrypt_native(const void *ctx, size_t length,
414 uint8_t *dst, const uint8_t *src)
416 twofish_encrypt(ctx, length, dst, src);
419 static void twofish_decrypt_native(const void *ctx, size_t length,
420 uint8_t *dst, const uint8_t *src)
422 twofish_decrypt(ctx, length, dst, src);
425 DEFINE_ECB_CBC_CTR_XTS(qcrypto_nettle_twofish,
426 QCryptoNettleTwofish, TWOFISH_BLOCK_SIZE,
427 twofish_encrypt_native, twofish_decrypt_native)
430 bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg,
431 QCryptoCipherMode mode)
434 case QCRYPTO_CIPHER_ALG_DES:
435 case QCRYPTO_CIPHER_ALG_3DES:
436 case QCRYPTO_CIPHER_ALG_AES_128:
437 case QCRYPTO_CIPHER_ALG_AES_192:
438 case QCRYPTO_CIPHER_ALG_AES_256:
439 case QCRYPTO_CIPHER_ALG_CAST5_128:
440 case QCRYPTO_CIPHER_ALG_SERPENT_128:
441 case QCRYPTO_CIPHER_ALG_SERPENT_192:
442 case QCRYPTO_CIPHER_ALG_SERPENT_256:
443 case QCRYPTO_CIPHER_ALG_TWOFISH_128:
444 case QCRYPTO_CIPHER_ALG_TWOFISH_192:
445 case QCRYPTO_CIPHER_ALG_TWOFISH_256:
452 case QCRYPTO_CIPHER_MODE_ECB:
453 case QCRYPTO_CIPHER_MODE_CBC:
454 case QCRYPTO_CIPHER_MODE_XTS:
455 case QCRYPTO_CIPHER_MODE_CTR:
462 static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
463 QCryptoCipherMode mode,
469 case QCRYPTO_CIPHER_MODE_ECB:
470 case QCRYPTO_CIPHER_MODE_CBC:
471 case QCRYPTO_CIPHER_MODE_XTS:
472 case QCRYPTO_CIPHER_MODE_CTR:
475 goto bad_cipher_mode;
478 if (!qcrypto_cipher_validate_key_length(alg, mode, nkey, errp)) {
483 case QCRYPTO_CIPHER_ALG_DES:
485 QCryptoNettleDES *ctx;
486 const QCryptoCipherDriver *drv;
489 case QCRYPTO_CIPHER_MODE_ECB:
490 drv = &qcrypto_nettle_des_driver_ecb;
492 case QCRYPTO_CIPHER_MODE_CBC:
493 drv = &qcrypto_nettle_des_driver_cbc;
495 case QCRYPTO_CIPHER_MODE_CTR:
496 drv = &qcrypto_nettle_des_driver_ctr;
499 goto bad_cipher_mode;
502 ctx = g_new0(QCryptoNettleDES, 1);
503 ctx->base.driver = drv;
504 des_set_key(&ctx->key, key);
509 case QCRYPTO_CIPHER_ALG_3DES:
511 QCryptoNettleDES3 *ctx;
512 const QCryptoCipherDriver *drv;
515 case QCRYPTO_CIPHER_MODE_ECB:
516 drv = &qcrypto_nettle_des3_driver_ecb;
518 case QCRYPTO_CIPHER_MODE_CBC:
519 drv = &qcrypto_nettle_des3_driver_cbc;
521 case QCRYPTO_CIPHER_MODE_CTR:
522 drv = &qcrypto_nettle_des3_driver_ctr;
525 goto bad_cipher_mode;
528 ctx = g_new0(QCryptoNettleDES3, 1);
529 ctx->base.driver = drv;
530 des3_set_key(&ctx->key, key);
534 case QCRYPTO_CIPHER_ALG_AES_128:
536 QCryptoNettleAES128 *ctx = g_new0(QCryptoNettleAES128, 1);
539 case QCRYPTO_CIPHER_MODE_ECB:
540 ctx->base.driver = &qcrypto_nettle_aes128_driver_ecb;
542 case QCRYPTO_CIPHER_MODE_CBC:
543 ctx->base.driver = &qcrypto_nettle_aes128_driver_cbc;
545 case QCRYPTO_CIPHER_MODE_CTR:
546 ctx->base.driver = &qcrypto_nettle_aes128_driver_ctr;
548 case QCRYPTO_CIPHER_MODE_XTS:
549 ctx->base.driver = &qcrypto_nettle_aes128_driver_xts;
551 aes128_set_encrypt_key(&ctx->key_xts[0], key + nkey);
552 aes128_set_decrypt_key(&ctx->key_xts[1], key + nkey);
555 g_assert_not_reached();
557 aes128_set_encrypt_key(&ctx->key[0], key);
558 aes128_set_decrypt_key(&ctx->key[1], key);
563 case QCRYPTO_CIPHER_ALG_AES_192:
565 QCryptoNettleAES192 *ctx = g_new0(QCryptoNettleAES192, 1);
568 case QCRYPTO_CIPHER_MODE_ECB:
569 ctx->base.driver = &qcrypto_nettle_aes192_driver_ecb;
571 case QCRYPTO_CIPHER_MODE_CBC:
572 ctx->base.driver = &qcrypto_nettle_aes192_driver_cbc;
574 case QCRYPTO_CIPHER_MODE_CTR:
575 ctx->base.driver = &qcrypto_nettle_aes192_driver_ctr;
577 case QCRYPTO_CIPHER_MODE_XTS:
578 ctx->base.driver = &qcrypto_nettle_aes192_driver_xts;
580 aes192_set_encrypt_key(&ctx->key_xts[0], key + nkey);
581 aes192_set_decrypt_key(&ctx->key_xts[1], key + nkey);
584 g_assert_not_reached();
586 aes192_set_encrypt_key(&ctx->key[0], key);
587 aes192_set_decrypt_key(&ctx->key[1], key);
592 case QCRYPTO_CIPHER_ALG_AES_256:
594 QCryptoNettleAES256 *ctx = g_new0(QCryptoNettleAES256, 1);
597 case QCRYPTO_CIPHER_MODE_ECB:
598 ctx->base.driver = &qcrypto_nettle_aes256_driver_ecb;
600 case QCRYPTO_CIPHER_MODE_CBC:
601 ctx->base.driver = &qcrypto_nettle_aes256_driver_cbc;
603 case QCRYPTO_CIPHER_MODE_CTR:
604 ctx->base.driver = &qcrypto_nettle_aes256_driver_ctr;
606 case QCRYPTO_CIPHER_MODE_XTS:
607 ctx->base.driver = &qcrypto_nettle_aes256_driver_xts;
609 aes256_set_encrypt_key(&ctx->key_xts[0], key + nkey);
610 aes256_set_decrypt_key(&ctx->key_xts[1], key + nkey);
613 g_assert_not_reached();
615 aes256_set_encrypt_key(&ctx->key[0], key);
616 aes256_set_decrypt_key(&ctx->key[1], key);
621 case QCRYPTO_CIPHER_ALG_CAST5_128:
623 QCryptoNettleCAST128 *ctx;
624 const QCryptoCipherDriver *drv;
627 case QCRYPTO_CIPHER_MODE_ECB:
628 drv = &qcrypto_nettle_cast128_driver_ecb;
630 case QCRYPTO_CIPHER_MODE_CBC:
631 drv = &qcrypto_nettle_cast128_driver_cbc;
633 case QCRYPTO_CIPHER_MODE_CTR:
634 drv = &qcrypto_nettle_cast128_driver_ctr;
637 goto bad_cipher_mode;
640 ctx = g_new0(QCryptoNettleCAST128, 1);
641 ctx->base.driver = drv;
642 cast5_set_key(&ctx->key, nkey, key);
647 case QCRYPTO_CIPHER_ALG_SERPENT_128:
648 case QCRYPTO_CIPHER_ALG_SERPENT_192:
649 case QCRYPTO_CIPHER_ALG_SERPENT_256:
651 QCryptoNettleSerpent *ctx = g_new0(QCryptoNettleSerpent, 1);
654 case QCRYPTO_CIPHER_MODE_ECB:
655 ctx->base.driver = &qcrypto_nettle_serpent_driver_ecb;
657 case QCRYPTO_CIPHER_MODE_CBC:
658 ctx->base.driver = &qcrypto_nettle_serpent_driver_cbc;
660 case QCRYPTO_CIPHER_MODE_CTR:
661 ctx->base.driver = &qcrypto_nettle_serpent_driver_ctr;
663 case QCRYPTO_CIPHER_MODE_XTS:
664 ctx->base.driver = &qcrypto_nettle_serpent_driver_xts;
666 serpent_set_key(&ctx->key_xts, nkey, key + nkey);
669 g_assert_not_reached();
671 serpent_set_key(&ctx->key, nkey, key);
676 case QCRYPTO_CIPHER_ALG_TWOFISH_128:
677 case QCRYPTO_CIPHER_ALG_TWOFISH_192:
678 case QCRYPTO_CIPHER_ALG_TWOFISH_256:
680 QCryptoNettleTwofish *ctx = g_new0(QCryptoNettleTwofish, 1);
683 case QCRYPTO_CIPHER_MODE_ECB:
684 ctx->base.driver = &qcrypto_nettle_twofish_driver_ecb;
686 case QCRYPTO_CIPHER_MODE_CBC:
687 ctx->base.driver = &qcrypto_nettle_twofish_driver_cbc;
689 case QCRYPTO_CIPHER_MODE_CTR:
690 ctx->base.driver = &qcrypto_nettle_twofish_driver_ctr;
692 case QCRYPTO_CIPHER_MODE_XTS:
693 ctx->base.driver = &qcrypto_nettle_twofish_driver_xts;
695 twofish_set_key(&ctx->key_xts, nkey, key + nkey);
698 g_assert_not_reached();
700 twofish_set_key(&ctx->key, nkey, key);
706 error_setg(errp, "Unsupported cipher algorithm %s",
707 QCryptoCipherAlgorithm_str(alg));
712 error_setg(errp, "Unsupported cipher mode %s",
713 QCryptoCipherMode_str(mode));