Skip to content

Commit

Permalink
net/tls: Describe ciphers sizes by const structs
Browse files Browse the repository at this point in the history
Introduce cipher sizes descriptor. It helps reducing the amount of code
duplications and repeated switch/cases that assigns the proper sizes
according to the cipher type.

Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Tariq Toukan authored and Jakub Kicinski committed Sep 23, 2022
1 parent 8db3d51 commit 2d2c5ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/net/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@

struct tls_rec;

struct tls_cipher_size_desc {
unsigned int iv;
unsigned int key;
unsigned int salt;
unsigned int tag;
unsigned int rec_seq;
};

extern const struct tls_cipher_size_desc tls_cipher_size_desc[];

/* Maximum data size carried in a TLS record */
#define TLS_MAX_PAYLOAD_SIZE ((size_t)1 << 14)

Expand Down
17 changes: 17 additions & 0 deletions net/tls/tls_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ enum {
TLS_NUM_PROTS,
};

#define CIPHER_SIZE_DESC(cipher) [cipher] = { \
.iv = cipher ## _IV_SIZE, \
.key = cipher ## _KEY_SIZE, \
.salt = cipher ## _SALT_SIZE, \
.tag = cipher ## _TAG_SIZE, \
.rec_seq = cipher ## _REC_SEQ_SIZE, \
}

const struct tls_cipher_size_desc tls_cipher_size_desc[] = {
CIPHER_SIZE_DESC(TLS_CIPHER_AES_GCM_128),
CIPHER_SIZE_DESC(TLS_CIPHER_AES_GCM_256),
CIPHER_SIZE_DESC(TLS_CIPHER_AES_CCM_128),
CIPHER_SIZE_DESC(TLS_CIPHER_CHACHA20_POLY1305),
CIPHER_SIZE_DESC(TLS_CIPHER_SM4_GCM),
CIPHER_SIZE_DESC(TLS_CIPHER_SM4_CCM),
};

static const struct proto *saved_tcpv6_prot;
static DEFINE_MUTEX(tcpv6_prot_mutex);
static const struct proto *saved_tcpv4_prot;
Expand Down

0 comments on commit 2d2c5ea

Please sign in to comment.