Skip to content

Commit 4923e8b

Browse files
committed
Add: PoC of video frames encryption using AES-CTR
This PoC demonstrates the use of AES-CTR encryption of video frames transmitted between the Tx and Rx sessions. It shows that video frames can be treated as binary blobs that could be encrypted. The PoC uses https://github.com/intel/intel-ipsec-mb for the AES-CTR encryption. Sample file can be generated with: ``` ffmpeg -an -y -f lavfi -i \ testsrc=d=5:s=1920x1080:r=25,format=yuv422p10be -f rawvideo \ /tmp/yuv422p10le.yuv ``` To run PoC: ``` ./tests/tools/RxTxApp/build/RxTxApp --config_file \ config/tx-rx-encryption.json --test_time=10 ```
1 parent fcefbb9 commit 4923e8b

File tree

5 files changed

+188
-3
lines changed

5 files changed

+188
-3
lines changed

config/tx-rx-encryption.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"tx_no_chain": false,
3+
"interfaces": [
4+
{
5+
"name": "0000:4b:01.0",
6+
"ip": "192.168.17.101"
7+
},
8+
{
9+
"name": "0000:4b:01.1",
10+
"ip": "192.168.17.102"
11+
}
12+
],
13+
"tx_sessions": [
14+
{
15+
"dip": [
16+
"192.168.17.102"
17+
],
18+
"interface": [
19+
0
20+
],
21+
"video": [],
22+
"st20p": [
23+
{
24+
"replicas": 1,
25+
"start_port": 20000,
26+
"payload_type": 112,
27+
"width": 1920,
28+
"height": 1080,
29+
"fps": "p25",
30+
"interlaced": false,
31+
"device": "AUTO",
32+
"pacing": "gap",
33+
"packing": "BPM",
34+
"input_format": "YUV422RFC4175PG2BE10",
35+
"transport_format": "YUV_422_10bit",
36+
"st20p_url": "/tmp/yuv422p10be.yuv",
37+
"display": false,
38+
"enable_rtcp": false
39+
}
40+
],
41+
"st22p": [],
42+
"st30p": [],
43+
"audio": [],
44+
"ancillary": [],
45+
"fastmetadata": []
46+
}
47+
],
48+
"rx_sessions": [
49+
{
50+
"ip": [
51+
"192.168.17.101"
52+
],
53+
"interface": [
54+
1
55+
],
56+
"video": [],
57+
"st20p": [
58+
{
59+
"replicas": 1,
60+
"start_port": 20000,
61+
"payload_type": 112,
62+
"width": 1920,
63+
"height": 1080,
64+
"fps": "p25",
65+
"interlaced": false,
66+
"device": "AUTO",
67+
"pacing": "gap",
68+
"packing": "BPM",
69+
"output_format": "YUV422RFC4175PG2BE10",
70+
"transport_format": "YUV_422_10bit",
71+
"measure_latency": false,
72+
"display": false,
73+
"enable_rtcp": false,
74+
"st20p_url": "/tmp/out.yuv"
75+
}
76+
],
77+
"st22p": [],
78+
"st30p": [],
79+
"audio": [],
80+
"ancillary": [],
81+
"fastmetadata": []
82+
}
83+
]
84+
}

tests/tools/RxTxApp/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ libm = cc.find_library('m', required : true)
2424
libpthread = cc.find_library('pthread', required : true)
2525
libjson_c = dependency('json-c', required : true)
2626
libpcap = dependency('pcap', required: true)
27+
libIPSec_MB = cc.find_library('IPSec_MB', required: true)
28+
2729

2830
libsdl2 = dependency('sdl2', required: false)
2931
if libsdl2.found()
@@ -90,5 +92,5 @@ executable('RxTxApp', sources,
9092
c_args : app_c_args,
9193
link_args: app_ld_args,
9294
# asan should be always the first dep
93-
dependencies: [asan_dep, mtl, libjson_c, libpcap, libsdl2, libsdl2_ttf, libm, libpthread, ws2_32_dep, mman_dep, libopenssl]
95+
dependencies: [asan_dep, mtl, libjson_c, libpcap, libsdl2, libsdl2_ttf, libm, libpthread, ws2_32_dep, mman_dep, libopenssl, libIPSec_MB]
9496
)

