Skip to content

Commit f3e444e

Browse files
qsnkuba-moo
authored andcommitted
tls: get cipher_name from cipher_desc in tls_set_sw_offload
tls_cipher_desc also contains the algorithm name needed by crypto_alloc_aead, use it. Finally, use get_cipher_desc to check if the cipher_type coming from userspace is valid, and remove the cipher_type switch. Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://lore.kernel.org/r/53d021d80138aa125a9cef4468aa5ce531975a7b.1692977948.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 48dfad2 commit f3e444e

1 file changed

Lines changed: 4 additions & 25 deletions

File tree

net/tls/tls_sw.c

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,7 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
25912591
struct cipher_context *cctx;
25922592
struct crypto_aead **aead;
25932593
struct crypto_tfm *tfm;
2594-
char *iv, *rec_seq, *key, *salt, *cipher_name;
2594+
char *iv, *rec_seq, *key, *salt;
25952595
const struct tls_cipher_desc *cipher_desc;
25962596
u16 nonce_size;
25972597
int rc = 0;
@@ -2647,33 +2647,12 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
26472647
aead = &sw_ctx_rx->aead_recv;
26482648
}
26492649

2650-
switch (crypto_info->cipher_type) {
2651-
case TLS_CIPHER_AES_GCM_128:
2652-
case TLS_CIPHER_AES_GCM_256:
2653-
cipher_name = "gcm(aes)";
2654-
break;
2655-
case TLS_CIPHER_AES_CCM_128:
2656-
cipher_name = "ccm(aes)";
2657-
break;
2658-
case TLS_CIPHER_CHACHA20_POLY1305:
2659-
cipher_name = "rfc7539(chacha20,poly1305)";
2660-
break;
2661-
case TLS_CIPHER_SM4_GCM:
2662-
cipher_name = "gcm(sm4)";
2663-
break;
2664-
case TLS_CIPHER_SM4_CCM:
2665-
cipher_name = "ccm(sm4)";
2666-
break;
2667-
case TLS_CIPHER_ARIA_GCM_128:
2668-
case TLS_CIPHER_ARIA_GCM_256:
2669-
cipher_name = "gcm(aria)";
2670-
break;
2671-
default:
2650+
cipher_desc = get_cipher_desc(crypto_info->cipher_type);
2651+
if (!cipher_desc) {
26722652
rc = -EINVAL;
26732653
goto free_priv;
26742654
}
26752655

2676-
cipher_desc = get_cipher_desc(crypto_info->cipher_type);
26772656
nonce_size = cipher_desc->nonce;
26782657

26792658
iv = crypto_info_iv(crypto_info, cipher_desc);
@@ -2721,7 +2700,7 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
27212700
}
27222701

27232702
if (!*aead) {
2724-
*aead = crypto_alloc_aead(cipher_name, 0, 0);
2703+
*aead = crypto_alloc_aead(cipher_desc->cipher_name, 0, 0);
27252704
if (IS_ERR(*aead)) {
27262705
rc = PTR_ERR(*aead);
27272706
*aead = NULL;

0 commit comments

Comments
 (0)