[AMF/MME] Fix crash during snow-3g encrypt (#2581)

There was a memory problem in the encryption using snow_3g_f8,
so AMF/MME crashed.

To solve this problem, we used the snow-3g encryption library
created as below.

https://github.com/rcatolino/libressl-snow3g

However, it seems that this library cannot be used to create
integrity hash like snow_3g_f8.

So, we decided to keep both snow-3g libraries for the time being.

1. lib/crypt/snow3g* : for INTEGRITY (NIA1, EIA1)
2. lib/crypt/openssl/snow3g* : for ENCRYPTION (NEA1, EEA1)
This commit is contained in:
Sukchan Lee 2023-09-13 23:15:28 +09:00
parent 05ed95d623
commit bd74c259ec
6 changed files with 1074 additions and 0 deletions

View file

@ -76,6 +76,7 @@ void ogs_nas_encrypt(uint8_t algorithm_identity,
uint8_t direction, ogs_pkbuf_t *pkbuf)
{
uint8_t ivec[16];
SNOW_CTX ctx;
ogs_assert(knas_enc);
ogs_assert(bearer <= 0x1f);
@ -86,8 +87,13 @@ void ogs_nas_encrypt(uint8_t algorithm_identity,
switch (algorithm_identity) {
case OGS_NAS_SECURITY_ALGORITHMS_128_EEA1:
#if 0 /* Issue #2581 : snow_3g_f8 have memory problem */
snow_3g_f8(knas_enc, count, bearer, direction,
pkbuf->data, (pkbuf->len << 3));
#else
SNOW_init(count, bearer, direction, (const char *)knas_enc, &ctx);
SNOW(pkbuf->len, pkbuf->data, pkbuf->data, &ctx);
#endif
break;
case OGS_NAS_SECURITY_ALGORITHMS_128_EEA2:
count = htonl(count);