net/tls: make inline helpers protocol-aware

Inline functions defined in tls.h have a lot of AES-specific
constants. Remove these constants and change argument to struct
tls_prot_info to have an access to cipher type in later patches

Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Vadim Fedorenko
2020-11-24 18:24:46 +03:00
committed by Jakub Kicinski
parent 594e31bceb
commit 6942a284fb
4 changed files with 25 additions and 28 deletions

View File

@@ -502,31 +502,30 @@ static inline void tls_advance_record_sn(struct sock *sk,
tls_err_abort(sk, EBADMSG);
if (prot->version != TLS_1_3_VERSION)
tls_bigint_increment(ctx->iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE,
tls_bigint_increment(ctx->iv + prot->salt_size,
prot->iv_size);
}
static inline void tls_fill_prepend(struct tls_context *ctx,
char *buf,
size_t plaintext_len,
unsigned char record_type,
int version)
unsigned char record_type)
{
struct tls_prot_info *prot = &ctx->prot_info;
size_t pkt_len, iv_size = prot->iv_size;
pkt_len = plaintext_len + prot->tag_size;
if (version != TLS_1_3_VERSION) {
if (prot->version != TLS_1_3_VERSION) {
pkt_len += iv_size;
memcpy(buf + TLS_NONCE_OFFSET,
ctx->tx.iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, iv_size);
ctx->tx.iv + prot->salt_size, iv_size);
}
/* we cover nonce explicit here as well, so buf should be of
* size KTLS_DTLS_HEADER_SIZE + KTLS_DTLS_NONCE_EXPLICIT_SIZE
*/
buf[0] = version == TLS_1_3_VERSION ?
buf[0] = prot->version == TLS_1_3_VERSION ?
TLS_RECORD_TYPE_DATA : record_type;
/* Note that VERSION must be TLS_1_2 for both TLS1.2 and TLS1.3 */
buf[1] = TLS_1_2_VERSION_MINOR;
@@ -539,18 +538,17 @@ static inline void tls_fill_prepend(struct tls_context *ctx,
static inline void tls_make_aad(char *buf,
size_t size,
char *record_sequence,
int record_sequence_size,
unsigned char record_type,
int version)
struct tls_prot_info *prot)
{
if (version != TLS_1_3_VERSION) {
memcpy(buf, record_sequence, record_sequence_size);
if (prot->version != TLS_1_3_VERSION) {
memcpy(buf, record_sequence, prot->rec_seq_size);
buf += 8;
} else {
size += TLS_CIPHER_AES_GCM_128_TAG_SIZE;
size += prot->tag_size;
}
buf[0] = version == TLS_1_3_VERSION ?
buf[0] = prot->version == TLS_1_3_VERSION ?
TLS_RECORD_TYPE_DATA : record_type;
buf[1] = TLS_1_2_VERSION_MAJOR;
buf[2] = TLS_1_2_VERSION_MINOR;
@@ -558,11 +556,11 @@ static inline void tls_make_aad(char *buf,
buf[4] = size & 0xFF;
}
static inline void xor_iv_with_seq(int version, char *iv, char *seq)
static inline void xor_iv_with_seq(struct tls_prot_info *prot, char *iv, char *seq)
{
int i;
if (version == TLS_1_3_VERSION) {
if (prot->version == TLS_1_3_VERSION) {
for (i = 0; i < 8; i++)
iv[i + 4] ^= seq[i];
}