Reimplement TCP-AO using crypto library
Subsystems (5)
cover Reimplement TCP-AO using crypto library
This series can also be retrieved from:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git tcp-ao-v1
For now this series is an RFC, since it depends on the AES-CMAC library API that is queued in libcrypto-next for 7.1. So, the soonest that this could be applied to net-next is 7.2. I'm sending it out now in case anyone has any early feedback.
This series refactors the TCP-AO (TCP Authentication Option) code to do MAC and KDF computations using lib/crypto/ instead of crypto_ahash. This greatly simplifies the code and makes it much more efficient. The entire tcp_sigpool and crypto_ahash cloning mechanisms become unnecessary and are removed, as the problems they were designed to solve don't exist with the library APIs.
To make this possible, this series also restricts the supported algorithms to a reasonable set, rather than supporting arbitrary algorithms that don't make sense and are very likely not being used. Specifically, this series leaves in place the support for AES-128-CMAC and HMAC-SHA1 which are the only algorithms that actually have an RFC specifying their use in TCP-AO, along with HMAC-SHA256 which is a reasonable algorithm to continue supporting as a Linux extension.
This passes the tcp_ao selftests (tools/testing/selftests/net/tcp_ao).
To get a sense for how much more efficient this makes the TCP-AO code, here's a microbenchmark for tcp_ao_hash_skb() with skb->len == 128:
Algorithm Avg cycles (before) Avg cycles (after)
--------- ------------------- ------------------
HMAC-SHA1 3319 1256
HMAC-SHA256 3311 1344
AES-128-CMAC 2720 1107Eric Biggers (8):
net/tcp-ao: Drop support for most non-RFC-specified algorithms net/tcp-ao: Use crypto library API instead of crypto_ahash net/tcp-ao: Use stack-allocated MAC and traffic_key buffers net/tcp-ao: Return void from functions that can no longer fail net/tcp: Remove tcp_sigpool
crypto: hash - Remove support for cloning hash tfms
crypto: cipher - Remove support for cloning cipher tfms
crypto: api - Remove core support for cloning tfms
crypto/ahash.c | 70 -- crypto/api.c | 26 - crypto/cipher.c | 28 - crypto/cmac.c | 16 - crypto/cryptd.c | 16 - crypto/hmac.c | 31 - crypto/internal.h | 2 - crypto/shash.c | 37 - include/crypto/hash.h | 8 - include/crypto/internal/cipher.h | 2 - include/net/tcp.h | 42 +- include/net/tcp_ao.h | 69 +- net/ipv4/Kconfig | 8 +- net/ipv4/Makefile | 1 - net/ipv4/tcp_ao.c | 677 +++++++++--------- net/ipv4/tcp_output.c | 10 +- net/ipv4/tcp_sigpool.c | 366 ---------- net/ipv6/tcp_ao.c | 139 ++-- tools/testing/selftests/net/tcp_ao/config | 3 - .../selftests/net/tcp_ao/key-management.c | 41 +- 20 files changed, 435 insertions(+), 1157 deletions(-) delete mode 100644 net/ipv4/tcp_sigpool.c
base-commit: 0a217be68aedd0f6b48cf0476462bc94bd73eee7
Signature · 1 line
2.53.0
RFC PATCH 1/8 net/tcp-ao: Drop support for most non-RFC-specified algorithms
RFC 5926 (https://datatracker.ietf.org/doc/html/rfc5926) specifies the use of AES-128-CMAC and HMAC-SHA1 with TCP-AO. This includes a specification for how traffic keys shall be derived for each algorithm.
Support for any other algorithms with TCP-AO isn't standardized, though an expired Internet Draft (a work-in-progress document, not a standard) from 2019 does propose adding HMAC-SHA256 support:
https://datatracker.ietf.org/doc/html/draft-nayak-tcp-sha2-03
Since both documents specify the KDF for each algorithm individually, it isn't necessarily clear how any other algorithm should be integrated.
Nevertheless, the Linux implementation of TCP-AO allows userspace to specify the MAC algorithm as a string tcp_ao_add::alg_name naming either "cmac(aes128)" or an arbitrary algorithm in the crypto_ahash API. The set of valid strings is undocumented. The implementation assumes that "cmac(aes128)" is the only algorithm that requires an entropy extraction step and that all algorithms accept keys with length equal to the untruncated MAC; thus, arbitrary HMAC algorithms probably do work, but some other MAC algorithms like AES-256-CMAC have never actually worked.
Unfortunately, this undocumented string allows many obsolete, insecure, or redundant algorithms. For example, "hmac(md5)" and the non-cryptographic "crc32" are accepted. It also ties the implementation to crypto_ahash and requires that most memory be dynamically allocated, making the implementation unnecessarily complex and inefficient.
Fortunately, it's very likely that only a few algorithms are actually used in practice. Let's restrict the set of allowed algorithms to "cmac(aes128)" (or "cmac(aes)" with keylen=16), "hmac(sha1)", and "hmac(sha256)". The first two are the actually standard ones, while HMAC-SHA256 seems like a reasonable algorithm to continue supporting as a Linux extension, considering the Internet Draft for it and the fact that SHA-256 is the usual choice of upgrade from the outdated SHA-1.
--- net/ipv4/tcp_ao.c | 4 ++ tools/testing/selftests/net/tcp_ao/config | 1 - .../selftests/net/tcp_ao/key-management.c | 41 ++----------------- 3 files changed, 7 insertions(+), 39 deletions(-)
net/ipv4/tcp_ao.c +4 -0
@@ -1561,10 +1561,14 @@ static struct tcp_ao_key *tcp_ao_key_alloc(struct sock *sk, cmd->alg_name[ARRAY_SIZE (cmd->alg_name) -1 ] ='\0' ;/* RFC5926, 3.1.1.2. KDF_AES_128_CMAC */ if (!strcmp ("cmac(aes128)" , algo)) algo ="cmac(aes)" ; +else if (strcmp ("hmac(sha1)" , algo) && +strcmp ("hmac(sha256)" , algo) && + (strcmp ("cmac(aes)" , algo) || cmd->keylen !=16 )) +return ERR_PTR (-ENOENT );/* Full TCP header (th->doff << 2) should fit into scratch area, * see tcp_ao_hash_header(). */ pool_id =tcp_sigpool_alloc_ahash (algo,60 );
tools/testing/selftests/net/tcp_ao/config +0 -1
@@ -1,7 +1,6 @@ CONFIG_CRYPTO_HMAC=y -CONFIG_CRYPTO_RMD160=y CONFIG_CRYPTO_SHA1=y CONFIG_IPV6=y CONFIG_IPV6_MULTIPLE_TABLES=y CONFIG_NET_L3_MASTER_DEV=y CONFIG_NET_VRF=y
tools/testing/selftests/net/tcp_ao/key-management.c +3 -38
81 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC PATCH 2/8 net/tcp-ao: Use crypto library API instead of crypto_ahash
In reply to Eric BiggersCurrently the kernel's TCP-AO implementation does the MAC and KDF computations using the crypto_ahash API. This API is inefficient and difficult to use, and it has required extensive workarounds in the form of per-CPU preallocated objects (tcp_sigpool) to work at all.
Let's use lib/crypto/ instead. This means switching to straightforward stack-allocated structures, virtually addressed buffers, and direct function calls. It also means removing quite a bit of error handling. This makes TCP-AO quite a bit faster.
This also enables many additional cleanups, which later commits will
handle: removing tcp-sigpool, removing support for crypto_tfm cloning, removing more error handling, and replacing more dynamically-allocated buffers with stack buffers based on the now-statically-known limits.
--- include/net/tcp_ao.h | 27 +- net/ipv4/Kconfig | 5 +- net/ipv4/tcp_ao.c | 523 +++++++++++----------- net/ipv6/tcp_ao.c | 63 ++- tools/testing/selftests/net/tcp_ao/config | 2 - 5 files changed, 304 insertions(+), 316 deletions(-)
include/net/tcp_ao.h +19 -8
@@ -1,11 +1,10 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef _TCP_AO_H #define _TCP_AO_H -#define TCP_AO_KEY_ALIGN 1 -#define __tcp_ao_key_align __aligned(TCP_AO_KEY_ALIGN) +#include <crypto/sha2.h> /* for SHA256_DIGEST_SIZE */ union tcp_ao_addr { struct in_addr a4; #if IS_ENABLED(CONFIG_IPV6) struct in6_addr a6;
@@ -30,15 +29,26 @@ struct tcp_ao_counters {atomic64_t key_not_found;atomic64_t ao_required;atomic64_t dropped_icmp; }; +enum tcp_ao_algo_id { +TCP_AO_ALGO_HMAC_SHA1 =1 ,/* specified by RFC 5926 */ +TCP_AO_ALGO_HMAC_SHA256 =2 ,/* Linux extension */ +TCP_AO_ALGO_AES_128_CMAC =3 ,/* specified by RFC 5926 */ +}; + +#define TCP_AO_MAX_MAC_LEN SHA256_DIGEST_SIZE +#define TCP_AO_MAX_TRAFFIC_KEY_LEN SHA256_DIGEST_SIZE + +struct tcp_ao_mac_ctx ; +struct tcp_ao_key {struct hlist_node node;union tcp_ao_addr addr; - u8 key[TCP_AO_MAXKEYLEN] __tcp_ao_key_align; -unsigned int tcp_sigpool_id; +u8 key[TCP_AO_MAXKEYLEN ]; +enum tcp_ao_algo_id algo;unsigned int digest_size;int l3index;u8 prefixlen;u8 family;u8 keylen;
@@ -166,18 +176,19 @@ struct tcp6_ao_context {__be16 dport;__be32 sisn;__be32 disn; }; -struct tcp_sigpool ;/* Established states are fast-path and there always is current_key/rnext_key */ #define TCP_AO_ESTABLISHED (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 | \ TCPF_CLOSE_WAIT | TCPF_LAST_ACK | TCPF_CLOSING)int tcp_ao_transmit_skb (struct sock *sk,struct sk_buff *skb,struct tcp_ao_key *key,struct tcphdr *th,__u8 *hash_location); +void tcp_ao_mac_update (struct tcp_ao_mac_ctx *mac_ctx,const void *data, +size_t data_len);int tcp_ao_hash_skb (unsigned short int family,char *ao_hash,struct tcp_ao_key *key,const struct sock *sk,const struct sk_buff *skb,const u8 *tkey,int hash_offset,u32 sne); int tcp_parse_ao(struct sock *sk, int cmd, unsigned short int family,
@@ -186,12 +197,12 @@ struct tcp_ao_key *tcp_ao_established_key(const struct sock *sk,struct tcp_ao_info *ao, int sndid, int rcvid);int tcp_ao_copy_all_matching (const struct sock *sk,struct sock *newsk,struct request_sock *req,struct sk_buff *skb,int family); -int tcp_ao_calc_traffic_key (struct tcp_ao_key *mkt,u8 *key,void *ctx, -unsigned int len,struct tcp_sigpool *hp); +void tcp_ao_calc_traffic_key (const struct tcp_ao_key *mkt,u8 *traffic_key, +const void *input,unsigned int input_len);void tcp_ao_destroy_sock (struct sock *sk,bool twsk);void tcp_ao_time_wait (struct tcp_timewait_sock *tcptw,struct tcp_sock *tp);bool tcp_ao_ignore_icmp (const struct sock *sk,int family,int type,int code);int tcp_ao_get_mkts (struct sock *sk,sockptr_t optval,sockptr_t optlen);int tcp_ao_get_sock_info (struct sock *sk,sockptr_t optval,sockptr_t optlen);
@@ -232,11 +243,11 @@ struct tcp_ao_key *tcp_v4_ao_lookup_rsk(const struct sock *sk, int sndid, int rcvid);int tcp_v4_ao_hash_skb (char *ao_hash,struct tcp_ao_key *key,const struct sock *sk,const struct sk_buff *skb,const u8 *tkey,int hash_offset,u32 sne);/* ipv6 specific functions */ -int tcp_v6_ao_hash_pseudoheader (struct tcp_sigpool *hp, +int tcp_v6_ao_hash_pseudoheader (struct tcp_ao_mac_ctx *mac_ctx,const struct in6_addr *daddr,const struct in6_addr *saddr,int nbytes);int tcp_v6_ao_calc_key_skb (struct tcp_ao_key *mkt,u8 *key,const struct sk_buff *skb,__be32 sisn,__be32 disn); int tcp_v6_ao_calc_key_sk(struct tcp_ao_key *mkt, u8 *key,
net/ipv4/Kconfig +3 -2
@@ -745,13 +745,14 @@ config DEFAULT_TCP_CONG config TCP_SIGPOOL tristate config TCP_AO bool "TCP: Authentication Option (RFC5925)" - select CRYPTO + select CRYPTO_LIB_AES_CBC_MACS + select CRYPTO_LIB_SHA1 + select CRYPTO_LIB_SHA256 select CRYPTO_LIB_UTILS - select TCP_SIGPOOL depends on 64BIT && IPV6 != m # seq-number extension needs WRITE_ONCE(u64) help TCP-AO specifies the use of stronger Message Authentication Codes (MACs), protects against replays for long-lived TCP connections, and provides more details on the association of security with TCP
net/ipv4/tcp_ao.c +256 -267
776 lines not on this page · raw message
net/ipv6/tcp_ao.c +26 -37
97 lines not on this page · raw message
tools/testing/selftests/net/tcp_ao/config +0 -2
@@ -1,7 +1,5 @@ -CONFIG_CRYPTO_HMAC=y -CONFIG_CRYPTO_SHA1=y CONFIG_IPV6=y CONFIG_IPV6_MULTIPLE_TABLES=y CONFIG_NET_L3_MASTER_DEV=y CONFIG_NET_VRF=y CONFIG_TCP_AO=y
Signature · 1 line
2.53.0
RFC PATCH 3/8 net/tcp-ao: Use stack-allocated MAC and traffic_key buffers
In reply to Eric BiggersNow that the maximum MAC and traffic key lengths are statically-known small values, allocate MACs and traffic keys on the stack instead of with kmalloc. This eliminates multiple failure-prone GFP_ATOMIC allocations.
Note that some cases such as tcp_ao_prepare_reset() are left unchanged for now since they would require slightly wider changes.
--- net/ipv4/tcp_ao.c | 44 +++++++++++--------------------------------- net/ipv6/tcp_ao.c | 17 +++++------------ 2 files changed, 16 insertions(+), 45 deletions(-)
net/ipv4/tcp_ao.c +11 -33
@@ -737,26 +737,19 @@ int tcp_v4_ao_hash_skb(char *ao_hash, struct tcp_ao_key *key,int tcp_v4_ao_synack_hash (char *ao_hash,struct tcp_ao_key *ao_key,struct request_sock *req,const struct sk_buff *skb,int hash_offset,u32 sne) { -void *hash_buf =NULL ; +u8 tkey_buf[TCP_AO_MAX_TRAFFIC_KEY_LEN ];int err; - hash_buf =kmalloc (tcp_ao_digest_size (ao_key),GFP_ATOMIC ); -if (!hash_buf) -return -ENOMEM ; - - err =tcp_v4_ao_calc_key_rsk (ao_key, hash_buf, req); + err =tcp_v4_ao_calc_key_rsk (ao_key, tkey_buf, req);if (err) - goto out; +return err; - err =tcp_ao_hash_skb (AF_INET , ao_hash, ao_key,req_to_sk (req), skb, - hash_buf, hash_offset, sne); -out: -kfree (hash_buf); -return err; +return tcp_ao_hash_skb (AF_INET , ao_hash, ao_key,req_to_sk (req), skb, + tkey_buf, hash_offset, sne); }struct tcp_ao_key *tcp_v4_ao_lookup_rsk (const struct sock *sk,struct request_sock *req,int sndid,int rcvid)
@@ -867,13 +860,13 @@ int tcp_ao_prepare_reset(const struct sock *sk, struct sk_buff *skb,int tcp_ao_transmit_skb (struct sock *sk,struct sk_buff *skb,struct tcp_ao_key *key,struct tcphdr *th,__u8 *hash_location) {struct tcp_skb_cb *tcb =TCP_SKB_CB (skb); +u8 tkey_buf[TCP_AO_MAX_TRAFFIC_KEY_LEN ];struct tcp_sock *tp =tcp_sk (sk);struct tcp_ao_info *ao; -void *tkey_buf =NULL ;u8 *traffic_key;u32 sne; ao =rcu_dereference_protected (tcp_sk (sk)->ao_info,lockdep_sock_is_held (sk));
@@ -881,13 +874,10 @@ int tcp_ao_transmit_skb(struct sock *sk, struct sk_buff *skb,if (unlikely (tcb->tcp_flags &TCPHDR_SYN )) {__be32 disn;if (!(tcb->tcp_flags &TCPHDR_ACK )) { disn =0 ; - tkey_buf =kmalloc (tcp_ao_digest_size (key),GFP_ATOMIC ); -if (!tkey_buf) -return -ENOMEM ; traffic_key = tkey_buf; }else { disn = ao->risn; } tp->af_specific->ao_calc_key_sk(key, traffic_key,
@@ -895,11 +885,10 @@ int tcp_ao_transmit_skb(struct sock *sk, struct sk_buff *skb, } sne =tcp_ao_compute_sne (READ_ONCE (ao->snd_sne),READ_ONCE (tp->snd_una),ntohl (th->seq)); tp->af_specific->calc_ao_hash (hash_location, key, sk, skb, traffic_key, hash_location - (u8 *)th, sne); -kfree (tkey_buf);return 0 ; } static struct tcp_ao_key *tcp_ao_inbound_lookup(unsigned short int family, const struct sock *sk, const struct sk_buff *skb,
@@ -961,54 +950,48 @@ tcp_ao_verify_hash(const struct sock *sk, const struct sk_buff *skb, const struct tcp_ao_hdr *aoh, struct tcp_ao_key *key, u8 *traffic_key, u8 *phash, u32 sne, int l3index) { const struct tcphdr *th = tcp_hdr(skb);u8 maclen =tcp_ao_hdr_maclen (aoh); -void *hash_buf =NULL ; +u8 hash_buf[TCP_AO_MAX_MAC_LEN ];if (maclen !=tcp_ao_maclen (key)) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPAOBAD );atomic64_inc (&info->counters.pkt_bad);atomic64_inc (&key->pkt_bad);trace_tcp_ao_wrong_maclen (sk, skb, aoh->keyid, aoh->rnext_keyid, maclen);return SKB_DROP_REASON_TCP_AOFAILURE ; } - hash_buf =kmalloc (tcp_ao_digest_size (key),GFP_ATOMIC ); -if (!hash_buf) -return SKB_DROP_REASON_NOT_SPECIFIED ; -/* XXX: make it per-AF callback? */ tcp_ao_hash_skb (family, hash_buf, key, sk, skb, traffic_key, (phash - (u8 *)th), sne);if (crypto_memneq (phash, hash_buf, maclen)) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPAOBAD );atomic64_inc (&info->counters.pkt_bad);atomic64_inc (&key->pkt_bad);trace_tcp_ao_mismatch (sk, skb, aoh->keyid, aoh->rnext_keyid, maclen); -kfree (hash_buf);return SKB_DROP_REASON_TCP_AOFAILURE ; }NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPAOGOOD );atomic64_inc (&info->counters.pkt_good);atomic64_inc (&key->pkt_good); -kfree (hash_buf);return SKB_NOT_DROPPED_YET ; }enum skb_drop_reason tcp_inbound_ao_hash (struct sock *sk,const struct sk_buff *skb,unsigned short int family,const struct request_sock *req,int l3index,const struct tcp_ao_hdr *aoh) { +u8 tkey_buf[TCP_AO_MAX_TRAFFIC_KEY_LEN ];const struct tcphdr *th =tcp_hdr (skb);u8 maclen =tcp_ao_hdr_maclen (aoh);u8 *phash = (u8 *)(aoh +1 );/* hash goes just after the header */ struct tcp_ao_info *info; -enum skb_drop_reason ret;struct tcp_ao_key *key;__be32 sisn, disn;u8 *traffic_key;int state;u32 sne =0 ;
@@ -1112,18 +1095,13 @@ tcp_inbound_ao_hash(struct sock *sk, const struct sk_buff *skb, }else {WARN_ONCE (1 ,"TCP-AO: Unexpected sk_state %d" , state);return SKB_DROP_REASON_TCP_AOFAILURE ; } verify_hash: - traffic_key =kmalloc (tcp_ao_digest_size (key),GFP_ATOMIC ); -if (!traffic_key) -return SKB_DROP_REASON_NOT_SPECIFIED ; -tcp_ao_calc_key_skb (key, traffic_key, skb, sisn, disn, family); - ret =tcp_ao_verify_hash (sk, skb, family, info, aoh, key, - traffic_key, phash, sne, l3index); -kfree (traffic_key); -return ret; +tcp_ao_calc_key_skb (key, tkey_buf, skb, sisn, disn, family); +return tcp_ao_verify_hash (sk, skb, family, info, aoh, key, + tkey_buf, phash, sne, l3index); key_not_found:NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPAOKEYNOTFOUND );atomic64_inc (&info->counters.key_not_found); trace_tcp_ao_key_not_found(sk, skb, aoh->keyid,
net/ipv6/tcp_ao.c +5 -12
@@ -136,22 +136,15 @@ int tcp_v6_parse_ao(struct sock *sk, int cmd,int tcp_v6_ao_synack_hash (char *ao_hash,struct tcp_ao_key *ao_key,struct request_sock *req,const struct sk_buff *skb,int hash_offset,u32 sne) { -void *hash_buf =NULL ; +u8 tkey_buf[TCP_AO_MAX_TRAFFIC_KEY_LEN ];int err; - hash_buf =kmalloc (tcp_ao_digest_size (ao_key),GFP_ATOMIC ); -if (!hash_buf) -return -ENOMEM ; - - err =tcp_v6_ao_calc_key_rsk (ao_key, hash_buf, req); + err =tcp_v6_ao_calc_key_rsk (ao_key, tkey_buf, req);if (err) - goto out; +return err; - err =tcp_ao_hash_skb (AF_INET6 , ao_hash, ao_key,req_to_sk (req), skb, - hash_buf, hash_offset, sne); -out: -kfree (hash_buf); -return err; +return tcp_ao_hash_skb (AF_INET6 , ao_hash, ao_key,req_to_sk (req), skb, + tkey_buf, hash_offset, sne); }
Signature · 1 line
2.53.0
RFC PATCH 4/8 net/tcp-ao: Return void from functions that can no longer fail
In reply to Eric BiggersSince tcp-ao now uses the crypto library API instead of crypto_ahash, and MACs and keys now have a statically-known maximum size, many tcp-ao functions can no longer fail. Propagate this change up into the return types of various functions.
--- include/net/tcp.h | 8 +-- include/net/tcp_ao.h | 44 +++++++-------- net/ipv4/tcp_ao.c | 128 ++++++++++++++++++++++-------------------- net/ipv4/tcp_output.c | 10 +--- net/ipv6/tcp_ao.c | 65 ++++++++++----------- 5 files changed, 123 insertions(+), 132 deletions(-)
include/net/tcp.h +4 -4
@@ -2426,13 +2426,13 @@ struct tcp_sock_af_ops {#ifdef CONFIG_TCP_AO int (*ao_parse)(struct sock *sk,int optname,sockptr_t optval,int optlen);struct tcp_ao_key *(*ao_lookup)(const struct sock *sk,struct sock *addr_sk,int sndid,int rcvid); -int (*ao_calc_key_sk)(struct tcp_ao_key *mkt,u8 *key, -const struct sock *sk, -__be32 sisn,__be32 disn,bool send); +void (*ao_calc_key_sk)(struct tcp_ao_key *mkt,u8 *key, +const struct sock *sk, +__be32 sisn,__be32 disn,bool send);int (*calc_ao_hash)(char *location,struct tcp_ao_key *ao,const struct sock *sk,const struct sk_buff *skb,const u8 *tkey,int hash_offset,u32 sne);#endif };
@@ -2449,11 +2449,11 @@ struct tcp_request_sock_ops {#endif #ifdef CONFIG_TCP_AO struct tcp_ao_key *(*ao_lookup)(const struct sock *sk,struct request_sock *req,int sndid,int rcvid); -int (*ao_calc_key)(struct tcp_ao_key *mkt,u8 *key,struct request_sock *sk); +void (*ao_calc_key)(struct tcp_ao_key *mkt,u8 *key,struct request_sock *sk);int (*ao_synack_hash)(char *ao_hash,struct tcp_ao_key *mkt,struct request_sock *req,const struct sk_buff *skb,int hash_offset,u32 sne);#endif #ifdef CONFIG_SYN_COOKIES
include/net/tcp_ao.h +22 -22
82 lines not on this page · raw message
net/ipv4/tcp_ao.c +66 -62
245 lines not on this page · raw message
net/ipv4/tcp_output.c +2 -8
@@ -1644,18 +1644,12 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,sk_gso_disable (sk); tp->af_specific->calc_md5_hash (opts.hash_location, key.md5_key, sk, skb);#endif }else if (tcp_key_is_ao (&key)) { -int err; - - err =tcp_ao_transmit_skb (sk, skb, key.ao_key, th, - opts.hash_location); -if (err) { -sk_skb_reason_drop (sk, skb,SKB_DROP_REASON_NOT_SPECIFIED ); -return -ENOMEM ; - } +tcp_ao_transmit_skb (sk, skb, key.ao_key, th, + opts.hash_location); }/* BPF prog is the last one writing header option */ bpf_skops_write_hdr_opt (sk, skb,NULL ,NULL ,0 , &opts);
net/ipv6/tcp_ao.c +29 -36
131 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC PATCH 5/8 net/tcp: Remove tcp_sigpool
In reply to Eric Biggerstcp_sigpool is no longer used. It existed only as a workaround for issues in the design of the crypto_ahash API, which have been avoided by switching to the much easier-to-use library APIs instead. Remove it.
--- include/net/tcp.h | 34 ---- net/ipv4/Kconfig | 3 - net/ipv4/Makefile | 1 - net/ipv4/tcp_sigpool.c | 366 ----------------------------------------- 4 files changed, 404 deletions(-) delete mode 100644 net/ipv4/tcp_sigpool.c
include/net/tcp.h +0 -34
@@ -1968,44 +1968,10 @@ struct tcp6_pseudohdr {struct in6_addr daddr;__be32 len;__be32 protocol;/* including padding */ }; -/* -* struct tcp_sigpool - per-CPU pool of ahash_requests -* @scratch: per-CPU temporary area, that can be used between -* tcp_sigpool_start() and tcp_sigpool_end() to perform -* crypto request -* @req: pre-allocated ahash request -*/ -struct tcp_sigpool { -void *scratch; -struct ahash_request *req; -}; - -int tcp_sigpool_alloc_ahash (const char *alg,size_t scratch_size); -void tcp_sigpool_get (unsigned int id); -void tcp_sigpool_release (unsigned int id); -int tcp_sigpool_hash_skb_data (struct tcp_sigpool *hp, -const struct sk_buff *skb, -unsigned int header_len); - -/** -* tcp_sigpool_start - disable bh and start using tcp_sigpool_ahash -* @id: tcp_sigpool that was previously allocated by tcp_sigpool_alloc_ahash() -* @c: returned tcp_sigpool for usage (uninitialized on failure) -* -* Returns: 0 on success, error otherwise. -*/ -int tcp_sigpool_start (unsigned int id,struct tcp_sigpool *c); -/** -* tcp_sigpool_end - enable bh and stop using tcp_sigpool -* @c: tcp_sigpool context that was returned by tcp_sigpool_start() -*/ -void tcp_sigpool_end (struct tcp_sigpool *c); -size_t tcp_sigpool_algo (unsigned int id,char *buf,size_t buf_len); -/* - functions */ void tcp_v4_md5_hash_skb (char *md5_hash,const struct tcp_md5sig_key *key,const struct sock *sk,const struct sk_buff *skb);int tcp_md5_do_add (struct sock *sk,const union tcp_md5_addr *addr,int family,u8 prefixlen,int l3index,u8 flags,const u8 *newkey,u8 newkeylen);
net/ipv4/Kconfig +0 -3
@@ -740,13 +740,10 @@ config DEFAULT_TCP_CONG default "dctcp" if DEFAULT_DCTCP default "cdg" if DEFAULT_CDG default "bbr" if DEFAULT_BBR default "cubic" -config TCP_SIGPOOL - tristate - config TCP_AO bool "TCP: Authentication Option (RFC5925)" select CRYPTO_LIB_AES_CBC_MACS select CRYPTO_LIB_SHA1 select CRYPTO_LIB_SHA256
net/ipv4/Makefile +0 -1
@@ -58,11 +58,10 @@ obj-$(CONFIG_TCP_CONG_NV) += tcp_nv.o obj-$(CONFIG_TCP_CONG_VENO) += tcp_veno.o obj-$(CONFIG_TCP_CONG_SCALABLE) += tcp_scalable.o obj-$(CONFIG_TCP_CONG_LP) += tcp_lp.o obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah.o obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o -obj-$(CONFIG_TCP_SIGPOOL) += tcp_sigpool.o obj-$(CONFIG_NET_SOCK_MSG) += tcp_bpf.o obj-$(CONFIG_BPF_SYSCALL) += udp_bpf.o obj-$(CONFIG_NETLABEL) += cipso_ipv4.o obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \
net/ipv4/tcp_sigpool.c deleted +0 -366
366 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC PATCH 6/8 crypto: hash - Remove support for cloning hash tfms
In reply to Eric BiggersHash transformation cloning no longer has a user, and there's a good chance no new one will appear because the library API solves the problem in a much simpler and more efficient way. Remove support for it.
--- crypto/ahash.c | 70 ------------------------------------------- crypto/cmac.c | 16 ---------- crypto/cryptd.c | 16 ---------- crypto/hmac.c | 31 ------------------- crypto/shash.c | 37 ----------------------- include/crypto/hash.h | 8 ----- 6 files changed, 178 deletions(-)
crypto/ahash.c +0 -70
@@ -860,80 +860,10 @@ bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg)return __crypto_ahash_alg (alg)->setkey != ahash_nosetkey; }EXPORT_SYMBOL_GPL (crypto_hash_alg_has_setkey); -struct crypto_ahash *crypto_clone_ahash (struct crypto_ahash *hash) -{ -struct hash_alg_common *halg =crypto_hash_alg_common (hash); -struct crypto_tfm *tfm =crypto_ahash_tfm (hash); -struct crypto_ahash *fb =NULL ; -struct crypto_ahash *nhash; -struct ahash_alg *alg; -int err; - -if (!crypto_hash_alg_has_setkey (halg)) { - tfm =crypto_tfm_get (tfm); -if (IS_ERR (tfm)) -return ERR_CAST (tfm); - -return hash; - } - - nhash =crypto_clone_tfm (&crypto_ahash_type, tfm); - -if (IS_ERR (nhash)) -return nhash; - - nhash->reqsize = hash->reqsize; - nhash->statesize = hash->statesize; - -if (likely (hash->using_shash)) { -struct crypto_shash **nctx =crypto_ahash_ctx (nhash); -struct crypto_shash *shash; - - shash =crypto_clone_shash (ahash_to_shash (hash)); -if (IS_ERR (shash)) { - err =PTR_ERR (shash); - goto out_free_nhash; - } -crypto_ahash_tfm (nhash)->exit = crypto_exit_ahash_using_shash; - nhash->using_shash = true; - *nctx = shash; -return nhash; - } - -if (crypto_ahash_need_fallback (hash)) { - fb =crypto_clone_ahash (crypto_ahash_fb (hash)); - err =PTR_ERR (fb); -if (IS_ERR (fb)) - goto out_free_nhash; - -crypto_ahash_tfm (nhash)->fb =crypto_ahash_tfm (fb); - } - - err = -ENOSYS ; - alg =crypto_ahash_alg (hash); -if (!alg->clone_tfm) - goto out_free_fb; - - err = alg->clone_tfm (nhash, hash); -if (err) - goto out_free_fb; - -crypto_ahash_tfm (nhash)->exit = crypto_ahash_exit_tfm; - -return nhash; - -out_free_fb: -crypto_free_ahash (fb); -out_free_nhash: -crypto_free_ahash (nhash); -return ERR_PTR (err); -} -EXPORT_SYMBOL_GPL (crypto_clone_ahash); -static int ahash_default_export_core (struct ahash_request *req,void *out) {return -ENOSYS ; }
crypto/cmac.c +0 -16
@@ -149,25 +149,10 @@ static int cmac_init_tfm(struct crypto_shash *tfm) ctx->child = cipher;return 0 ; } -static int cmac_clone_tfm (struct crypto_shash *tfm,struct crypto_shash *otfm) -{ -struct cmac_tfm_ctx *octx =crypto_shash_ctx (otfm); -struct cmac_tfm_ctx *ctx =crypto_shash_ctx (tfm); -struct crypto_cipher *cipher; - - cipher =crypto_clone_cipher (octx->child); -if (IS_ERR (cipher)) -return PTR_ERR (cipher); - - ctx->child = cipher; - -return 0 ; -} -static void cmac_exit_tfm (struct crypto_shash *tfm) {struct cmac_tfm_ctx *ctx =crypto_shash_ctx (tfm);crypto_free_cipher (ctx->child); }
@@ -220,11 +205,10 @@ static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb) inst->alg.init = crypto_cmac_digest_init; inst->alg.update = crypto_cmac_digest_update; inst->alg.finup = crypto_cmac_digest_finup; inst->alg.setkey = crypto_cmac_digest_setkey; inst->alg.init_tfm = cmac_init_tfm; - inst->alg.clone_tfm = cmac_clone_tfm; inst->alg.exit_tfm = cmac_exit_tfm; inst->free = shash_free_singlespawn_instance; err =shash_register_instance (tmpl, inst);
crypto/cryptd.c +0 -16
@@ -450,25 +450,10 @@ static int cryptd_hash_init_tfm(struct crypto_ahash *tfm)sizeof (struct cryptd_hash_request_ctx ) + crypto_shash_descsize(hash));return 0 ; } -static int cryptd_hash_clone_tfm (struct crypto_ahash *ntfm, -struct crypto_ahash *tfm) -{ -struct cryptd_hash_ctx *nctx =crypto_ahash_ctx (ntfm); -struct cryptd_hash_ctx *ctx =crypto_ahash_ctx (tfm); -struct crypto_shash *hash; - - hash =crypto_clone_shash (ctx->child); -if (IS_ERR (hash)) -return PTR_ERR (hash); - - nctx->child = hash; -return 0 ; -} -static void cryptd_hash_exit_tfm (struct crypto_ahash *tfm) {struct cryptd_hash_ctx *ctx =crypto_ahash_ctx (tfm);crypto_free_shash (ctx->child);
@@ -697,11 +682,10 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, inst->alg.halg.digestsize = alg->digestsize; inst->alg.halg.statesize = alg->statesize; inst->alg.halg.base.cra_ctxsize =sizeof (struct cryptd_hash_ctx ); inst->alg.init_tfm = cryptd_hash_init_tfm; - inst->alg.clone_tfm = cryptd_hash_clone_tfm; inst->alg.exit_tfm = cryptd_hash_exit_tfm; inst->alg.init = cryptd_hash_init_enqueue; inst->alg.update = cryptd_hash_update_enqueue; inst->alg.final = cryptd_hash_final_enqueue;
crypto/hmac.c +0 -31
@@ -156,24 +156,10 @@ static int hmac_init_tfm(struct crypto_shash *parent) tctx->hash = hash;return 0 ; } -static int hmac_clone_tfm (struct crypto_shash *dst,struct crypto_shash *src) -{ -struct hmac_ctx *sctx =crypto_shash_ctx (src); -struct hmac_ctx *dctx =crypto_shash_ctx (dst); -struct crypto_shash *hash; - - hash =crypto_clone_shash (sctx->hash); -if (IS_ERR (hash)) -return PTR_ERR (hash); - - dctx->hash = hash; -return 0 ; -} -static void hmac_exit_tfm (struct crypto_shash *parent) {struct hmac_ctx *tctx =crypto_shash_ctx (parent);crypto_free_shash (tctx->hash);
@@ -233,11 +219,10 @@ static int __hmac_create_shash(struct crypto_template *tmpl, inst->alg.import = hmac_import; inst->alg.export_core = hmac_export_core; inst->alg.import_core = hmac_import_core; inst->alg.setkey = hmac_setkey; inst->alg.init_tfm = hmac_init_tfm; - inst->alg.clone_tfm = hmac_clone_tfm; inst->alg.exit_tfm = hmac_exit_tfm; inst->free = shash_free_singlespawn_instance; err =shash_register_instance (tmpl, inst);
@@ -421,25 +406,10 @@ static int hmac_init_ahash_tfm(struct crypto_ahash *parent) tctx->hash = hash;return 0 ; } -static int hmac_clone_ahash_tfm (struct crypto_ahash *dst, -struct crypto_ahash *src) -{ -struct ahash_hmac_ctx *sctx =crypto_ahash_ctx (src); -struct ahash_hmac_ctx *dctx =crypto_ahash_ctx (dst); -struct crypto_ahash *hash; - - hash =crypto_clone_ahash (sctx->hash); -if (IS_ERR (hash)) -return PTR_ERR (hash); - - dctx->hash = hash; -return 0 ; -} -static void hmac_exit_ahash_tfm (struct crypto_ahash *parent) {struct ahash_hmac_ctx *tctx =crypto_ahash_ctx (parent);crypto_free_ahash (tctx->hash);
@@ -501,11 +471,10 @@ static int hmac_create_ahash(struct crypto_template *tmpl, struct rtattr **tb, inst->alg.import = hmac_import_ahash; inst->alg.export_core = hmac_export_core_ahash; inst->alg.import_core = hmac_import_core_ahash; inst->alg.setkey = hmac_setkey_ahash; inst->alg.init_tfm = hmac_init_ahash_tfm; - inst->alg.clone_tfm = hmac_clone_ahash_tfm; inst->alg.exit_tfm = hmac_exit_ahash_tfm; inst->free = ahash_free_singlespawn_instance; err =ahash_register_instance (tmpl, inst);
crypto/shash.c +0 -37
@@ -393,47 +393,10 @@ int crypto_has_shash(const char *alg_name, u32 type, u32 mask) {return crypto_type_has_alg (alg_name, &crypto_shash_type, type, mask); }EXPORT_SYMBOL_GPL (crypto_has_shash); -struct crypto_shash *crypto_clone_shash (struct crypto_shash *hash) -{ -struct crypto_tfm *tfm =crypto_shash_tfm (hash); -struct shash_alg *alg =crypto_shash_alg (hash); -struct crypto_shash *nhash; -int err; - -if (!crypto_shash_alg_has_setkey (alg)) { - tfm =crypto_tfm_get (tfm); -if (IS_ERR (tfm)) -return ERR_CAST (tfm); - -return hash; - } - -if (!alg->clone_tfm && (alg->init_tfm || alg->base.cra_init)) -return ERR_PTR (-ENOSYS ); - - nhash =crypto_clone_tfm (&crypto_shash_type, tfm); -if (IS_ERR (nhash)) -return nhash; - -if (alg->clone_tfm) { - err = alg->clone_tfm (nhash, hash); -if (err) { -crypto_free_shash (nhash); -return ERR_PTR (err); - } - } - -if (alg->exit_tfm) -crypto_shash_tfm (nhash)->exit = crypto_shash_exit_tfm; - -return nhash; -} -EXPORT_SYMBOL_GPL (crypto_clone_shash); -int hash_prepare_alg (struct hash_alg_common *alg) {struct crypto_alg *base = &alg->base;if (alg->digestsize >HASH_MAX_DIGESTSIZE )
include/crypto/hash.h +0 -8
@@ -146,11 +146,10 @@ struct ahash_request {* requirement of the transformation and put any software * fallbacks in place. * @exit_tfm: Deinitialize the cryptographic transformation object. * This is a counterpart to @init_tfm, used to remove * various changes set in @init_tfm. -* @clone_tfm: Copy transform into new object, may allocate memory. * @halg: see struct hash_alg_common */ struct ahash_alg {int (*init)(struct ahash_request *req);int (*update)(struct ahash_request *req);
@@ -163,11 +162,10 @@ struct ahash_alg {int (*import_core)(struct ahash_request *req,const void *in);int (*setkey)(struct crypto_ahash *tfm,const u8 *key,unsigned int keylen);int (*init_tfm)(struct crypto_ahash *tfm);void (*exit_tfm)(struct crypto_ahash *tfm); -int (*clone_tfm)(struct crypto_ahash *dst,struct crypto_ahash *src);struct hash_alg_common halg; };struct shash_desc {
@@ -237,11 +235,10 @@ struct shash_desc {* requirement of the transformation and put any software * fallbacks in place. * @exit_tfm: Deinitialize the cryptographic transformation object. * This is a counterpart to @init_tfm, used to remove * various changes set in @init_tfm. -* @clone_tfm: Copy transform into new object, may allocate memory. * @descsize: Size of the operational state for the message digest. This state * size is the memory size that needs to be allocated for * shash_desc.__ctx * @halg: see struct hash_alg_common * @HASH_ALG_COMMON: see struct hash_alg_common
@@ -261,11 +258,10 @@ struct shash_alg {int (*import_core)(struct shash_desc *desc,const void *in);int (*setkey)(struct crypto_shash *tfm,const u8 *key,unsigned int keylen);int (*init_tfm)(struct crypto_shash *tfm);void (*exit_tfm)(struct crypto_shash *tfm); -int (*clone_tfm)(struct crypto_shash *dst,struct crypto_shash *src);unsigned int descsize;union {struct HASH_ALG_COMMON ;
@@ -320,12 +316,10 @@ static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm)* of an error, PTR_ERR() returns the error code. */ struct crypto_ahash *crypto_alloc_ahash (const char *alg_name,u32 type,u32 mask); -struct crypto_ahash *crypto_clone_ahash (struct crypto_ahash *tfm); -static inline struct crypto_tfm *crypto_ahash_tfm (struct crypto_ahash *tfm) {return &tfm->base; }
@@ -757,12 +751,10 @@ static inline void ahash_request_set_virt(struct ahash_request *req,* of an error, PTR_ERR() returns the error code. */ struct crypto_shash *crypto_alloc_shash (const char *alg_name,u32 type,u32 mask); -struct crypto_shash *crypto_clone_shash (struct crypto_shash *tfm); -int crypto_has_shash (const char *alg_name,u32 type,u32 mask);static inline struct crypto_tfm *crypto_shash_tfm (struct crypto_shash *tfm) {return &tfm->base;
Signature · 1 line
2.53.0
RFC PATCH 7/8 crypto: cipher - Remove support for cloning cipher tfms
In reply to Eric BiggersSince the only caller of crypto_clone_cipher() was cmac_clone_tfm() which has been removed, remove crypto_clone_cipher() as well.
--- crypto/cipher.c | 28 ---------------------------- include/crypto/internal/cipher.h | 2 -- 2 files changed, 30 deletions(-)
crypto/cipher.c +0 -28
@@ -87,33 +87,5 @@ void crypto_cipher_decrypt_one(struct crypto_cipher *tfm, u8 *dst, const u8 *src) {cipher_crypt_one (tfm ,dst ,src ,false ); }EXPORT_SYMBOL_NS_GPL (crypto_cipher_decrypt_one,"CRYPTO_INTERNAL" ); - -struct crypto_cipher *crypto_clone_cipher (struct crypto_cipher *cipher) -{ -struct crypto_tfm *tfm =crypto_cipher_tfm (cipher); -struct crypto_alg *alg = tfm->__crt_alg; -struct crypto_cipher *ncipher; -struct crypto_tfm *ntfm; - -if (alg->cra_init) -return ERR_PTR (-ENOSYS ); - -if (unlikely (!crypto_mod_get (alg))) -return ERR_PTR (-ESTALE ); - - ntfm =__crypto_alloc_tfmgfp (alg,CRYPTO_ALG_TYPE_CIPHER , -CRYPTO_ALG_TYPE_MASK ,GFP_ATOMIC ); -if (IS_ERR (ntfm)) { -crypto_mod_put (alg); -return ERR_CAST (ntfm); - } - - ntfm->crt_flags = tfm->crt_flags; - - ncipher =__crypto_cipher_cast (ntfm); - -return ncipher; -} -EXPORT_SYMBOL_GPL (crypto_clone_cipher);
include/crypto/internal/cipher.h +0 -2
@@ -174,12 +174,10 @@ void crypto_cipher_encrypt_one(struct crypto_cipher *tfm,* the plaintext and ciphertext buffers are at least one block in size. */ void crypto_cipher_decrypt_one (struct crypto_cipher *tfm,u8 *dst,const u8 *src); -struct crypto_cipher *crypto_clone_cipher (struct crypto_cipher *cipher); -struct crypto_cipher_spawn {struct crypto_spawn base; }; static inline int crypto_grab_cipher(struct crypto_cipher_spawn *spawn,
Signature · 1 line
2.53.0
RFC PATCH 8/8 crypto: api - Remove core support for cloning tfms
In reply to Eric BiggersSince all callers of crypto_clone_tfm() have been removed, remove it.
--- crypto/api.c | 26 -------------------------- crypto/internal.h | 2 -- 2 files changed, 28 deletions(-)
crypto/api.c +0 -26
@@ -558,36 +558,10 @@ void *crypto_create_tfm_node(struct crypto_alg *alg, out:return mem; }EXPORT_SYMBOL_GPL (crypto_create_tfm_node); -void *crypto_clone_tfm (const struct crypto_type *frontend, -struct crypto_tfm *otfm) -{ -struct crypto_alg *alg = otfm->__crt_alg; -struct crypto_tfm *tfm; -char *mem; - - mem =ERR_PTR (-ESTALE ); -if (unlikely (!crypto_mod_get (alg))) - goto out; - - mem =crypto_alloc_tfmmem (alg, frontend, otfm->node,GFP_ATOMIC ); -if (IS_ERR (mem)) { -crypto_mod_put (alg); - goto out; - } - - tfm = (struct crypto_tfm *)(mem + frontend->tfmsize); - tfm->crt_flags = otfm->crt_flags; - tfm->fb = tfm; - -out: -return mem; -} -EXPORT_SYMBOL_GPL (crypto_clone_tfm); -struct crypto_alg *crypto_find_alg (const char *alg_name,const struct crypto_type *frontend,u32 type,u32 mask) {if (frontend) {
crypto/internal.h +0 -2
@@ -124,12 +124,10 @@ struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, u32 mask, gfp_t gfp);struct crypto_tfm *__crypto_alloc_tfm (struct crypto_alg *alg,u32 type,u32 mask);void *crypto_create_tfm_node (struct crypto_alg *alg,const struct crypto_type *frontend,int node); -void *crypto_clone_tfm (const struct crypto_type *frontend, -struct crypto_tfm *otfm);static inline void *crypto_create_tfm (struct crypto_alg *alg,const struct crypto_type *frontend) {return crypto_create_tfm_node (alg, frontend,NUMA_NO_NODE );
Signature · 1 line
2.53.0
Quoted 37 lines · Eric Biggers
This series can also be retrieved from:
git fetch
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git
tcp-ao-v1For now this series is an RFC, since it depends on the AES-CMAC library API that is queued in libcrypto-next for 7.1. So, the soonest that this could be applied to net-next is 7.2. I'm sending it out now in case anyone has any early feedback.
This series refactors the TCP-AO (TCP Authentication Option) code to do MAC and KDF computations using
lib/crypto/instead ofcrypto_ahash. This greatly simplifies the code and makes it much more efficient. The entiretcp_sigpoolandcrypto_ahashcloning mechanisms become unnecessary and are removed, as the problems they were designed to solve don't exist with the library APIs.To make this possible, this series also restricts the supported algorithms to a reasonable set, rather than supporting arbitrary algorithms that don't make sense and are very likely not being used. Specifically, this series leaves in place the support for AES-128-CMAC and HMAC-SHA1 which are the only algorithms that actually have an RFC specifying their use in TCP-AO, along with HMAC-SHA256 which is a reasonable algorithm to continue supporting as a Linux extension.
This passes the
tcp_aoselftests (tools/testing/selftests/net/tcp_ao).To get a sense for how much more efficient this makes the TCP-AO code, here's a microbenchmark for
tcp_ao_hash_skb()withskb->len== 128:Algorithm Avg cycles (before) Avg cycles (after) --------- ------------------- ------------------ HMAC-SHA1 3319 1256 HMAC-SHA256 3311 1344 AES-128-CMAC 2720 1107
Quoted 10 lines
Eric Biggers (8):
net/tcp-ao: Drop support for most non-RFC-specified algorithmsnet/tcp-ao: Use crypto library API instead ofcrypto_ahashnet/tcp-ao: Use stack-allocated MAC andtraffic_keybuffersnet/tcp-ao: Return void from functions that can no longer fail net/tcp: Removetcp_sigpool
crypto: hash - Remove support for cloning hash tfms
crypto: cipher - Remove support for cloning cipher tfms
crypto: api - Remove core support for cloning tfms
I wonder how widely this is being used, given that there are much cheaper options than CMAC or HMAC, and nobody bothered to ratify the HMAC-SHA256 draft.
Anybody have any insights?
Hi Eric,
On Sat, 7 Mar 2026 at 22:46, Eric Biggers <[email protected]> wrote:
[..]
Quoted 17 lines
This series refactors the TCP-AO (TCP Authentication Option) code to do MAC and KDF computations using
lib/crypto/instead ofcrypto_ahash. This greatly simplifies the code and makes it much more efficient. The entiretcp_sigpoolandcrypto_ahashcloning mechanisms become unnecessary and are removed, as the problems they were designed to solve don't exist with the library APIs.To make this possible, this series also restricts the supported algorithms to a reasonable set, rather than supporting arbitrary algorithms that don't make sense and are very likely not being used. Specifically, this series leaves in place the support for AES-128-CMAC and HMAC-SHA1 which are the only algorithms that actually have an RFC specifying their use in TCP-AO, along with HMAC-SHA256 which is a reasonable algorithm to continue supporting as a Linux extension.
This passes the
tcp_aoselftests (tools/testing/selftests/net/tcp_ao).
Quoted 8 lines
To get a sense for how much more efficient this makes the TCP-AO code, here's a microbenchmark for
tcp_ao_hash_skb()withskb->len== 128:Algorithm Avg cycles (before) Avg cycles (after) --------- ------------------- ------------------ HMAC-SHA1 3319 1256 HMAC-SHA256 3311 1344 AES-128-CMAC 2720 1107
I like the numbers that you achieved here and tcp_sigpool riddance. If you want to measure the throughput difference, there are iperf hacks I made at the time of upstreaming TCP-AO:
https://github.com/0x7f454c46/iperf/tree/tcp-md5-ao
We certainly have to support AES-128-CMAC, HMAC-SHA1 and HMAC-SHA2. For the last one, we specifically had an RFE from a customer.
It's a little pity to go from ">> Additional algorithms, beyond those mandated for TCP-AO, MAY be supported." back to "The mandatory-to-implement MAC algorithms for use with TCP-AO are described in a separate RFC [RFC5926]." as I've always enjoyed Linux (and opensource in general) that provides more flexibility than just strict mandatory required options - that's why I originally intentionally gave a user options to use not only mandatory algorithms. Well, that's sentimental, and yet I see that other BGP implementations already allow these optional algorithms.
I.e.:
"Of course, TCP-AO key contains a shared secret key. It is specified by the option secret as a text string or as a sequence of hexadecimal digit pairs (bytestring).
Used cryptographic algorithm can be specified for each key with the option algorithm. Possible values are: hmac md5, hmac sha1, hmac sha224, hmac sha256, hmac sha384, hmac sha512, and cmac aes128. Default value is hmac sha1." [1][2]
I guess that may cause a regression for an existing config. So, I don't know, could we get your big speedup and yet let the user choose what algorithm they want to use? Basically, making tcp_ao_hash_skb() a callback with optional algorithms implementation and a faster mandatory algorithms that will use hmac_sha1_init_usingrawkey(), hmac_sha256_init_usingrawkey(), aes_cmac_preparekey()?
[1] https://bird.nic.cz/doc/bird-3.2.0.html
[2] https://github.com/CZ-NIC/bird/blob/0ee9f93bd076c5cc425ceaec9acedbbb7c9021ec/sysdep/linux/sysio.h#L246
Thanks,
Dmitry
Quoted 32 lines · Dmitry Safonov
I like the numbers that you achieved here and
tcp_sigpoolriddance. If you want to measure the throughput difference, there are iperf hacks I made at the time of upstreaming TCP-AO:
https://github.com/0x7f454c46/iperf/tree/tcp-md5-aoWe certainly have to support AES-128-CMAC, HMAC-SHA1 and HMAC-SHA2. For the last one, we specifically had an RFE from a customer.
It's a little pity to go from ">> Additional algorithms, beyond those mandated for TCP-AO, MAY be supported." back to "The mandatory-to-implement MAC algorithms for use with TCP-AO are described in a separate RFC [RFC5926]." as I've always enjoyed Linux (and opensource in general) that provides more flexibility than just strict mandatory required options
I.e.:
"Of course, TCP-AO key contains a shared secret key. It is specified by the option secret as a text string or as a sequence of hexadecimal digit pairs (bytestring).
Used cryptographic algorithm can be specified for each key with the option algorithm. Possible values are: hmac md5, hmac sha1, hmac sha224, hmac sha256, hmac sha384, hmac sha512, and cmac aes128. Default value is hmac sha1." [1][2]I guess that may cause a regression for an existing config. So, I don't know, could we get your big speedup and yet let the user choose what algorithm they want to use? Basically, making
tcp_ao_hash_skb()a callback with optional algorithms implementation and a faster mandatory algorithms that will usehmac_sha1_init_usingrawkey(),hmac_sha256_init_usingrawkey(),aes_cmac_preparekey()?
Quoted 2 lines
[1] https://bird.nic.cz/doc/bird-3.2.0.html
[2] https://github.com/CZ-NIC/bird/blob/0ee9f93bd076c5cc425ceaec9acedbbb7c9021ec/sysdep/linux/sysio.h#L246
This series already preserves the nonstandard but reasonable HMAC-SHA256 support as a Linux extension. And users retain a choice of algorithms. Maybe think of it as helping them make that choice by dropping things that we know (but the user may not know) should not be chosen.
I mean, even CRC-32 was an option for the MAC. Really? That's something that should be a CVE, not a "feature that demonstrates the flexibility of open source software".
Offering all four variants of HMAC-SHA2 is also almost entirely pointless here, given that TCP-AO MACs are limited to 20 bytes by the TCP options space anyway.
If there are specific additional algorithm(s) that are actually needed for backwards compatibility, then we can add them to the list of algorithms that the new implementation supports. However, do you actually know of any user using anything other than HMAC-SHA1, HMAC-SHA256, or AES-128-CMAC? If so, what is their use case?
But let's not keep the crypto_ahash based implementation of TCP-AO around as well, as there's a massive amount of complexity and inefficiency in it. I think this series makes that very clear.
- Eric
Quoted 55 lines · Eric Biggers
Quoted 32 lines · Dmitry Safonov
I like the numbers that you achieved here and
tcp_sigpoolriddance. If you want to measure the throughput difference, there are iperf hacks I made at the time of upstreaming TCP-AO:
https://github.com/0x7f454c46/iperf/tree/tcp-md5-aoWe certainly have to support AES-128-CMAC, HMAC-SHA1 and HMAC-SHA2. For the last one, we specifically had an RFE from a customer.
It's a little pity to go from ">> Additional algorithms, beyond those mandated for TCP-AO, MAY be supported." back to "The mandatory-to-implement MAC algorithms for use with TCP-AO are described in a separate RFC [RFC5926]." as I've always enjoyed Linux (and opensource in general) that provides more flexibility than just strict mandatory required options
I.e.:
"Of course, TCP-AO key contains a shared secret key. It is specified by the option secret as a text string or as a sequence of hexadecimal digit pairs (bytestring).
Used cryptographic algorithm can be specified for each key with the option algorithm. Possible values are: hmac md5, hmac sha1, hmac sha224, hmac sha256, hmac sha384, hmac sha512, and cmac aes128. Default value is hmac sha1." [1][2]I guess that may cause a regression for an existing config. So, I don't know, could we get your big speedup and yet let the user choose what algorithm they want to use? Basically, making
tcp_ao_hash_skb()a callback with optional algorithms implementation and a faster mandatory algorithms that will usehmac_sha1_init_usingrawkey(),hmac_sha256_init_usingrawkey(),aes_cmac_preparekey()?Quoted 2 lines
[1] https://bird.nic.cz/doc/bird-3.2.0.html
[2] https://github.com/CZ-NIC/bird/blob/0ee9f93bd076c5cc425ceaec9acedbbb7c9021ec/sysdep/linux/sysio.h#L246This series already preserves the nonstandard but reasonable HMAC-SHA256 support as a Linux extension. And users retain a choice of algorithms. Maybe think of it as helping them make that choice by dropping things that we know (but the user may not know) should not be chosen.
I mean, even CRC-32 was an option for the MAC. Really? That's something that should be a CVE, not a "feature that demonstrates the flexibility of open source software".
Offering all four variants of HMAC-SHA2 is also almost entirely pointless here, given that TCP-AO MACs are limited to 20 bytes by the TCP options space anyway.
If there are specific additional algorithm(s) that are actually needed for backwards compatibility, then we can add them to the list of algorithms that the new implementation supports. However, do you actually know of any user using anything other than HMAC-SHA1, HMAC-SHA256, or AES-128-CMAC? If so, what is their use case?
Quoted 4 lines
But let's not keep the
crypto_ahashbased implementation of TCP-AO around as well, as there's a massive amount of complexity and inefficiency in it. I think this series makes that very clear.
Agree that supporting arbitrary algorithms is a bug, not a feature, and if anyone does notice that a combination that actually makes /some/ sense no longer works, we can always add it back in library form (even though generating a 64-byte SHA-512 digest and truncating it to 20 bytes seems kind of pointless). But supporting CRC-32 or HMAC-MD5 is just ridiculous so let's not go there.