Skip to content

Commit dbc1b8d

Browse files
modules: libSRTP glue added to the modules folder.
gule files added so Zephyr RTOS can use libSRTP. Signed-off-by: Sayed Naser Moravej <seyednasermoravej@gmail.com>
1 parent 0fd85f7 commit dbc1b8d

File tree

8 files changed

+234
-77
lines changed

8 files changed

+234
-77
lines changed

MAINTAINERS.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5853,6 +5853,16 @@ West:
58535853
labels:
58545854
- "area: Audio"
58555855

5856+
"West project: libsrtp":
5857+
status: maintained
5858+
maintainers:
5859+
- josuah
5860+
files:
5861+
- modules/libsrtp/
5862+
- samples/modules/libsrtp/
5863+
labels:
5864+
- "area: Networking"
5865+
58565866
"West project: littlefs":
58575867
status: odd fixes
58585868
files:

modules/libsrtp/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2025 Sayed Naser Moravej <seyednasermoravej@gmail.com>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if(CONFIG_LIBSRTP)
5+
6+
zephyr_include_directories(
7+
${ZEPHYR_LIBSRTP_MODULE_DIR}/include
8+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/include
9+
${CMAKE_CURRENT_SOURCE_DIR}
10+
${ZEPHYR_LIBSRTP_MODULE_DIR}/test
11+
)
12+
13+
zephyr_library_named(libsrtp)
14+
15+
zephyr_library_compile_definitions(MBEDTLS)
16+
17+
zephyr_library_sources(
18+
${ZEPHYR_LIBSRTP_MODULE_DIR}/srtp/srtp.c
19+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/cipher/cipher.c
20+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/cipher/cipher_test_cases.c
21+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/cipher/null_cipher.c
22+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/math/datatypes.c
23+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/kernel/alloc.c
24+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/kernel/key.c
25+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/kernel/err.c
26+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/kernel/crypto_kernel.c
27+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/replay/rdb.c
28+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/replay/rdbx.c
29+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/hash/auth.c
30+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/hash/auth_test_cases.c
31+
${ZEPHYR_LIBSRTP_MODULE_DIR}/test/rtp.c
32+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/hash/null_auth.c
33+
${ZEPHYR_LIBSRTP_MODULE_DIR}/test/util.c
34+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/hash/hmac_mbedtls.c
35+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/cipher/aes_icm_mbedtls.c
36+
${ZEPHYR_LIBSRTP_MODULE_DIR}/crypto/cipher/aes_gcm_mbedtls.c
37+
)
38+
39+
zephyr_library_compile_definitions(libsrtp HAVE_CONFIG_H)
40+
41+
zephyr_library_link_libraries(mbedTLS)
42+
43+
endif()

modules/libsrtp/Kconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 2025 Sayed Naser Moravej <seyednasermoravej@gmail.com>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config LIBSRTP
5+
bool "libsrtp support"
6+
depends on MBEDTLS
7+
select MBEDTLS_CIPHER_AES_ENABLED
8+
select MBEDTLS_CIPHER_CAMELLIA_ENABLED
9+
select MBEDTLS_CIPHER_DES_ENABLED
10+
select MBEDTLS_CIPHER_CHACHA20_ENABLED
11+
select MBEDTLS_CIPHER_CCM_ENABLED
12+
select MBEDTLS_CIPHER_GCM_ENABLED
13+
select MBEDTLS_CIPHER_MODE_XTS_ENABLED
14+
select MBEDTLS_CIPHER_MODE_CBC_ENABLED
15+
select MBEDTLS_CIPHER_MODE_CTR_ENABLED
16+
17+
help
18+
Enable libsrtp library integration as a Zephyr module.

