Zephyr Network Self-test
with MbedTLS
[email protected]
© 2024 Realtek Semiconductor Corp. All rights
Realtek Confidential 1
Outline
Network Overview
Network virtual test support
Network mbedtls calling flow
Supported alogrithm
Summary
Realtek Confidential 2
Networking Overview
Fig.1.1 The Network IP stack.
5. network packet placed to proper transmit queue
6. device driver send it to the network
1. application calls send() from socket API
2. net packet structure created,
user data copy to it
3. udp protocal header
added in front of data
4. ipv4 protocal header added
Realtek Confidential 3
Networking Overview
Fig.1.2 Zephyr network source tree layout
./subsys/
├── net /
│ ├── lib # Application-level protocols (DNS, MQTT, etc.) and additional stack components (BSD
Sockets, etc.)
│ └── ip # This is where the IP stack code is located(TCP/UDP/IPv4)
│ └── l2 # This is where the IP stack layer 2 code is located
├── Include/net # header files applications need to include to use IP networking
./samples/net/
./tests/net / # Samples and Test
./mbedtls/ #mbedtls library
Realtek Confidential 4
Outline
Network Overview
Network virtual test support
Network mbedtls calling flow
Supported alogrithm
Summary
Realtek Confidential 5
Network virtual test support
• Zephyr Socket API Test
• Test BSD/TLS socket API behavior
• bind()/connect()/listen()/close()
send()/recv()
• Self-contained test using a standalone ELF
• Zephyr Socket API Sample
• Qemu to Qemu test or Qemu to Host test
• Echo_server/ echo_client/ tls_client
Realtek Confidential 6
Network virtual test support
Zephyr Network test case
tests/net/socket • socketpair/ Can be used for socket self testing
• tcp/ Plain socket( POSIX API)
• udp/
• tls/ tls socket( 加密通信 )
• tls_ext/
samples/net/sockets • echo_client/ Can be used for board demo;
• echo_server/ qemu to qemu test or qemu to host test
• Socketpair/
• Tcp/
Apptainer> west build -p auto -b sheipa_kr4 zephyr/tests/net/socket/tls
[246/246] Linking C executable zephyr/zephyr.elf
Memory region Used Size Region Size %age Used
ROM: 236965 B 4 MB 5.65%
RAM: 77288 B 256 MB 0.03%
IDT_LIST: 0 GB 2 KB 0.00%
Realtek Confidential 7
Network virtual test framework
QEMU/RLXVM
1. Create socket
prepare_sock_tls_v4( &c_saddr, IPPROTO_TLS_1_2); server client
prepare_sock_tls_v4( &s_saddr, IPPROTO_TLS_1_2); tls_socket tls_socket
2. Server start listen test_listen()
handshake test_connect()
3. Client start connect and handshake handshake success
4. Client send TEST STR
test_send(TEST_STR)
test_recv(rx_buf,MSG_WAITALL)
5. Server receive rx_buffer and
compare with TEST_STR
mem_equal(rx_buf,TEST_STR)
Realtek Confidential 8
Network virtual test framework
• Lalu support in zephyr
V2.0 V2.2 V2.6 V2.7 V3.5 V3.7(LTS) V4.2
KR0 KR4 future
TR9(MP) TR9 TR9 support
MIPS MIPS MIPS
TM9 TM9 KM4 KM4
• Zephyr qemu/rlxvm auto run support
• cmake/emu/qemu.cmake is the place to add simulation instruction
• Add scripts/rlxvm_zephyr.sh to start VM
• Set RLXVM_DIR=${ZEPHYR_RLXVM_DIR}
• Regression test on jenkins
Realtek Confidential 9
Outline
Network Overview
Network virtual test support
Network mbedtls calling flow
Supported alogrithm
Summary
Realtek Confidential 10
Network mbedtls calling flow
application socket api Tls layer mbedtls Network stack
send(data)
tls_sock_sendto_vmeth(data)
Send_tls(data)
Mbedtls_ssl_write(&ctx->ssl,buf,len)
tls_tx() 回调
Zsock_sendto()
loopback
zsock_recvfrom()
Mbedtls_ssl_read()
tls_recv() 回调
tls_socket_recvfrom_vmeth(data)
recv(data)
application socket api Tls layer mbedtls Network stack
Realtek Confidential 11
Network mbedtls calling flow
• Configuration for TLS_SOCKET test:
1. TLS handshake
CONFIG_NET_TEST=Y server client certificate
Key exchange
CONFIG_NET_SOCKETS=Y
CONFIG_NET_SOCKETS_SOCKOP_TLS=Y
2. Data Send/Receive
CONFIG_NET_LOOPBACK=Y encryption and decryption
data Integrality check
CONFIG_MBEDTLS=Y
CONFIG_MBEDTLS_BUILTIN=Y
Realtek Confidential 12
Outline
Network Overview
Network virtual test support
Network mbedtls calling flow
Supported alogrithm
Summary
Realtek Confidential 13
Supported algorithm
Lalu Driver
AES
SM4
RSA
Zephyr Mbedtls Config
SHA SHA1/SHA2/SHA3
Key exchange • RSA
• ECDSA HMAC
• PSK,DHE SHAKE
HASH • SHA256/384/512
SM3
cipher mode • AES ECC ECDH/EDDSA/ECDSA
• DES
• (ARC4/ChaCha20/Blowfish) LMS
message • MD4/5 Dilithium
auth • SHA1 SHA256/512
• MAC(CMAC/HMAC) Kyber
SPHINCS+
Realtek Confidential 14
SUMMARY
Run tls_socket test on RLXVM(1 week)
Add rlxvm runner in cmake/emu
Compile and run test/net/sockets/tls
Add KR0(LALU) support and maintain TLS(3 weeks)
Regression test and Jenkins job(2~3 weeks)
Add other algorithm testing
Realtek Confidential 15
Thank You 謝謝 ありがとう 감사합니다 Gracias Merci Danke धन्यवाद شكًر اObrigado/Obrigada Спасибо
Realtek Confidential 16