From 4b2b0cc15d51d7916a939de06a7e83d8042211dc Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 10 Jul 2017 14:32:48 +0200 Subject: Add function to generate random identifier The function is a wrapper on top of getrandom() (if available via glibc) or corresponding syscall. If neither is available than failure is always returned. It's intended to generate small random data good enough for session identifiers and keys. To generate long-term cryptographic keys it's better to use special crypto libraries (like GnuTLS for example) instead. As an example it's used to replace old insecure random number generator in osmo-auc-gen utility. Change-Id: I0241b814ea4c4ce1458f7ad76e31d390383c2048 Related: OS#1694 --- include/osmocom/gsm/gsm_utils.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/osmocom/gsm') diff --git a/include/osmocom/gsm/gsm_utils.h b/include/osmocom/gsm/gsm_utils.h index bfcef08b..83e29cac 100644 --- a/include/osmocom/gsm/gsm_utils.h +++ b/include/osmocom/gsm/gsm_utils.h @@ -38,6 +38,9 @@ #define GSM_MAX_FN (26*51*2048) +/* Max length of random identifier which can be requested via osmo_get_rand_id() */ +#define OSMO_MAX_RAND_ID_LEN 16 + struct gsm_time { uint32_t fn; /* FN count */ uint16_t t1; /* FN div (26*51) */ @@ -60,6 +63,8 @@ enum gsm_band { const char *gsm_band_name(enum gsm_band band); enum gsm_band gsm_band_parse(const char *mhz); +int osmo_get_rand_id(uint8_t *out, size_t len); + /*! * Decode a sequence of GSM 03.38 encoded 7 bit characters. * -- cgit v1.2.3