From fdb3d8ce7898801d5b18d446a17ccc0f09451d4f Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 21 Apr 2016 16:51:04 +0200 Subject: [PATCH] Deprecate osmo_a5_1 and osmo_a5_2 Mark the functions as deprecated to discourage their use: people should use unified osmo_a5 which supports all the A5/1-4 ciphers. --- include/osmocom/gsm/a5.h | 5 +- src/gsm/a5.c | 108 +++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/include/osmocom/gsm/a5.h b/include/osmocom/gsm/a5.h index d22cdbbbd..a2278f22a 100644 --- a/include/osmocom/gsm/a5.h +++ b/include/osmocom/gsm/a5.h @@ -24,6 +24,7 @@ #include +#include #include /*! \defgroup a5 GSM A5 ciphering algorithm @@ -54,7 +55,7 @@ osmo_a5_fn_count(uint32_t fn) * (converted internally to fn_count) */ int osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); -void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); -void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); +void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) OSMO_DEPRECATED("Use generic osmo_a5() instead"); +void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) OSMO_DEPRECATED("Use generic osmo_a5() instead"); /*! @} */ diff --git a/src/gsm/a5.c b/src/gsm/a5.c index d0c7c5f52..f1fd697ee 100644 --- a/src/gsm/a5.c +++ b/src/gsm/a5.c @@ -101,54 +101,6 @@ _a5_3(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul, bool fn_correct) _a5_4(ck, fn, dl, ul, fn_correct); } -/*! \brief Main method to generate a A5/x cipher stream - * \param[in] n Which A5/x method to use - * \param[in] key 8 or 16 (for a5/4) byte array for the key (as received from the SIM) - * \param[in] fn Frame number - * \param[out] dl Pointer to array of ubits to return Downlink cipher stream - * \param[out] ul Pointer to array of ubits to return Uplink cipher stream - * \returns 0 for success, -ENOTSUP for invalid cipher selection. - * - * Currently A5/[0-4] are supported. - * Either (or both) of dl/ul can be NULL if not needed. - */ -int -osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) -{ - switch (n) - { - case 0: - if (dl) - memset(dl, 0x00, 114); - if (ul) - memset(ul, 0x00, 114); - break; - - case 1: - osmo_a5_1(key, fn, dl, ul); - break; - - case 2: - osmo_a5_2(key, fn, dl, ul); - break; - - case 3: - _a5_3(key, fn, dl, ul, true); - break; - - case 4: - _a5_4(key, fn, dl, ul, true); - break; - - default: - /* a5/[5..7] not supported here/yet */ - return -ENOTSUP; - } - - return 0; -} - - /* ------------------------------------------------------------------------ */ /* A5/1&2 common stuff */ /* ------------------------------------------------------------------------ */ @@ -261,7 +213,7 @@ _a5_1_get_output(uint32_t r[]) * Either (or both) of dl/ul can be NULL if not needed. */ void -osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) +_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) { uint32_t r[3] = {0, 0, 0}; uint32_t fn_count; @@ -314,6 +266,10 @@ osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) } } +void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) +{ + osmo_a5(1, key, fn, dl, ul); +} /* ------------------------------------------------------------------------ */ /* A5/2 */ @@ -378,7 +334,7 @@ _a5_2_get_output(uint32_t r[]) * Either (or both) of dl/ul can be NULL if not needed. */ void -osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) +_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) { uint32_t r[4] = {0, 0, 0, 0}; uint32_t fn_count; @@ -438,4 +394,56 @@ osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) } } +void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) +{ + osmo_a5(2, key, fn, dl, ul); +} + +/*! \brief Main method to generate a A5/x cipher stream + * \param[in] n Which A5/x method to use + * \param[in] key 8 or 16 (for a5/4) byte array for the key (as received from the SIM) + * \param[in] fn Frame number + * \param[out] dl Pointer to array of ubits to return Downlink cipher stream + * \param[out] ul Pointer to array of ubits to return Uplink cipher stream + * \returns 0 for success, -ENOTSUP for invalid cipher selection. + * + * Currently A5/[0-4] are supported. + * Either (or both) of dl/ul can be NULL if not needed. + */ +int +osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul) +{ + switch (n) + { + case 0: + if (dl) + memset(dl, 0x00, 114); + if (ul) + memset(ul, 0x00, 114); + break; + + case 1: + _a5_1(key, fn, dl, ul); + break; + + case 2: + _a5_2(key, fn, dl, ul); + break; + + case 3: + _a5_3(key, fn, dl, ul, true); + break; + + case 4: + _a5_4(key, fn, dl, ul, true); + break; + + default: + /* a5/[5..7] not supported here/yet */ + return -ENOTSUP; + } + + return 0; +} + /*! @} */