Skip to content

Commit 276c7e0

Browse files
committed
two times
1 parent f9815b7 commit 276c7e0

File tree

1 file changed

+64
-14
lines changed

1 file changed

+64
-14
lines changed

test/test_srtp.c

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const char *octet_string_hex_string(const uint8_t *str, size_t length)
4040
}
4141

4242

43+
4344
static int test()
4445
{
4546
Aes aes;
@@ -50,18 +51,35 @@ static int test()
5051
}
5152

5253
uint8_t key[16] = {
53-
0xc6, 0x1e, 0x7a, 0x93, 0x74, 0x4f, 0x39, 0xee, 0x10, 0x73, 0x4a, 0xfe, 0x3f, 0xf7, 0xa0, 0x87
54+
0xc6, 0x1e, 0x7a, 0x93, 0x74, 0x4f, 0x39, 0xee,
55+
0x10, 0x73, 0x4a, 0xfe, 0x3f, 0xf7, 0xa0, 0x87
56+
};
57+
58+
uint8_t iv_0[16] = {
59+
0x30, 0xcb, 0xbc, 0x08, 0x4c, 0xc3, 0x36, 0x3b,
60+
0xd4, 0x9d, 0xb3, 0x4a, 0x88, 0xd4, 0x00, 0x00
61+
};
62+
uint8_t src_0[] = {
63+
0x51, 0x00, 0x02, 0x00, 0xab, 0xab, 0xab, 0xab,
64+
0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
65+
0xab, 0xab, 0xab, 0xab
66+
};
67+
uint8_t ref_0[] = {
68+
0xeb, 0x92, 0x36, 0x52, 0x51, 0xc3, 0xe0, 0x36,
69+
0xf8, 0xde, 0x27, 0xe9, 0xc2, 0x7e, 0xe3, 0xe0,
70+
0xb4, 0x65, 0x1d, 0x9f
5471
};
55-
uint8_t iv[16] = {
72+
73+
uint8_t iv_1[16] = {
5674
0x30, 0xcb, 0xbc, 0x08, 0x4c, 0xc3, 0x36, 0x3b,
5775
0xd4, 0x9d, 0xb3, 0x4a, 0x88, 0xd7, 0x00, 0x00
5876
};
59-
uint8_t src[] = {
77+
uint8_t src_1[] = {
6078
0x05, 0x02, 0x00, 0x02, 0xab, 0xab, 0xab, 0xab,
6179
0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
6280
0xab, 0xab, 0xab, 0xab
6381
};
64-
uint8_t ref[] = {
82+
uint8_t ref_1[] = {
6583
0x4e, 0xd9, 0xcc, 0x4e, 0x6a, 0x71, 0x2b, 0x30,
6684
0x96, 0xc5, 0xca, 0x77, 0x33, 0x9d, 0x42, 0x04,
6785
0xce, 0x0d, 0x77, 0x39
@@ -75,27 +93,59 @@ static int test()
7593
return 1;
7694
}
7795

78-
printf("iv : %s\n", octet_string_hex_string(iv, sizeof(iv)));
96+
printf("iv_0: %s\n", octet_string_hex_string(iv_0, sizeof(iv_0)));
97+
98+
err = wc_AesSetIV(&aes, iv_0);
99+
if (err < 0) {
100+
printf("set IV 0, wolfSSL error code: %d", err);
101+
return 1;
102+
}
103+
104+
printf("src_0: %s\n", octet_string_hex_string(src_0, sizeof(src_0)));
105+
106+
err = wc_AesCtrEncrypt(&aes, src_0, src_0, sizeof(src_0));
107+
if (err < 0) {
108+
printf("encrypt 0, wolfSSL encrypt error: %d", err);
109+
return 1;
110+
}
111+
112+
printf("enc_0: %s\n", octet_string_hex_string(src_0, sizeof(src_0)));
113+
114+
if (memcmp(src_0, ref_0, sizeof(src_0)) != 0) {
115+
printf("encrypt 0 failed, not equal\n");
116+
printf("ref_0: %s\n", octet_string_hex_string(ref_0, sizeof(ref_0)));
117+
return 1;
118+
}
119+
120+
printf("key: %s\n", octet_string_hex_string(key, sizeof(key)));
121+
122+
err = wc_AesSetKey(&aes, key, sizeof(key), NULL, AES_ENCRYPTION);
123+
if (err < 0) {
124+
printf("set key, wolfSSL error code: %d", err);
125+
return 1;
126+
}
127+
128+
printf("iv_1 : %s\n", octet_string_hex_string(iv_1, sizeof(iv_1)));
79129

80-
err = wc_AesSetIV(&aes, iv);
130+
err = wc_AesSetIV(&aes, iv_1);
81131
if (err < 0) {
82-
printf("set IV, wolfSSL error code: %d", err);
132+
printf("set IV 1, wolfSSL error code: %d", err);
83133
return 1;
84134
}
85135

86-
printf("src: %s\n", octet_string_hex_string(src, sizeof(src)));
136+
printf("src_1: %s\n", octet_string_hex_string(src_1, sizeof(src_1)));
87137

88-
err = wc_AesCtrEncrypt(&aes, src, src, sizeof(src));
138+
err = wc_AesCtrEncrypt(&aes, src_1, src_1, sizeof(src_1));
89139
if (err < 0) {
90-
printf("encrypt, wolfSSL encrypt error: %d", err);
140+
printf("encrypt 1, wolfSSL encrypt error: %d", err);
91141
return 1;
92142
}
93143

94-
printf("enc: %s\n", octet_string_hex_string(src, sizeof(src)));
144+
printf("enc_1: %s\n", octet_string_hex_string(src_1, sizeof(src_1)));
95145

96-
if (memcmp(src, ref, sizeof(src)) != 0) {
97-
printf("encrypt failed, not equal\n");
98-
printf("ref: %s\n", octet_string_hex_string(ref, sizeof(ref)));
146+
if (memcmp(src_1, ref_1, sizeof(src_1)) != 0) {
147+
printf("encrypt 1 failed, not equal\n");
148+
printf("ref_1: %s\n", octet_string_hex_string(ref_1, sizeof(ref_1)));
99149
return 1;
100150
}
101151

0 commit comments

Comments
 (0)