Skip to content

Commit 48dfad2

Browse files
qsnkuba-moo
authored andcommitted
tls: use tls_cipher_desc to access per-cipher crypto_info in tls_set_sw_offload
The crypto_info_* helpers allow us to fetch pointers into the per-cipher crypto_info's data. Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://lore.kernel.org/r/c23af110caf0af6b68de2f86c58064913e2e902a.1692977948.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d9a6ca1 commit 48dfad2

1 file changed

Lines changed: 13 additions & 76 deletions

File tree

net/tls/tls_sw.c

Lines changed: 13 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,94 +2648,26 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
26482648
}
26492649

26502650
switch (crypto_info->cipher_type) {
2651-
case TLS_CIPHER_AES_GCM_128: {
2652-
struct tls12_crypto_info_aes_gcm_128 *gcm_128_info;
2653-
2654-
gcm_128_info = (void *)crypto_info;
2655-
iv = gcm_128_info->iv;
2656-
rec_seq = gcm_128_info->rec_seq;
2657-
key = gcm_128_info->key;
2658-
salt = gcm_128_info->salt;
2651+
case TLS_CIPHER_AES_GCM_128:
2652+
case TLS_CIPHER_AES_GCM_256:
26592653
cipher_name = "gcm(aes)";
26602654
break;
2661-
}
2662-
case TLS_CIPHER_AES_GCM_256: {
2663-
struct tls12_crypto_info_aes_gcm_256 *gcm_256_info;
2664-
2665-
gcm_256_info = (void *)crypto_info;
2666-
iv = gcm_256_info->iv;
2667-
rec_seq = gcm_256_info->rec_seq;
2668-
key = gcm_256_info->key;
2669-
salt = gcm_256_info->salt;
2670-
cipher_name = "gcm(aes)";
2671-
break;
2672-
}
2673-
case TLS_CIPHER_AES_CCM_128: {
2674-
struct tls12_crypto_info_aes_ccm_128 *ccm_128_info;
2675-
2676-
ccm_128_info = (void *)crypto_info;
2677-
iv = ccm_128_info->iv;
2678-
rec_seq = ccm_128_info->rec_seq;
2679-
key = ccm_128_info->key;
2680-
salt = ccm_128_info->salt;
2655+
case TLS_CIPHER_AES_CCM_128:
26812656
cipher_name = "ccm(aes)";
26822657
break;
2683-
}
2684-
case TLS_CIPHER_CHACHA20_POLY1305: {
2685-
struct tls12_crypto_info_chacha20_poly1305 *chacha20_poly1305_info;
2686-
2687-
chacha20_poly1305_info = (void *)crypto_info;
2688-
iv = chacha20_poly1305_info->iv;
2689-
rec_seq = chacha20_poly1305_info->rec_seq;
2690-
key = chacha20_poly1305_info->key;
2691-
salt = chacha20_poly1305_info->salt;
2658+
case TLS_CIPHER_CHACHA20_POLY1305:
26922659
cipher_name = "rfc7539(chacha20,poly1305)";
26932660
break;
2694-
}
2695-
case TLS_CIPHER_SM4_GCM: {
2696-
struct tls12_crypto_info_sm4_gcm *sm4_gcm_info;
2697-
2698-
sm4_gcm_info = (void *)crypto_info;
2699-
iv = sm4_gcm_info->iv;
2700-
rec_seq = sm4_gcm_info->rec_seq;
2701-
key = sm4_gcm_info->key;
2702-
salt = sm4_gcm_info->salt;
2661+
case TLS_CIPHER_SM4_GCM:
27032662
cipher_name = "gcm(sm4)";
27042663
break;
2705-
}
2706-
case TLS_CIPHER_SM4_CCM: {
2707-
struct tls12_crypto_info_sm4_ccm *sm4_ccm_info;
2708-
2709-
sm4_ccm_info = (void *)crypto_info;
2710-
iv = sm4_ccm_info->iv;
2711-
rec_seq = sm4_ccm_info->rec_seq;
2712-
key = sm4_ccm_info->key;
2713-
salt = sm4_ccm_info->salt;
2664+
case TLS_CIPHER_SM4_CCM:
27142665
cipher_name = "ccm(sm4)";
27152666
break;
2716-
}
2717-
case TLS_CIPHER_ARIA_GCM_128: {
2718-
struct tls12_crypto_info_aria_gcm_128 *aria_gcm_128_info;
2719-
2720-
aria_gcm_128_info = (void *)crypto_info;
2721-
iv = aria_gcm_128_info->iv;
2722-
rec_seq = aria_gcm_128_info->rec_seq;
2723-
key = aria_gcm_128_info->key;
2724-
salt = aria_gcm_128_info->salt;
2667+
case TLS_CIPHER_ARIA_GCM_128:
2668+
case TLS_CIPHER_ARIA_GCM_256:
27252669
cipher_name = "gcm(aria)";
27262670
break;
2727-
}
2728-
case TLS_CIPHER_ARIA_GCM_256: {
2729-
struct tls12_crypto_info_aria_gcm_256 *gcm_256_info;
2730-
2731-
gcm_256_info = (void *)crypto_info;
2732-
iv = gcm_256_info->iv;
2733-
rec_seq = gcm_256_info->rec_seq;
2734-
key = gcm_256_info->key;
2735-
salt = gcm_256_info->salt;
2736-
cipher_name = "gcm(aria)";
2737-
break;
2738-
}
27392671
default:
27402672
rc = -EINVAL;
27412673
goto free_priv;
@@ -2744,6 +2676,11 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
27442676
cipher_desc = get_cipher_desc(crypto_info->cipher_type);
27452677
nonce_size = cipher_desc->nonce;
27462678

2679+
iv = crypto_info_iv(crypto_info, cipher_desc);
2680+
key = crypto_info_key(crypto_info, cipher_desc);
2681+
salt = crypto_info_salt(crypto_info, cipher_desc);
2682+
rec_seq = crypto_info_rec_seq(crypto_info, cipher_desc);
2683+
27472684
if (crypto_info->version == TLS_1_3_VERSION) {
27482685
nonce_size = 0;
27492686
prot->aad_size = TLS_HEADER_SIZE;

0 commit comments

Comments
 (0)