modules/libsrtp/config.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2025 Sayed Naser Moravej <seyednasermoravej@gmail.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdbool.h>
8+
9+
#define PACKAGE_VERSION "1.0.0"
10+
11+
#define PACKAGE_STRING "Zephyr 1.0.0"
12+
13+
#define ENABLE_DEBUG_LOGGING 1
14+
15+
#define CPU_CISC 1
16+
17+
#define HAVE_ARPA_INET_H 1
18+
19+
#define HAVE_INTTYPES_H 1
20+
21+
#define HAVE_NETINET_IN_H 1
22+
23+
#define HAVE_STDINT_H 1
24+
25+
#define HAVE_STDLIB_H 1
26+
27+
#define HAVE_SYS_SOCKET_H 1
28+
29+
#define HAVE_SYS_TYPES_H 1
30+
31+
#define HAVE_UNISTD_H 1
32+
33+
#define HAVE_INET_ATON 1
34+
35+
#define HAVE_USLEEP 1
36+
37+
#define HAVE_UINT8_T 1
38+
39+
#define HAVE_UINT16_T 1
40+
41+
#define HAVE_UINT32_T 1
42+
43+
#define HAVE_UINT64_T 1
44+
45+
#define HAVE_INT32_T 1
46+
47+
#define SIZEOF_UNSIGNED_LONG 4
48+
49+
#define SIZEOF_UNSIGNED_LONG_LONG 8
50+
51+
#define _SYS_SOCKET_H 1
52+
53+
#include <zephyr/net/socket.h>
54+
55+
#define MBEDTLS_AES_C
56+
57+
#define MBEDTLS_CIPHER_C
58+
59+
#define MBEDTLS_GCM_C
60+
61+
#define MBEDTLS_CTR_DRBG_C
62+
63+
#define MBEDTLS_MD_C
64+
65+
#define MBEDTLS_HMAC_DRBG_C
66+
67+
#define MBEDTLS 1
68+
69+
#define HAVE_INLINE 1
Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
mainmenu "RTPW Sample Application"
22

33
config NET_SAMPLE_SRTP_KEY
4-
string "SRTP master key for RTPW example."
5-
default "c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451"
6-
help
7-
This key in hexadecimal which is used by the application. You can override it in prj.conf
8-
or via menuconfig / guiconfig.
4+
string "SRTP master key for RTPW example."
5+
default "c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451"
6+
help
7+
This key in hexadecimal which is used by the application. You can override it in prj.conf
8+
or via menuconfig / guiconfig.
99

1010
choice
11-
prompt "Program mode"
12-
default NET_SAMPLE_SENDER
13-
help
14-
Select whether this application runs as sender or receiver.
11+
prompt "Program mode"
12+
default NET_SAMPLE_SENDER
13+
help
14+
Select whether this application runs as sender or receiver.
1515

1616
config NET_SAMPLE_SENDER
17-
bool "Sender mode"
18-
help
19-
Build the application as an RTP sender.
17+
bool "Sender mode"
18+
help
19+
Build the application as an RTP sender.
2020

2121
config NET_SAMPLE_RECEIVER
22-
bool "Receiver mode"
23-
help
24-
Build the application as an RTP receiver.
22+
bool "Receiver mode"
23+
help
24+
Build the application as an RTP receiver.
2525

2626
endchoice
2727

2828
config NET_CONFIG_PEER_IPV4_ADDR
29-
string
30-
default "10.42.0.1" if NET_SAMPLE_SENDER
31-
default "0.0.0.0" if NET_SAMPLE_RECEIVER
32-
help
33-
Peer IPv4 address used by the RTPW example.
29+
string
30+
default "10.42.0.1" if NET_SAMPLE_SENDER
31+
default "0.0.0.0" if NET_SAMPLE_RECEIVER
32+
help
33+
Peer IPv4 address used by the RTPW example.
3434

3535
config NET_SAMPLE_SRTP_SERVER_PORT
36-
int "SRTP port"
37-
default 9999
38-
help
39-
SRTP port that the application sends or receives over that port.
36+
int "SRTP port"
37+
default 9999
38+
help
39+
SRTP port that the application sends or receives over that port.
4040

4141
source "Kconfig.zephyr"
42-

samples/modules/libsrtp/rtpw/README.rst

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,93 @@
11
.. zephyr:code-sample:: rtpw
2-
:name: Rtpw
2+
:name: SRTP client and server
33

44
Send and receive data using (S)RTP protocol.
55

66
Overveiw
77
********
88

99
A simple demo of using (S)RTP protocol to send and receive data over network. The sample could be sender or receiver.
10+
1011
To test (S)RTP via a Linux machine, you should build the libsrtp.
12+
1113
To test the sender while PC is receiver, the peer IP address should be set in Kconfig file. Next open a terminal and enter command:
1214

