Skip to content

Commit e907277

Browse files
qsnkuba-moo
authored andcommitted
tls: expand use of tls_cipher_desc in tls_sw_fallback_init
tls_sw_fallback_init already gets the key and tag size from tls_cipher_desc. We can now also check that the cipher type is valid, and stop hard-coding the algorithm name passed to crypto_alloc_aead. Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://lore.kernel.org/r/c8c94b8fcafbfb558e09589c1f1ad48dbdf92f76.1692977948.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d2322cf commit e907277

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

net/tls/tls_device_fallback.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -472,32 +472,24 @@ int tls_sw_fallback_init(struct sock *sk,
472472
struct tls_crypto_info *crypto_info)
473473
{
474474
const struct tls_cipher_desc *cipher_desc;
475-
const u8 *key;
476475
int rc;
477476

478-
switch (crypto_info->cipher_type) {
479-
case TLS_CIPHER_AES_GCM_128:
480-
key = ((struct tls12_crypto_info_aes_gcm_128 *)crypto_info)->key;
481-
break;
482-
case TLS_CIPHER_AES_GCM_256:
483-
key = ((struct tls12_crypto_info_aes_gcm_256 *)crypto_info)->key;
484-
break;
485-
default:
486-
rc = -EINVAL;
487-
goto err_out;
488-
}
489477
cipher_desc = get_cipher_desc(crypto_info->cipher_type);
478+
if (!cipher_desc || !cipher_desc->offloadable)
479+
return -EINVAL;
490480

491481
offload_ctx->aead_send =
492-
crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC);
482+
crypto_alloc_aead(cipher_desc->cipher_name, 0, CRYPTO_ALG_ASYNC);
493483
if (IS_ERR(offload_ctx->aead_send)) {
494484
rc = PTR_ERR(offload_ctx->aead_send);
495485
pr_err_ratelimited("crypto_alloc_aead failed rc=%d\n", rc);
496486
offload_ctx->aead_send = NULL;
497487
goto err_out;
498488
}
499489

500-
rc = crypto_aead_setkey(offload_ctx->aead_send, key, cipher_desc->key);
490+
rc = crypto_aead_setkey(offload_ctx->aead_send,
491+
crypto_info_key(crypto_info, cipher_desc),
492+
cipher_desc->key);
501493
if (rc)
502494
goto free_aead;
503495

0 commit comments

Comments
 (0)