Skip to content

Commit a48023a

Browse files
sec: add NEA3 ciphering engine
1 parent ceff955 commit a48023a

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

lib/security/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(SOURCES
1111
ciphering_engine_generic.cpp
1212
ciphering_engine_nea1.cpp
1313
ciphering_engine_nea2.cpp
14+
ciphering_engine_nea3.cpp
1415
integrity_engine_generic.cpp
1516
security.cpp
1617
security_engine_impl.cpp
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
*
3+
* \section COPYRIGHT
4+
*
5+
* Copyright 2021-2024 Software Radio Systems Limited
6+
*
7+
* By using this file, you agree to the terms and conditions set
8+
* forth in the LICENSE file which can be found at the top level of
9+
* the distribution.
10+
*
11+
*/
12+
13+
#include "ciphering_engine_nea3.h"
14+
#include "srsran/security/ciphering.h"
15+
16+
using namespace srsran;
17+
using namespace security;
18+
19+
ciphering_engine_nea3::ciphering_engine_nea3(sec_128_key k_128_enc_,
20+
uint8_t bearer_id_,
21+
security_direction direction_) :
22+
k_128_enc(k_128_enc_), bearer_id(bearer_id_), direction(direction_)
23+
{
24+
}
25+
26+
security_result ciphering_engine_nea3::apply_ciphering(byte_buffer buf, size_t offset, uint32_t count)
27+
{
28+
security_result result{.buf = std::move(buf), .count = count};
29+
byte_buffer_view msg{result.buf.value().begin() + offset, result.buf.value().end()};
30+
31+
security_nea3(k_128_enc, count, bearer_id, direction, msg);
32+
33+
return result;
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
*
3+
* \section COPYRIGHT
4+
*
5+
* Copyright 2021-2024 Software Radio Systems Limited
6+
*
7+
* By using this file, you agree to the terms and conditions set
8+
* forth in the LICENSE file which can be found at the top level of
9+
* the distribution.
10+
*
11+
*/
12+
13+
#pragma once
14+
15+
#include "srsran/security/ciphering_engine.h"
16+
#include "srsran/security/security.h"
17+
18+
namespace srsran {
19+
namespace security {
20+
21+
class ciphering_engine_nea3 final : public ciphering_engine
22+
{
23+
public:
24+
ciphering_engine_nea3(sec_128_key k_128_enc_, uint8_t bearer_id_, security_direction direction_);
25+
virtual ~ciphering_engine_nea3() = default;
26+
27+
security_result apply_ciphering(byte_buffer buf, size_t offset, uint32_t count) override;
28+
29+
private:
30+
sec_128_key k_128_enc;
31+
uint8_t bearer_id;
32+
security_direction direction;
33+
};
34+
35+
} // namespace security
36+
} // namespace srsran

lib/security/security_engine_impl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ciphering_engine_generic.h"
1515
#include "ciphering_engine_nea1.h"
1616
#include "ciphering_engine_nea2.h"
17+
#include "ciphering_engine_nea3.h"
1718
#include "integrity_engine_generic.h"
1819

1920
using namespace srsran;
@@ -42,9 +43,12 @@ security_engine_impl::security_engine_impl(security::sec_128_as_config sec_cfg,
4243
case ciphering_algorithm::nea2:
4344
cipher_eng = std::make_unique<ciphering_engine_nea2>(sec_cfg.k_128_enc, bearer_id, direction);
4445
break;
46+
case ciphering_algorithm::nea3:
47+
cipher_eng = std::make_unique<ciphering_engine_nea3>(sec_cfg.k_128_enc, bearer_id, direction);
48+
break;
4549
default:
46-
cipher_eng =
47-
std::make_unique<ciphering_engine_generic>(sec_cfg.k_128_enc, bearer_id, direction, sec_cfg.cipher_algo);
50+
// no cipher_eng for NEA0
51+
break;
4852
}
4953
}
5054
}

tests/unittests/security/ciphering_engine_test.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "lib/security/ciphering_engine_generic.h"
1212
#include "lib/security/ciphering_engine_nea1.h"
1313
#include "lib/security/ciphering_engine_nea2.h"
14+
#include "lib/security/ciphering_engine_nea3.h"
1415
#include "nea1_test_set.h"
1516
#include "nea2_test_set.h"
1617
#include "nea3_test_set.h"
@@ -144,6 +145,26 @@ TEST_P(fxt_nea2, ciphering_engine_nea2)
144145
EXPECT_EQ(result.buf.value(), ciphertext);
145146
}
146147

148+
TEST_P(fxt_nea3, ciphering_engine_nea3)
149+
{
150+
nea_test_set param = GetParam();
151+
152+
// Pack hex strings into srsran types
153+
sec_128_key key = make_sec_128_key(param.key_cstr);
154+
auto dir = static_cast<security_direction>(param.direction);
155+
byte_buffer plaintext = make_byte_buffer(param.plaintext_cstr).value();
156+
byte_buffer ciphertext = make_byte_buffer(param.ciphertext_cstr).value();
157+
158+
// Create ciphering engine
159+
std::unique_ptr<ciphering_engine> nea = std::make_unique<ciphering_engine_nea3>(key, param.bearer, dir);
160+
161+
// Apply ciphering and compare results
162+
security_result result = nea->apply_ciphering(plaintext.deep_copy().value(), 0, param.count);
163+
ASSERT_TRUE(result.buf.has_value());
164+
ASSERT_TRUE(trim_tail_to_bitlength(result.buf.value(), param.length));
165+
EXPECT_EQ(result.buf.value(), ciphertext);
166+
}
167+
147168
TEST_P(fxt_nea1, ciphering_engine_generic_nea1)
148169
{
149170
nea_test_set param = GetParam();

0 commit comments

Comments
 (0)