From patchwork Tue Jun 17 09:16:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max X-Patchwork-Id: 360414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 93B53140091 for ; Tue, 17 Jun 2014 19:18:58 +1000 (EST) Received: from localhost ([127.0.0.1] helo=ganesha.gnumonks.org) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1WwpX6-0001EB-GH; Tue, 17 Jun 2014 11:18:24 +0200 Received: from hylle06.itea.ntnu.no ([129.241.56.235]) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1WwpVw-0001BO-31 for baseband-devel@lists.osmocom.org; Tue, 17 Jun 2014 11:17:17 +0200 Received: from localhost (localhost [127.0.0.1]) by hylle06.itea.ntnu.no (Postfix) with ESMTP id 2FE02667B11 for ; Tue, 17 Jun 2014 11:17:10 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at hylle06.itea.ntnu.no Received: from alumnimail.it.ntnu.no (alumnimail.it.ntnu.no [129.241.18.22]) by hylle06.itea.ntnu.no (Postfix) with ESMTP id ABF57667B0F for ; Tue, 17 Jun 2014 11:17:09 +0200 (CEST) Received: from localhost (nat.sec.t-labs.tu-berlin.de [130.149.230.1]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: suraev) by alumnimail.it.ntnu.no (Postfix) with ESMTPSA id 536685804E1 for ; Tue, 17 Jun 2014 11:17:09 +0200 (CEST) From: Max Suraev To: baseband-devel@lists.osmocom.org Subject: [PATCH] Update internal GPRS cipher API to comply with ETSI TS 155.22 Date: Tue, 17 Jun 2014 11:16:58 +0200 Message-Id: <1402996618-7967-1-git-send-email-Max.Suraev@fairwaves.co> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1395085252-7428-1-git-send-email-max.suraev@fairwaves.co> References: <1395085252-7428-1-git-send-email-max.suraev@fairwaves.co> X-Spam-Score: -2.3 (--) X-BeenThere: baseband-devel@lists.osmocom.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Development discussion about Osmocom BaseBand List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: baseband-devel-bounces@lists.osmocom.org Errors-To: baseband-devel-bounces@lists.osmocom.org Signed-off-by: Max Suraev --- TODO-RELEASE | 3 ++- include/osmocom/crypt/gprs_cipher.h | 8 ++++++-- src/gsm/gprs_cipher_core.c | 23 +++++++++++++++++++++-- src/gsm/libosmogsm.map | 1 + 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/TODO-RELEASE b/TODO-RELEASE index 43b1e8e..c7366ae 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -1 +1,2 @@ -#library what description / commit summary line +#library what description / commit summary line +libosmogsm internal API update Internal API for GPRS cipher implementors updated to accommodate for arbitrary key lengths \ No newline at end of file diff --git a/include/osmocom/crypt/gprs_cipher.h b/include/osmocom/crypt/gprs_cipher.h index 940b07b..d6edefa 100644 --- a/include/osmocom/crypt/gprs_cipher.h +++ b/include/osmocom/crypt/gprs_cipher.h @@ -9,6 +9,7 @@ enum gprs_ciph_algo { GPRS_ALGO_GEA1, GPRS_ALGO_GEA2, GPRS_ALGO_GEA3, + GPRS_ALGO_GEA4, _GPRS_ALGO_NUM }; @@ -27,7 +28,7 @@ struct gprs_cipher_impl { /* As specified in 04.64 Annex A. Uses Kc, IV and direction * to generate the 1523 bytes cipher stream that need to be * XORed wit the plaintext for encrypt / ciphertext for decrypt */ - int (*run)(uint8_t *out, uint16_t len, uint64_t kc, uint32_t iv, + int (*run)(uint8_t *out, uint16_t len, uint8_t *kc, uint32_t iv, enum gprs_cipher_direction direction); }; @@ -39,11 +40,14 @@ int gprs_cipher_load(const char *path); /* function to be called by core code */ int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo, - uint64_t kc, uint32_t iv, enum gprs_cipher_direction dir); + uint8_t *kc, uint32_t iv, enum gprs_cipher_direction dir); /* Do we have an implementation for this cipher? */ int gprs_cipher_supported(enum gprs_ciph_algo algo); +/* Return key length for supported cipher, in bytes */ +unsigned gprs_cipher_key_length(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); diff --git a/src/gsm/gprs_cipher_core.c b/src/gsm/gprs_cipher_core.c index b9a22a1..e4fac04 100644 --- a/src/gsm/gprs_cipher_core.c +++ b/src/gsm/gprs_cipher_core.c @@ -53,12 +53,14 @@ int gprs_cipher_register(struct gprs_cipher_impl *ciph) int gprs_cipher_load(const char *path) { /* load all plugins available from path */ - return osmo_plugin_load_all(path); + if (path) + return osmo_plugin_load_all(path); + return 0; } /* function to be called by core code */ int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo, - uint64_t kc, uint32_t iv, enum gprs_cipher_direction dir) + uint8_t *kc, uint32_t iv, enum gprs_cipher_direction dir) { if (algo >= ARRAY_SIZE(selected_ciphers)) return -ERANGE; @@ -73,6 +75,23 @@ int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo, return selected_ciphers[algo]->run(out, len, kc, iv, dir); } +/*! \brief Obtain key lenght for given GPRS cipher + * \param[in] algo Enum representive GPRS cipher + * \returns unsigned integer key length for supported algorithms, + * for GEA0 and unknown ciphers will return 0 + */ +unsigned gprs_cipher_key_length(enum gprs_ciph_algo algo) +{ + switch (algo) { + case GPRS_ALGO_GEA0: return 0; + case GPRS_ALGO_GEA1: + case GPRS_ALGO_GEA2: + case GPRS_ALGO_GEA3: return 8; + case GPRS_ALGO_GEA4: return 16; + default: return 0; + } +} + int gprs_cipher_supported(enum gprs_ciph_algo algo) { if (algo >= ARRAY_SIZE(selected_ciphers)) diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index cab4fc4..7808be6 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -32,6 +32,7 @@ gprs_cipher_load; gprs_cipher_register; gprs_cipher_run; gprs_cipher_supported; +gprs_cipher_key_length; gprs_tlli_type; gprs_tmsi2tlli;