Skip to content

Commit 6801404

Browse files
committed
crypto: delete built-in XTS cipher mode support
The built-in AES+XTS implementation is used for the LUKS encryption When building system emulators it is reasonable to expect that an external crypto library is being used instead. The performance of the builtin XTS implementation is terrible as it has no CPU acceleration support. It is thus not worth keeping a home grown XTS implementation for the built-in cipher backend. Reviewed-by: Eric Blake <[email protected]> Signed-off-by: Daniel P. Berrangé <[email protected]>
1 parent 21407dd commit 6801404

File tree

3 files changed

+6
-67
lines changed

3 files changed

+6
-67
lines changed

crypto/cipher-builtin.c.inc

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020

2121
#include "crypto/aes.h"
22-
#include "crypto/xts.h"
2322

2423
typedef struct QCryptoCipherBuiltinAESContext QCryptoCipherBuiltinAESContext;
2524
struct QCryptoCipherBuiltinAESContext {
@@ -31,7 +30,6 @@ typedef struct QCryptoCipherBuiltinAES QCryptoCipherBuiltinAES;
3130
struct QCryptoCipherBuiltinAES {
3231
QCryptoCipher base;
3332
QCryptoCipherBuiltinAESContext key;
34-
QCryptoCipherBuiltinAESContext key_tweak;
3533
uint8_t iv[AES_BLOCK_SIZE];
3634
};
3735

@@ -193,39 +191,6 @@ static int qcrypto_cipher_aes_decrypt_cbc(QCryptoCipher *cipher,
193191
return 0;
194192
}
195193

196-
static int qcrypto_cipher_aes_encrypt_xts(QCryptoCipher *cipher,
197-
const void *in, void *out,
198-
size_t len, Error **errp)
199-
{
200-
QCryptoCipherBuiltinAES *ctx
201-
= container_of(cipher, QCryptoCipherBuiltinAES, base);
202-
203-
if (!qcrypto_length_check(len, AES_BLOCK_SIZE, errp)) {
204-
return -1;
205-
}
206-
xts_encrypt(&ctx->key, &ctx->key_tweak,
207-
do_aes_encrypt_ecb, do_aes_decrypt_ecb,
208-
ctx->iv, len, out, in);
209-
return 0;
210-
}
211-
212-
static int qcrypto_cipher_aes_decrypt_xts(QCryptoCipher *cipher,
213-
const void *in, void *out,
214-
size_t len, Error **errp)
215-
{
216-
QCryptoCipherBuiltinAES *ctx
217-
= container_of(cipher, QCryptoCipherBuiltinAES, base);
218-
219-
if (!qcrypto_length_check(len, AES_BLOCK_SIZE, errp)) {
220-
return -1;
221-
}
222-
xts_decrypt(&ctx->key, &ctx->key_tweak,
223-
do_aes_encrypt_ecb, do_aes_decrypt_ecb,
224-
ctx->iv, len, out, in);
225-
return 0;
226-
}
227-
228-
229194
static int qcrypto_cipher_aes_setiv(QCryptoCipher *cipher, const uint8_t *iv,
230195
size_t niv, Error **errp)
231196
{
@@ -256,14 +221,6 @@ static const struct QCryptoCipherDriver qcrypto_cipher_aes_driver_cbc = {
256221
.cipher_free = qcrypto_cipher_ctx_free,
257222
};
258223

259-
static const struct QCryptoCipherDriver qcrypto_cipher_aes_driver_xts = {
260-
.cipher_encrypt = qcrypto_cipher_aes_encrypt_xts,
261-
.cipher_decrypt = qcrypto_cipher_aes_decrypt_xts,
262-
.cipher_setiv = qcrypto_cipher_aes_setiv,
263-
.cipher_free = qcrypto_cipher_ctx_free,
264-
};
265-
266-
267224
bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg,
268225
QCryptoCipherMode mode)
269226
{
@@ -274,7 +231,6 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg,
274231
switch (mode) {
275232
case QCRYPTO_CIPHER_MODE_ECB:
276233
case QCRYPTO_CIPHER_MODE_CBC:
277-
case QCRYPTO_CIPHER_MODE_XTS:
278234
return true;
279235
default:
280236
return false;
@@ -310,29 +266,13 @@ static QCryptoCipher *qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
310266
case QCRYPTO_CIPHER_MODE_CBC:
311267
drv = &qcrypto_cipher_aes_driver_cbc;
312268
break;
313-
case QCRYPTO_CIPHER_MODE_XTS:
314-
drv = &qcrypto_cipher_aes_driver_xts;
315-
break;
316269
default:
317270
goto bad_mode;
318271
}
319272

320273
ctx = g_new0(QCryptoCipherBuiltinAES, 1);
321274
ctx->base.driver = drv;
322275

323-
if (mode == QCRYPTO_CIPHER_MODE_XTS) {
324-
nkey /= 2;
325-
if (AES_set_encrypt_key(key + nkey, nkey * 8,
326-
&ctx->key_tweak.enc)) {
327-
error_setg(errp, "Failed to set encryption key");
328-
goto error;
329-
}
330-
if (AES_set_decrypt_key(key + nkey, nkey * 8,
331-
&ctx->key_tweak.dec)) {
332-
error_setg(errp, "Failed to set decryption key");
333-
goto error;
334-
}
335-
}
336276
if (AES_set_encrypt_key(key, nkey * 8, &ctx->key.enc)) {
337277
error_setg(errp, "Failed to set encryption key");
338278
goto error;

crypto/meson.build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ crypto_ss.add(files(
2323

2424
if nettle.found()
2525
crypto_ss.add(nettle, files('hash-nettle.c', 'hmac-nettle.c', 'pbkdf-nettle.c'))
26+
if xts == 'private'
27+
crypto_ss.add(files('xts.c'))
28+
endif
2629
elif gcrypt.found()
2730
crypto_ss.add(gcrypt, files('hash-gcrypt.c', 'hmac-gcrypt.c', 'pbkdf-gcrypt.c'))
2831
else
2932
crypto_ss.add(files('hash-glib.c', 'hmac-glib.c', 'pbkdf-stub.c'))
3033
endif
31-
if xts == 'private'
32-
crypto_ss.add(files('xts.c'))
33-
endif
3434

3535
crypto_ss.add(when: 'CONFIG_SECRET_KEYRING', if_true: files('secret_keyring.c'))
3636
crypto_ss.add(when: 'CONFIG_AF_ALG', if_true: files('afalg.c', 'cipher-afalg.c', 'hash-afalg.c'))

meson.build

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -826,24 +826,23 @@ endif
826826
# Nettle has priority over gcrypt
827827
gcrypt = not_found
828828
nettle = not_found
829-
xts = 'private'
829+
xts = 'none'
830830
if get_option('nettle').enabled() and get_option('gcrypt').enabled()
831831
error('Only one of gcrypt & nettle can be enabled')
832832
elif (not get_option('nettle').auto() or have_system) and not get_option('gcrypt').enabled()
833833
nettle = dependency('nettle', version: '>=3.4',
834834
method: 'pkg-config',
835835
required: get_option('nettle'),
836836
kwargs: static_kwargs)
837-
if nettle.found() and cc.has_header('nettle/xts.h', dependencies: nettle)
838-
xts = 'nettle'
837+
if nettle.found() and not cc.has_header('nettle/xts.h', dependencies: nettle)
838+
xts = 'private'
839839
endif
840840
endif
841841
if (not get_option('gcrypt').auto() or have_system) and not nettle.found()
842842
gcrypt = dependency('libgcrypt', version: '>=1.8',
843843
method: 'config-tool',
844844
required: get_option('gcrypt'),
845845
kwargs: static_kwargs)
846-
xts = 'gcrypt'
847846
# Debian has removed -lgpg-error from libgcrypt-config
848847
# as it "spreads unnecessary dependencies" which in
849848
# turn breaks static builds...

0 commit comments

Comments
 (0)