13-
.. code-block:: console
14-
``~/libsrtp/test$ ./rtpw -r -k c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451 -e 128 -a 0.0.0.0 9999``
15+
.. code-block:: shell
16+
17+
~/libsrtp/test$ ./rtpw -r -k c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451 -e 128 -a 0.0.0.0 9999
18+
1519
You should see in PC side:
16-
.. code-block::
17-
``Using libsrtp3 3.0.0-pre [0x3000000]
18-
security services: confidentiality message authentication
19-
set master key/salt to c1eec3717da76195bb878578790af71c/4ee9f859e197a414a78d5abc7451
20-
word: SRTP test0.
21-
word: SRTP test1.
22-
word: SRTP test2.
23-
word: SRTP test3.``
20+
21+
.. code-block:: console
22+
23+
Using libsrtp3 3.0.0-pre [0x3000000]
24+
security services: confidentiality message authentication
25+
set master key/salt to c1eec3717da76195bb878578790af71c/4ee9f859e197a414a78d5abc7451
26+
word: SRTP test0.
27+
word: SRTP test1.
28+
word: SRTP test2.
29+
word: SRTP test3.
2430
2531
You should see in device side:
26-
.. code-block::
27-
``*** Booting Zephyr OS build v4.2.0-5032-g84d1da7ea2a6 ***
28-
[00:00:00.060,000] <inf> net_config: Initializing network
29-
[00:00:00.068,000] <inf> net_config: Waiting interface 1 (0x341b0380) to be up...
30-
[00:00:01.651,000] <inf> phy_mii: PHY (0) Link speed 100 Mb, full duplex
31-
[00:00:01.660,000] <inf> net_config: Interface 1 (0x341b0380) coming up
32-
[00:00:01.670,000] <inf> net_config: IPv4 address: 10.42.0.2
33-
[00:00:01.678,000] <inf> rtpw_sample: Using Zephyr 1.0.0 [0x1000000]
34-
35-
``[00:00:01.770,000] <inf> rtpw_sample: peer IPv4 address: 10.42.0.1.
36-
[00:00:01.779,000] <inf> rtpw_sample: my IPv4 address: 10.42.0.2.
37-
[00:00:01.788,000] <inf> rtpw_sample: sending word: SRTP test0.
38-
[00:00:02.297,000] <inf> rtpw_sample: sending word: SRTP test1.
39-
[00:00:02.806,000] <inf> rtpw_sample: sending word: SRTP test2.
40-
[00:00:03.315,000] <inf> rtpw_sample: sending word: SRTP test3.``
32+
33+
.. code-block:: console
34+
35+
*** Booting Zephyr OS build v4.2.0-5032-g84d1da7ea2a6 ***
36+
[00:00:00.060,000] <inf> net_config: Initializing network
37+
[00:00:00.068,000] <inf> net_config: Waiting interface 1 (0x341b0380) to be up...
38+
[00:00:01.651,000] <inf> phy_mii: PHY (0) Link speed 100 Mb, full duplex
39+
[00:00:01.660,000] <inf> net_config: Interface 1 (0x341b0380) coming up
40+
[00:00:01.670,000] <inf> net_config: IPv4 address: 10.42.0.2
41+
[00:00:01.678,000] <inf> rtpw_sample: Using Zephyr 1.0.0 [0x1000000]
42+
[00:00:01.770,000] <inf> rtpw_sample: peer IPv4 address: 10.42.0.1.
43+
[00:00:01.779,000] <inf> rtpw_sample: my IPv4 address: 10.42.0.2.
44+
[00:00:01.788,000] <inf> rtpw_sample: sending word: SRTP test0.
45+
[00:00:02.297,000] <inf> rtpw_sample: sending word: SRTP test1.
46+
[00:00:02.806,000] <inf> rtpw_sample: sending word: SRTP test2.
47+
[00:00:03.315,000] <inf> rtpw_sample: sending word: SRTP test3.
4148
4249
To test (S)RTP via a Linux machine, you should build the libsrtp.
4350
To test the receiver while PC is sender, the peer IP address should be set in Kconfig file. Next open a terminal and enter command:
4451

45-
.. code-block:: console
46-
``~/libsrtp/test$ ./rtpw -s -k c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451 -e 128 -a <CONFIG_NET_CONFIG_MY_IPV4_ADDR> 9999``
52+
.. code-block:: shell
53+
54+
~/libsrtp/test$ ./rtpw -s -k c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451 -e 128 -a <CONFIG_NET_CONFIG_MY_IPV4_ADDR> 9999
55+
4756
for example:
48-
``~/libsrtp/test$ ./rtpw -s -k c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451 -e 128 -a 10.42.0.2 9999``
57+
58+
.. code-block:: shell
59+
60+
~/libsrtp/test$ ./rtpw -s -k c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451 -e 128 -a 10.42.0.2 9999
4961
5062
You should see in PC side:
51-
.. code-block:: console
52-
``Using libsrtp3 3.0.0-pre [0x3000000]
53-
security services: confidentiality message authentication
54-
set master key/salt to c1eec3717da76195bb878578790af71c/4ee9f859e197a414a78d5abc7451
55-
sending word: abducing
56-
sending word: acidheads
57-
sending word: acidness
58-
sending word: actons``
5963

