From e335b91ccd6175f43d8bb0c2ea4811e49cb4d95b Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 30 Jun 2010 19:50:14 +0200 Subject: [PATCH] GPRS: Add 'input' generator functions for GPRS cipher algorithm --- include/osmocom/crypt/gprs_cipher.h | 6 ++++++ src/gprs_cipher_core.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/osmocom/crypt/gprs_cipher.h b/include/osmocom/crypt/gprs_cipher.h index 165603764..3e514ec7f 100644 --- a/include/osmocom/crypt/gprs_cipher.h +++ b/include/osmocom/crypt/gprs_cipher.h @@ -45,4 +45,10 @@ int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo, /* Do we have an implementation for this cipher? */ int gprs_cipher_supported(enum gprs_ciph_algo algo); +/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ +uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc); + +/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ +uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc); + #endif /* _GPRS_CIPHER_H */ diff --git a/src/gprs_cipher_core.c b/src/gprs_cipher_core.c index a72dda846..6174bd727 100644 --- a/src/gprs_cipher_core.c +++ b/src/gprs_cipher_core.c @@ -83,3 +83,17 @@ int gprs_cipher_supported(enum gprs_ciph_algo algo) return 0; } + +/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ +uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc) +{ + uint32_t sx = ((1<<27) * sapi) + (1<<31); + + return (iov_ui ^ sx) + lfn + oc; +} + +/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ +uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc) +{ + return iov_i + lfn + oc; +}