Skip to content

Commit

Permalink
net: tcp: use PSA for SHA256 when BUILD_WITH_TFM
Browse files Browse the repository at this point in the history
When BUILD_WITH_TFM is enabled we can dispatch hash computation
to TFM. This allows to remove the built-in support of SHA256 from
the non-secure side (if it's not used for any other purpose, of course).

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
  • Loading branch information
valeriosetti committed Apr 29, 2024
1 parent 8db7c17 commit 84dee98
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 1 addition & 3 deletions subsys/net/ip/Kconfig.tcp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ config NET_TCP_ISN_RFC6528
bool "Use ISN algorithm from RFC 6528"
default y
depends on NET_TCP
select MBEDTLS
select MBEDTLS_MD
select MBEDTLS_MAC_MD5_ENABLED
select PSA_WANT_ALG_SHA_256
help
Implement Initial Sequence Number calculation as described in
RFC 6528 chapter 3. https://tools.ietf.org/html/rfc6528
Expand Down
12 changes: 9 additions & 3 deletions subsys/net/ip/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LOG_MODULE_REGISTER(net_tcp, CONFIG_NET_TCP_LOG_LEVEL);
#include <zephyr/random/random.h>

#if defined(CONFIG_NET_TCP_ISN_RFC6528)
#include <mbedtls/md5.h>
#include <psa/crypto.h>
#endif
#include <zephyr/net/net_pkt.h>
#include <zephyr/net/net_context.h>
Expand Down Expand Up @@ -2245,7 +2245,10 @@ static uint32_t tcpv6_init_isn(struct in6_addr *saddr,
memcpy(buf.key, unique_key, sizeof(buf.key));

#if defined(CONFIG_NET_TCP_ISN_RFC6528)
mbedtls_md5((const unsigned char *)&buf, sizeof(buf), hash);
size_t hash_len;

psa_hash_compute(PSA_ALG_SHA_256, (const unsigned char *)&buf, sizeof(buf),
hash, sizeof(hash), &hash_len);
#endif

return seq_scale(UNALIGNED_GET((uint32_t *)&hash[0]));
Expand Down Expand Up @@ -2284,7 +2287,10 @@ static uint32_t tcpv4_init_isn(struct in_addr *saddr,
memcpy(buf.key, unique_key, sizeof(unique_key));

#if defined(CONFIG_NET_TCP_ISN_RFC6528)
mbedtls_md5((const unsigned char *)&buf, sizeof(buf), hash);
size_t hash_len;

psa_hash_compute(PSA_ALG_SHA_256, (const unsigned char *)&buf, sizeof(buf),
hash, sizeof(hash), &hash_len);
#endif

return seq_scale(UNALIGNED_GET((uint32_t *)&hash[0]));
Expand Down

0 comments on commit 84dee98

Please sign in to comment.