60-
You should see in device side:
6164
.. code-block:: console
62-
``*** Booting Zephyr OS build v4.2.0-5032-g84d1da7ea2a6 ***
63-
[00:00:00.060,000] <inf> net_config: Initializing network
64-
[00:00:00.068,000] <inf> net_config: Waiting interface 1 (0x341b04c0) to be up...
65-
[00:00:01.651,000] <inf> phy_mii: PHY (0) Link speed 100 Mb, full duplex
66-
[00:00:01.660,000] <inf> net_config: Interface 1 (0x341b04c0) coming up
67-
[00:00:01.670,000] <inf> net_config: IPv4 address: 10.42.0.2
68-
[00:00:01.678,000] <inf> rtpw_sample: Using Zephyr 1.0.0 [0x1000000]``
6965
70-
``[00:00:01.770,000] <inf> rtpw_sample: peer IPv4 address: 0.0.0.0.
71-
[00:00:01.779,000] <inf> rtpw_sample: my IPv4 address: 10.42.0.2.
72-
[00:00:18.010,000] <inf> rtpw_sample: receiving word: abducing``
66+
Using libsrtp3 3.0.0-pre [0x3000000]
67+
security services: confidentiality message authentication
68+
set master key/salt to c1eec3717da76195bb878578790af71c/4ee9f859e197a414a78d5abc7451
69+
sending word: abducing
70+
sending word: acidheads
71+
sending word: acidness
72+
sending word: actons
7373
74-
``[00:00:18.510,000] <inf> rtpw_sample: receiving word: acidheads``
74+
You should see in device side:
7575

76-
``[00:00:19.010,000] <inf> rtpw_sample: receiving word: acidness``
76+
.. code-block:: console
7777
78-
``[00:00:19.510,000] <inf> rtpw_sample: receiving word: actons``
78+
*** Booting Zephyr OS build v4.2.0-5032-g84d1da7ea2a6 ***
79+
[00:00:00.060,000] <inf> net_config: Initializing network
80+
[00:00:00.068,000] <inf> net_config: Waiting interface 1 (0x341b04c0) to be up...
81+
[00:00:01.651,000] <inf> phy_mii: PHY (0) Link speed 100 Mb, full duplex
82+
[00:00:01.660,000] <inf> net_config: Interface 1 (0x341b04c0) coming up
83+
[00:00:01.670,000] <inf> net_config: IPv4 address: 10.42.0.2
84+
[00:00:01.678,000] <inf> rtpw_sample: Using Zephyr 1.0.0 [0x1000000]
85+
[00:00:01.770,000] <inf> rtpw_sample: peer IPv4 address: 0.0.0.0.
86+
[00:00:01.779,000] <inf> rtpw_sample: my IPv4 address: 10.42.0.2.
87+
[00:00:18.010,000] <inf> rtpw_sample: receiving word: abducing
88+
[00:00:18.510,000] <inf> rtpw_sample: receiving word: acidheads
89+
[00:00:19.010,000] <inf> rtpw_sample: receiving word: acidness
90+
[00:00:19.510,000] <inf> rtpw_sample: receiving word: actons
7991
8092
Configuration
8193
*************

samples/modules/libsrtp/rtpw/src/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright 2025 Sayed Naser Moravej <seyednasermoravej@gmail.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
17
#include <zephyr/kernel.h>
28
#include <zephyr/net/socket.h>
39
#include <zephyr/logging/log.h>

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ manifest:
303303
path: modules/lib/libsbc
304304
- name: libsrtp
305305
url: https://github.com/seyednasermoravej/libsrtp.git
306-
revision: 37f04ac12705fae855cbf74bb1d119507a061631
306+
revision: dc70159412c6fc791da8f09a994a8bf0e95cb769
307307
path: modules/lib/libsrtp
308308
- name: littlefs
309309
path: modules/fs/littlefs

0 commit comments

Comments
 (0)