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 QCryptoNettleDESRFB {
241 uint8_t iv[DES_BLOCK_SIZE];
242 } QCryptoNettleDESRFB;
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_rfb, QCryptoNettleDESRFB,
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_RFB:
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_RFB:
485 QCryptoNettleDESRFB *ctx;
486 const QCryptoCipherDriver *drv;
490 case QCRYPTO_CIPHER_MODE_ECB:
491 drv = &qcrypto_nettle_des_rfb_driver_ecb;
493 case QCRYPTO_CIPHER_MODE_CBC:
494 drv = &qcrypto_nettle_des_rfb_driver_cbc;
496 case QCRYPTO_CIPHER_MODE_CTR:
497 drv = &qcrypto_nettle_des_rfb_driver_ctr;
500 goto bad_cipher_mode;
503 ctx = g_new0(QCryptoNettleDESRFB, 1);
504 ctx->base.driver = drv;
506 rfbkey = qcrypto_cipher_munge_des_rfb_key(key, nkey);
507 des_set_key(&ctx->key, rfbkey);
513 case QCRYPTO_CIPHER_ALG_3DES:
515 QCryptoNettleDES3 *ctx;
516 const QCryptoCipherDriver *drv;
519 case QCRYPTO_CIPHER_MODE_ECB:
520 drv = &qcrypto_nettle_des3_driver_ecb;
522 case QCRYPTO_CIPHER_MODE_CBC:
523 drv = &qcrypto_nettle_des3_driver_cbc;
525 case QCRYPTO_CIPHER_MODE_CTR:
526 drv = &qcrypto_nettle_des3_driver_ctr;
529 goto bad_cipher_mode;
532 ctx = g_new0(QCryptoNettleDES3, 1);
533 ctx->base.driver = drv;
534 des3_set_key(&ctx->key, key);
538 case QCRYPTO_CIPHER_ALG_AES_128:
540 QCryptoNettleAES128 *ctx = g_new0(QCryptoNettleAES128, 1);
543 case QCRYPTO_CIPHER_MODE_ECB:
544 ctx->base.driver = &qcrypto_nettle_aes128_driver_ecb;
546 case QCRYPTO_CIPHER_MODE_CBC:
547 ctx->base.driver = &qcrypto_nettle_aes128_driver_cbc;
549 case QCRYPTO_CIPHER_MODE_CTR:
550 ctx->base.driver = &qcrypto_nettle_aes128_driver_ctr;
552 case QCRYPTO_CIPHER_MODE_XTS:
553 ctx->base.driver = &qcrypto_nettle_aes128_driver_xts;
555 aes128_set_encrypt_key(&ctx->key_xts[0], key + nkey);
556 aes128_set_decrypt_key(&ctx->key_xts[1], key + nkey);
559 g_assert_not_reached();
561 aes128_set_encrypt_key(&ctx->key[0], key);
562 aes128_set_decrypt_key(&ctx->key[1], key);
567 case QCRYPTO_CIPHER_ALG_AES_192:
569 QCryptoNettleAES192 *ctx = g_new0(QCryptoNettleAES192, 1);
572 case QCRYPTO_CIPHER_MODE_ECB:
573 ctx->base.driver = &qcrypto_nettle_aes192_driver_ecb;
575 case QCRYPTO_CIPHER_MODE_CBC:
576 ctx->base.driver = &qcrypto_nettle_aes192_driver_cbc;
578 case QCRYPTO_CIPHER_MODE_CTR:
579 ctx->base.driver = &qcrypto_nettle_aes192_driver_ctr;
581 case QCRYPTO_CIPHER_MODE_XTS:
582 ctx->base.driver = &qcrypto_nettle_aes192_driver_xts;
584 aes192_set_encrypt_key(&ctx->key_xts[0], key + nkey);
585 aes192_set_decrypt_key(&ctx->key_xts[1], key + nkey);
588 g_assert_not_reached();
590 aes192_set_encrypt_key(&ctx->key[0], key);
591 aes192_set_decrypt_key(&ctx->key[1], key);
596 case QCRYPTO_CIPHER_ALG_AES_256:
598 QCryptoNettleAES256 *ctx = g_new0(QCryptoNettleAES256, 1);
601 case QCRYPTO_CIPHER_MODE_ECB:
602 ctx->base.driver = &qcrypto_nettle_aes256_driver_ecb;
604 case QCRYPTO_CIPHER_MODE_CBC:
605 ctx->base.driver = &qcrypto_nettle_aes256_driver_cbc;
607 case QCRYPTO_CIPHER_MODE_CTR:
608 ctx->base.driver = &qcrypto_nettle_aes256_driver_ctr;
610 case QCRYPTO_CIPHER_MODE_XTS:
611 ctx->base.driver = &qcrypto_nettle_aes256_driver_xts;
613 aes256_set_encrypt_key(&ctx->key_xts[0], key + nkey);
614 aes256_set_decrypt_key(&ctx->key_xts[1], key + nkey);
617 g_assert_not_reached();
619 aes256_set_encrypt_key(&ctx->key[0], key);
620 aes256_set_decrypt_key(&ctx->key[1], key);
625 case QCRYPTO_CIPHER_ALG_CAST5_128:
627 QCryptoNettleCAST128 *ctx;
628 const QCryptoCipherDriver *drv;
631 case QCRYPTO_CIPHER_MODE_ECB:
632 drv = &qcrypto_nettle_cast128_driver_ecb;
634 case QCRYPTO_CIPHER_MODE_CBC:
635 drv = &qcrypto_nettle_cast128_driver_cbc;
637 case QCRYPTO_CIPHER_MODE_CTR:
638 drv = &qcrypto_nettle_cast128_driver_ctr;
641 goto bad_cipher_mode;
644 ctx = g_new0(QCryptoNettleCAST128, 1);
645 ctx->base.driver = drv;
646 cast5_set_key(&ctx->key, nkey, key);
651 case QCRYPTO_CIPHER_ALG_SERPENT_128:
652 case QCRYPTO_CIPHER_ALG_SERPENT_192:
653 case QCRYPTO_CIPHER_ALG_SERPENT_256:
655 QCryptoNettleSerpent *ctx = g_new0(QCryptoNettleSerpent, 1);
658 case QCRYPTO_CIPHER_MODE_ECB:
659 ctx->base.driver = &qcrypto_nettle_serpent_driver_ecb;
661 case QCRYPTO_CIPHER_MODE_CBC:
662 ctx->base.driver = &qcrypto_nettle_serpent_driver_cbc;
664 case QCRYPTO_CIPHER_MODE_CTR:
665 ctx->base.driver = &qcrypto_nettle_serpent_driver_ctr;
667 case QCRYPTO_CIPHER_MODE_XTS:
668 ctx->base.driver = &qcrypto_nettle_serpent_driver_xts;
670 serpent_set_key(&ctx->key_xts, nkey, key + nkey);
673 g_assert_not_reached();
675 serpent_set_key(&ctx->key, nkey, key);
680 case QCRYPTO_CIPHER_ALG_TWOFISH_128:
681 case QCRYPTO_CIPHER_ALG_TWOFISH_192:
682 case QCRYPTO_CIPHER_ALG_TWOFISH_256:
684 QCryptoNettleTwofish *ctx = g_new0(QCryptoNettleTwofish, 1);
687 case QCRYPTO_CIPHER_MODE_ECB:
688 ctx->base.driver = &qcrypto_nettle_twofish_driver_ecb;
690 case QCRYPTO_CIPHER_MODE_CBC:
691 ctx->base.driver = &qcrypto_nettle_twofish_driver_cbc;
693 case QCRYPTO_CIPHER_MODE_CTR:
694 ctx->base.driver = &qcrypto_nettle_twofish_driver_ctr;
696 case QCRYPTO_CIPHER_MODE_XTS:
697 ctx->base.driver = &qcrypto_nettle_twofish_driver_xts;
699 twofish_set_key(&ctx->key_xts, nkey, key + nkey);
702 g_assert_not_reached();
704 twofish_set_key(&ctx->key, nkey, key);
710 error_setg(errp, "Unsupported cipher algorithm %s",
711 QCryptoCipherAlgorithm_str(alg));
716 error_setg(errp, "Unsupported cipher mode %s",
717 QCryptoCipherMode_str(mode));