[openbsc 3/5] gprs: Use RAND_bytes for p-tmsi

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Daniel Willmann dwilllmann at sysmocom.de
Mon Oct 12 17:36:33 UTC 2015


From: Daniel Willmann <dwillmann at sysmocom.de>

[hfreyther: Link to libcrypto, include header, add uint8_t* cast]
---
 openbsc/src/gprs/Makefile.am   | 3 ++-
 openbsc/src/gprs/gprs_sgsn.c   | 6 +++++-
 openbsc/tests/sgsn/Makefile.am | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/openbsc/src/gprs/Makefile.am b/openbsc/src/gprs/Makefile.am
index f46a402..dcc6842 100644
--- a/openbsc/src/gprs/Makefile.am
+++ b/openbsc/src/gprs/Makefile.am
@@ -30,4 +30,5 @@ osmo_sgsn_SOURCES =	gprs_gmm.c gprs_sgsn.c gprs_sndcp.c gprs_sndcp_vty.c \
 			gsm_04_08_gprs.c sgsn_cdr.c sgsn_ares.c
 osmo_sgsn_LDADD = 	\
 			$(top_builddir)/src/libcommon/libcommon.a \
-			-lgtp $(OSMO_LIBS) $(LIBOSMOABIS_LIBS) $(LIBCARES_LIBS) -lrt
+			-lgtp $(OSMO_LIBS) $(LIBOSMOABIS_LIBS) $(LIBCARES_LIBS) \
+			$(LIBCRYPTO_LIBS) -lrt
diff --git a/openbsc/src/gprs/gprs_sgsn.c b/openbsc/src/gprs/gprs_sgsn.c
index f40de0b..9b11c35 100644
--- a/openbsc/src/gprs/gprs_sgsn.c
+++ b/openbsc/src/gprs/gprs_sgsn.c
@@ -41,6 +41,8 @@
 
 #include <time.h>
 
+#include <openssl/rand.h>
+
 #define GPRS_LLME_CHECK_TICK 30
 
 extern struct sgsn_instance *sgsn;
@@ -525,7 +527,9 @@ uint32_t sgsn_alloc_ptmsi(void)
 	int max_retries = 100;
 
 restart:
-	ptmsi = rand();
+	if (RAND_bytes((uint8_t *) &ptmsi, sizeof(ptmsi)) != 1)
+		goto failed;
+
 	/* Enforce that the 2 MSB are set without loosing the distance between
 	 * identical values. Since rand() has no duplicate values within a
 	 * period (because the size of the state is the same like the size of
diff --git a/openbsc/tests/sgsn/Makefile.am b/openbsc/tests/sgsn/Makefile.am
index 2782d9e..4c6ba9f 100644
--- a/openbsc/tests/sgsn/Makefile.am
+++ b/openbsc/tests/sgsn/Makefile.am
@@ -35,5 +35,6 @@ sgsn_test_LDADD = \
 	$(LIBOSMOGSM_LIBS) \
 	$(LIBOSMOGB_LIBS) \
 	$(LIBCARES_LIBS) \
+	$(LIBCRYPTO_LIBS) \
 	-lgtp -lrt
 
-- 
2.1.4




More information about the OpenBSC mailing list