99 */
1010
1111#include " lib/security/ciphering_engine_nea2.h"
12+ #include " nea2_test_set.h"
1213#include " srsran/security/ciphering_engine.h"
1314#include " srsran/security/security.h"
1415#include " srsran/srslog/srslog.h"
@@ -18,7 +19,7 @@ using namespace srsran;
1819using namespace srsran ::security;
1920
2021// / Fixture class for ciphering engine tests
21- class ciphering_engine_test : public :: testing::Test
22+ class ciphering_engine_test : public testing ::TestWithParam<nea_test_set>
2223{
2324protected:
2425 void SetUp () override
@@ -85,211 +86,40 @@ bool trim_tail_to_bitlength(byte_buffer_view buf, uint32_t bitlength)
8586 return true ;
8687}
8788
88- // / 128-NEA2 Test Set 1
89- // / Ref: TS 33.501 Sec. D.4.4, TS 33.401 Sec. C.1 128-EEA2
90- TEST_F (ciphering_engine_test, security_nea2_testset1)
89+ TEST_P (ciphering_engine_test, ciphering_engine_nea2)
9190{
92- // Testdata in plain format
93- const char * key_cstr = " d3c5d592327fb11c4035c6680af8c6d1" ;
94- uint32_t count = 0x398a59b4 ;
95- uint8_t bearer = 0x15 ;
96- uint8_t direction = 1 ;
97- uint32_t length = 253 ;
98- const char * plaintext_cstr = " 981ba6824c1bfb1ab485472029b71d808ce33e2cc3c0b5fc1f3de8a6dc66b1f0" ;
99- const char * ciphertext_cstr = " e9fed8a63d155304d71df20bf3e82214b20ed7dad2f233dc3c22d7bdeeed8e78" ;
91+ nea_test_set param = GetParam ();
10092
10193 // Pack hex strings into srsran types
102- sec_128_key key = make_sec_128_key (key_cstr);
103- auto dir = static_cast <security_direction>(direction);
104- byte_buffer plaintext = make_byte_buffer (plaintext_cstr).value ();
105- byte_buffer ciphertext = make_byte_buffer (ciphertext_cstr).value ();
94+ sec_128_key key = make_sec_128_key (param. key_cstr );
95+ auto dir = static_cast <security_direction>(param. direction );
96+ byte_buffer plaintext = make_byte_buffer (param. plaintext_cstr ).value ();
97+ byte_buffer ciphertext = make_byte_buffer (param. ciphertext_cstr ).value ();
10698
10799 // Create ciphering engine
108- std::unique_ptr<ciphering_engine> nea = std::make_unique<ciphering_engine_nea2>(key, bearer, dir);
100+ std::unique_ptr<ciphering_engine> nea = std::make_unique<ciphering_engine_nea2>(key, param. bearer , dir);
109101
110102 // Apply ciphering and compare results
111- security_result result = nea->apply_ciphering (plaintext.deep_copy ().value (), 0 , count);
103+ security_result result = nea->apply_ciphering (plaintext.deep_copy ().value (), 0 , param. count );
112104 ASSERT_TRUE (result.buf .has_value ());
113- ASSERT_TRUE (trim_tail_to_bitlength (result.buf .value (), length));
105+ ASSERT_TRUE (trim_tail_to_bitlength (result.buf .value (), param. length ));
114106 EXPECT_EQ (result.buf .value (), ciphertext);
115107}
116108
117- // / 128-NEA2 Test Set 2
118- // / Ref: TS 33.501 Sec. D.4.4, TS 33.401 Sec. C.1 128-EEA2
119- TEST_F (ciphering_engine_test, security_nea2_testset2)
109+ // ////////////////////////////////////////////////////////
110+ // Finally, instantiate all testcases for each test set //
111+ // ////////////////////////////////////////////////////////
112+ std::string test_param_info_to_string (const ::testing::TestParamInfo<nea_test_set>& info)
120113{
121- // Testdata in plain format
122- const char * key_cstr = " 2bd6459f82c440e0952c49104805ff48" ;
123- uint32_t count = 0xc675a64b ;
124- uint8_t bearer = 0x0c ;
125- uint8_t direction = 1 ;
126- uint32_t length = 798 ;
127- const char * plaintext_cstr =
128- " 7ec61272743bf1614726446a6c38ced166f6ca76eb5430044286346cef130f92922b03450d3a9975e5bd2ea0eb55ad8e1b199e3ec4316020"
129- " e9a1b285e762795359b7bdfd39bef4b2484583d5afe082aee638bf5fd5a606193901a08f4ab41aab9b134880" ;
130- const char * ciphertext_cstr =
131- " 5961605353c64bdca15b195e288553a910632506d6200aa790c4c806c99904cf2445cc50bb1cf168a49673734e081b57e324ce5259c0e78d"
132- " 4cd97b870976503c0943f2cb5ae8f052c7b7d392239587b8956086bcab18836042e2e6ce42432a17105c53d0" ;
133-
134- // Pack hex strings into srsran types
135- sec_128_key key = make_sec_128_key (key_cstr);
136- auto dir = static_cast <security_direction>(direction);
137- byte_buffer plaintext = make_byte_buffer (plaintext_cstr).value ();
138- byte_buffer ciphertext = make_byte_buffer (ciphertext_cstr).value ();
139-
140- // Create ciphering engine
141- std::unique_ptr<ciphering_engine> nea = std::make_unique<ciphering_engine_nea2>(key, bearer, dir);
142-
143- // Apply ciphering and compare results
144- security_result result = nea->apply_ciphering (plaintext.deep_copy ().value (), 0 , count);
145- ASSERT_TRUE (result.buf .has_value ());
146- ASSERT_TRUE (trim_tail_to_bitlength (result.buf .value (), length));
147- EXPECT_EQ (result.buf .value (), ciphertext);
148- }
149-
150- // / 128-NEA2 Test Set 3
151- // / Ref: TS 33.501 Sec. D.4.4, TS 33.401 Sec. C.1 128-EEA2
152- TEST_F (ciphering_engine_test, security_nea2_testset3)
153- {
154- // Testdata in plain format
155- const char * key_cstr = " 0a8b6bd8d9b08b08d64e32d1817777fb" ;
156- uint32_t count = 0x544d49cd ;
157- uint8_t bearer = 0x04 ;
158- uint8_t direction = 0 ;
159- uint32_t length = 310 ;
160- const char * plaintext_cstr = " fd40a41d370a1f65745095687d47ba1d36d2349e23f644392c8ea9c49d40c13271aff264d0f248" ;
161- const char * ciphertext_cstr = " 75750d37b4bba2a4dedb34235bd68c6645acdaaca48138a3b0c471e2a7041a576423d2927287f0" ;
162-
163- // Pack hex strings into srsran types
164- sec_128_key key = make_sec_128_key (key_cstr);
165- auto dir = static_cast <security_direction>(direction);
166- byte_buffer plaintext = make_byte_buffer (plaintext_cstr).value ();
167- byte_buffer ciphertext = make_byte_buffer (ciphertext_cstr).value ();
168-
169- // Create ciphering engine
170- std::unique_ptr<ciphering_engine> nea = std::make_unique<ciphering_engine_nea2>(key, bearer, dir);
171-
172- // Apply ciphering and compare results
173- security_result result = nea->apply_ciphering (plaintext.deep_copy ().value (), 0 , count);
174- ASSERT_TRUE (result.buf .has_value ());
175- ASSERT_TRUE (trim_tail_to_bitlength (result.buf .value (), length));
176- EXPECT_EQ (result.buf .value (), ciphertext);
114+ fmt::memory_buffer buffer;
115+ fmt::format_to (buffer, " {}" , info.param .name );
116+ return fmt::to_string (buffer);
177117}
178118
179- // / 128-NEA2 Test Set 4
180- // / Ref: TS 33.501 Sec. D.4.4, TS 33.401 Sec. C.1 128-EEA2
181- TEST_F (ciphering_engine_test, security_nea2_testset4)
182- {
183- // Testdata in plain format
184- const char * key_cstr = " aa1f95aea533bcb32eb63bf52d8f831a" ;
185- uint32_t count = 0x72d8c671 ;
186- uint8_t bearer = 0x10 ;
187- uint8_t direction = 1 ;
188- uint32_t length = 1022 ;
189- const char * plaintext_cstr = " fb1b96c5c8badfb2e8e8edfde78e57f2ad81e74103fc430a534dcc37afcec70e1517bb06f27219dae49022d"
190- " dc47a068de4c9496a951a6b09edbdc864c7adbd740ac50c022f3082bafd22d78197c5d508b977bca13f32e6"
191- " 52e74ba728576077ce628c535e87dc6077ba07d29068590c8cb5f1088e082cfa0ec961302d69cf3d44" ;
192- const char * ciphertext_cstr = " dfb440acb3773549efc04628aeb8d8156275230bdc690d94b00d8d95f28c4b56307f60f4ca55eba661ebba"
193- " 72ac808fa8c49e26788ed04a5d606cb418de74878b9a22f8ef29590bc4eb57c9faf7c41524a885b8979c42"
194- " 3f2f8f8e0592a9879201be7ff9777a162ab810feb324ba74c4c156e04d39097209653ac33e5a5f2d8864" ;
195-
196- // Pack hex strings into srsran types
197- sec_128_key key = make_sec_128_key (key_cstr);
198- auto dir = static_cast <security_direction>(direction);
199- byte_buffer plaintext = make_byte_buffer (plaintext_cstr).value ();
200- byte_buffer ciphertext = make_byte_buffer (ciphertext_cstr).value ();
201-
202- // Create ciphering engine
203- std::unique_ptr<ciphering_engine> nea = std::make_unique<ciphering_engine_nea2>(key, bearer, dir);
204-
205- // Apply ciphering and compare results
206- security_result result = nea->apply_ciphering (plaintext.deep_copy ().value (), 0 , count);
207- ASSERT_TRUE (result.buf .has_value ());
208- ASSERT_TRUE (trim_tail_to_bitlength (result.buf .value (), length));
209- EXPECT_EQ (result.buf .value (), ciphertext);
210- }
211-
212- // / 128-NEA2 Test Set 5
213- // / Ref: TS 33.501 Sec. D.4.4, TS 33.401 Sec. C.1 128-EEA2
214- TEST_F (ciphering_engine_test, security_nea2_testset5)
215- {
216- // Testdata in plain format
217- const char * key_cstr = " 9618ae46891f86578eebe90ef7a1202e" ;
218- uint32_t count = 0xc675a64b ;
219- uint8_t bearer = 0x0c ;
220- uint8_t direction = 1 ;
221- uint32_t length = 1245 ;
222- const char * plaintext_cstr =
223- " 8daa17b1ae050529c6827f28c0ef6a1242e93f8b314fb18a77f790ae049fedd612267fecaefc450174d76d9f9aa7755a30cd90a9a5874bf4"
224- " 8eaf70eea3a62a250a8b6bd8d9b08b08d64e32d1817777fb544d49cd49720e219dbf8bbed33904e1fd40a41d370a1f65745095687d47ba1d"
225- " 36d2349e23f644392c8ea9c49d40c13271aff264d0f24841d6465f0996ff84e65fc517c53efc3363c38492a8" ;
226- const char * ciphertext_cstr =
227- " 919c8c33d66789703d05a0d7ce82a2aeac4ee76c0f4da050335e8a84e7897ba5df2f36bd513e3d0c8578c7a0fcf043e03aa3a39fbaad7d15"
228- " be074faa5d9029f71fb457b647834714b0e18f117fca10677945096c8c5f326ba8d6095eb29c3e36cf245d1622aafe921f7566c4f5d644f2"
229- " f1fc0ec684ddb21349747622e209295d27ff3f95623371d49b147c0af486171f22cd04b1cbeb2658223e6938" ;
230-
231- // Pack hex strings into srsran types
232- sec_128_key key = make_sec_128_key (key_cstr);
233- auto dir = static_cast <security_direction>(direction);
234- byte_buffer plaintext = make_byte_buffer (plaintext_cstr).value ();
235- byte_buffer ciphertext = make_byte_buffer (ciphertext_cstr).value ();
236-
237- // Create ciphering engine
238- std::unique_ptr<ciphering_engine> nea = std::make_unique<ciphering_engine_nea2>(key, bearer, dir);
239-
240- // Apply ciphering and compare results
241- security_result result = nea->apply_ciphering (plaintext.deep_copy ().value (), 0 , count);
242- ASSERT_TRUE (result.buf .has_value ());
243- ASSERT_TRUE (trim_tail_to_bitlength (result.buf .value (), length));
244- EXPECT_EQ (result.buf .value (), ciphertext);
245- }
246-
247- // / 128-NEA2 Test Set 6
248- // / Ref: TS 33.501 Sec. D.4.4, TS 33.401 Sec. C.1 128-EEA2
249- TEST_F (ciphering_engine_test, security_nea2_testset6)
250- {
251- // Testdata in plain format
252- const char * key_cstr = " 54f4e2e04c83786eec8fb5abe8e36566" ;
253- uint32_t count = 0xaca4f50f ;
254- uint8_t bearer = 0x0b ;
255- uint8_t direction = 0 ;
256- uint32_t length = 3861 ;
257- const char * plaintext_cstr =
258- " 40981ba6824c1bfb4286b299783daf442c099f7ab0f58d5c8e46b104f08f01b41ab485472029b71d36bd1a3d90dc3a41b46d51672ac4c966"
259- " 3a2be063da4bc8d2808ce33e2cccbfc634e1b259060876a0fbb5a437ebcc8d31c19e4454318745e3fa16bb11adae248879fe52db2543e53c"
260- " f445d3d828ce0bf5c560593d97278a59762dd0c2c9cd68d4496a792508614014b13b6aa51128c18cd6a90b87978c2ff1cabe7d9f898a411b"
261- " fdb84f68f6727b1499cdd30df0443ab4a66653330bcba1105e4cec034c73e605b4310eaaadcfd5b0ca27ffd89d144df4792759427c9cc1f8"
262- " cd8c87202364b8a687954cb05a8d4e2d99e73db160deb180ad0841e96741a5d59fe4189f15420026fe4cd12104932fb38f735340438aaf7e"
263- " ca6fd5cfd3a195ce5abe65272af607ada1be65a6b4c9c0693234092c4d018f1756c6db9dc8a6d80b888138616b681262f954d0e771174878"
264- " 0d92291d86299972db741cfa4f37b8b56cdb18a7ca8218e86e4b4b716a4d04371fbec262fc5ad0b3819b187b97e55b1a4d7c19ee24c8b4d7"
265- " 723cfedf045b8acae4869517d80e50615d9035d5d9c5a40af602280b542597b0cb18619eeb35925759d195e100e8e4aa0c38a3c2abe0f3d8"
266- " ff04f3c33c295069c23694b5bbeacdd542e28e8a94edb9119f412d054be1fa7200b090" ;
267- const char * ciphertext_cstr =
268- " 5cb72c6edc878f1566e10253afc364c9fa540d914db94cbee275d0917ca6af0d77acb4ef3bbe1a722b2ef5bd1d4b8e2aa5024ec1388a201e"
269- " 7bce7920aec615895f763a5564dcc4c482a2ee1d8bfecc4498eca83fbb75f9ab530e0dafbede2fa5895b82991b6277c529e0f2529d7f7960"
270- " 6be96706296dedfa9d7412b616958cb563c678c02825c30d0aee77c4c146d2765412421a808d13cec819694c75ad572e9b973d948b81a933"
271- " 7c3b2a17192e22c2069f7ed1162af44cdea817603665e807ce40c8e0dd9d6394dc6e31153fe1955c47afb51f2617ee0c5e3b8ef1ad7574ed"
272- " 343edc2743cc94c990e1f1fd264253c178dea739c0befeebcd9f9b76d49c1015c9fecf50e53b8b5204dbcd3eed863855dabcdcc94b31e318"
273- " 021568855c8b9e52a981957a112827f978ba960f1447911b317b5511fbcc7fb13ac153db74251117e4861eb9e83bffffc4eb7755579038e5"
274- " 7924b1f78b3e1ad90bab2a07871b72db5eef96c334044966db0c37cafd1a89e5646a3580eb6465f121dce9cb88d85b96cf23ccccd4280767"
275- " bee8eeb23d8652461db6493103003baf89f5e18261ea43c84a92ebffffe4909dc46c5192f825f770600b9602c557b5f8b431a79d45977dd9"
276- " c41b863da9e142e90020cfd074d6927b7ab3b6725d1a6f3f98b9c9daa8982aff067828" ;
277-
278- // Pack hex strings into srsran types
279- sec_128_key key = make_sec_128_key (key_cstr);
280- auto dir = static_cast <security_direction>(direction);
281- byte_buffer plaintext = make_byte_buffer (plaintext_cstr).value ();
282- byte_buffer ciphertext = make_byte_buffer (ciphertext_cstr).value ();
283-
284- // Create ciphering engine
285- std::unique_ptr<ciphering_engine> nea = std::make_unique<ciphering_engine_nea2>(key, bearer, dir);
286-
287- // Apply ciphering and compare results
288- security_result result = nea->apply_ciphering (plaintext.deep_copy ().value (), 0 , count);
289- ASSERT_TRUE (result.buf .has_value ());
290- ASSERT_TRUE (trim_tail_to_bitlength (result.buf .value (), length));
291- EXPECT_EQ (result.buf .value (), ciphertext);
292- }
119+ INSTANTIATE_TEST_SUITE_P (ciphering_engine_test_nea2,
120+ ciphering_engine_test,
121+ ::testing::ValuesIn (nea2_test_set.begin(), nea2_test_set.end()),
122+ test_param_info_to_string);
293123
294124int main (int argc, char ** argv)
295125{
0 commit comments