tests/tools/RxTxApp/src/app_base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ struct st_app_rx_st20p_session {
558558

559559
bool measure_latency;
560560
uint64_t stat_latency_us_sum;
561+
562+
void* tmp_framebuff;
561563
};
562564

563565
struct st_app_tx_st30p_session {

tests/tools/RxTxApp/src/rx_st20p_app.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,52 @@
33
*/
44

55
#include "rx_st20p_app.h"
6+
#include <intel-ipsec-mb.h>
7+
8+
static IMB_MGR *mgr;
9+
10+
static uint8_t cipher_key[16] = {0};
11+
static uint8_t cipher_iv[16] = {0};
12+
DECLARE_ALIGNED(static uint32_t exp_enc_key[4*15], 16);
13+
DECLARE_ALIGNED(static uint32_t exp_dec_key[4*15], 16);
14+
static IMB_JOB *job;
615

716
static void app_rx_st20p_consume_frame(struct st_app_rx_st20p_session* s,
817
struct st_frame* frame) {
918
struct st_display* d = s->display;
1019
int idx = s->idx;
1120

1221
if (s->st20p_destination_file) {
13-
if (!fwrite(frame->addr[0], 1, s->st20p_frame_size, s->st20p_destination_file)) {
22+
job = IMB_GET_NEXT_JOB(mgr);
23+
job->src = frame->addr[0];
24+
job->dst = s->tmp_framebuff;
25+
job->cipher_mode = IMB_CIPHER_CNTR;
26+
job->hash_alg = IMB_AUTH_NULL;
27+
job->enc_keys = exp_enc_key;
28+
job->dec_keys = exp_dec_key;
29+
job->iv = cipher_iv;
30+
job->cipher_direction = IMB_DIR_DECRYPT;
31+
job->chain_order = IMB_ORDER_HASH_CIPHER;
32+
job->key_len_in_bytes = 16;
33+
job->iv_len_in_bytes = 16;
34+
job->cipher_start_src_offset_in_bytes = 0;
35+
job->msg_len_to_cipher_in_bytes = s->st20p_frame_size;
36+
job = IMB_SUBMIT_JOB(mgr);
37+
if (job == NULL) {
38+
const int err = imb_get_errno(mgr);
39+
printf("%d Unexpected null return from submit job()\n"
40+
"\t Error code %d, %s\n", __LINE__, err,
41+
imb_get_strerror(err));
42+
exit(1);
43+
}
44+
if (job->status != IMB_STATUS_COMPLETED) {
45+
const int err = imb_get_errno(mgr);
46+
printf("%d Wrong job status\n"
47+
"\t Error code %d, %s\n", __LINE__, err,
48+
imb_get_strerror(err));
49+
}
50+
51+
if (!fwrite(s->tmp_framebuff, 1, s->st20p_frame_size, s->st20p_destination_file)) {
1452
err("%s(%d), failed to write frame to file %s\n", __func__, idx,
1553
s->st20p_destination_url);
1654
}
@@ -57,6 +95,10 @@ static void* app_rx_st20p_frame_thread(void* arg) {
5795
uint8_t shas[SHA256_DIGEST_LENGTH];
5896
int idx = s->idx;
5997

98+
mgr = alloc_mb_mgr(0);
99+
init_mb_mgr_auto(mgr, NULL);
100+
IMB_AES_KEYEXP_128(mgr, cipher_key, exp_enc_key, exp_dec_key);
101+
60102
info("%s(%d), start\n", __func__, s->idx);
61103
while (!s->st20p_app_thread_stop) {
62104
frame = st20p_rx_get_frame(s->handle);
@@ -103,6 +145,8 @@ static void* app_rx_st20p_frame_thread(void* arg) {
103145
}
104146
info("%s(%d), stop\n", __func__, s->idx);
105147

148+
free_mb_mgr(mgr);
149+
106150
return NULL;
107151
}
108152

@@ -286,6 +330,13 @@ static int app_rx_st20p_init(struct st_app_context* ctx,
286330
s->handle = handle;
287331

288332
s->st20p_frame_size = st20p_rx_frame_size(handle);
333+
s->tmp_framebuff = malloc(s->st20p_frame_size);
334+
if (!s->tmp_framebuff) {
335+
err("%s(%d), failed to allocate tmp frame buffer\n", __func__, idx);
336+
app_rx_st20p_uinit(s);
337+
return -ENOMEM;
338+
}
339+
289340

290341
ret = app_rx_st20p_init_frame_thread(s);
291342
if (ret < 0) {
@@ -374,9 +425,11 @@ int st_app_rx_st20p_sessions_uinit(struct st_app_context* ctx) {
374425
for (i = 0; i < ctx->rx_st20p_session_cnt; i++) {
375426
s = &ctx->rx_st20p_sessions[i];
376427
app_rx_st20p_uinit(s);
428+
free(s->tmp_framebuff);
377429
}
378430
st_app_free(ctx->rx_st20p_sessions);
379431

432+
380433
return 0;
381434
}
382435

tests/tools/RxTxApp/src/tx_st20p_app.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
*/
44

55
#include "tx_st20p_app.h"
6+
#include <intel-ipsec-mb.h>
7+
8+
static IMB_MGR *mgr;
9+
10+
static uint8_t cipher_key[16] = {0};
11+
static uint8_t cipher_iv[16] = {0};
12+
DECLARE_ALIGNED(static uint32_t exp_enc_key[4*15], 16);
13+
DECLARE_ALIGNED(static uint32_t exp_dec_key[4*15], 16);
14+
static IMB_JOB *job;
615

716
static void app_tx_st20p_display_frame(struct st_app_tx_st20p_session* s,
817
struct st_frame* frame) {
@@ -46,7 +55,36 @@ static void app_tx_st20p_build_frame(struct st_app_tx_st20p_session* s,
4655
uint8_t* src = s->st20p_frame_cursor;
4756

4857
if (!s->ctx->tx_copy_once || !s->st20p_frames_copied) {
49-
mtl_memcpy(frame->addr[0], src, frame_size);
58+
// mtl_memcpy(frame->addr[0], src, frame_size);
59+
job = IMB_GET_NEXT_JOB(mgr);
60+
job->src = src;
61+
job->dst = frame->addr[0];
62+
job->cipher_mode = IMB_CIPHER_CNTR;
63+
job->hash_alg = IMB_AUTH_NULL;
64+
job->enc_keys = exp_enc_key;
65+
job->dec_keys = exp_dec_key;
66+
job->iv = cipher_iv;
67+
job->cipher_direction = IMB_DIR_ENCRYPT;
68+
job->chain_order = IMB_ORDER_CIPHER_HASH;
69+
job->key_len_in_bytes = 16;
70+
job->iv_len_in_bytes = 16;
71+
job->cipher_start_src_offset_in_bytes = 0;
72+
job->msg_len_to_cipher_in_bytes = frame_size;
73+
job = IMB_SUBMIT_JOB(mgr);
74+
if (job == NULL) {
75+
const int err = imb_get_errno(mgr);
76+
printf("%d Unexpected null return from submit job()\n"
77+
"\t Error code %d, %s\n", __LINE__, err,
78+
imb_get_strerror(err));
79+
exit(1);
80+
}
81+
if (job->status != IMB_STATUS_COMPLETED) {
82+
const int err = imb_get_errno(mgr);
83+
printf("%d Wrong job status\n"
84+
"\t Error code %d, %s\n", __LINE__, err,
85+
imb_get_strerror(err));
86+
exit(1);
87+
}
5088
}
5189
/* point to next frame */
5290
s->st20p_frame_cursor += frame_size;
@@ -65,6 +103,10 @@ static void* app_tx_st20p_frame_thread(void* arg) {
65103
struct st_frame* frame;
66104
uint8_t shas[SHA256_DIGEST_LENGTH];
67105

106+
mgr = alloc_mb_mgr(0);
107+
init_mb_mgr_auto(mgr, NULL);
108+
IMB_AES_KEYEXP_128(mgr, cipher_key, exp_enc_key, exp_dec_key);
109+
68110
info("%s(%d), start\n", __func__, idx);
69111
while (!s->st20p_app_thread_stop) {
70112
frame = st20p_tx_get_frame(handle);
@@ -82,6 +124,8 @@ static void* app_tx_st20p_frame_thread(void* arg) {
82124
}
83125
info("%s(%d), stop\n", __func__, idx);
84126

127+
free_mb_mgr(mgr);
128+
85129
return NULL;
86130
}
87131

0 commit comments

Comments
 (0)