From patchwork Wed Jul 9 15:46:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max X-Patchwork-Id: 368252 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 8DC58140116 for ; Thu, 10 Jul 2014 01:48:42 +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 1X4u5z-0005ZP-NJ; Wed, 09 Jul 2014 17:47:48 +0200 Received: from hylle05.itea.ntnu.no ([2001:700:300:3::225]) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1X4u57-0005ZC-O7 for baseband-devel@lists.osmocom.org; Wed, 09 Jul 2014 17:46:56 +0200 Received: from localhost (localhost [127.0.0.1]) by hylle05.itea.ntnu.no (Postfix) with ESMTP id C403990A598 for ; Wed, 9 Jul 2014 17:46:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at hylle05.itea.ntnu.no Received: from alumnimail.it.ntnu.no (alumnimail.it.ntnu.no [129.241.18.22]) by hylle05.itea.ntnu.no (Postfix) with ESMTP id 88BE390A206 for ; Wed, 9 Jul 2014 17:46:50 +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 5B55B58050E for ; Wed, 9 Jul 2014 17:46:50 +0200 (CEST) From: Max Suraev To: baseband-devel@lists.osmocom.org Subject: [PATCH] Cleanup SQN code, use generic functions Date: Wed, 9 Jul 2014 17:46:40 +0200 Message-Id: <1404920800-21107-1-git-send-email-Max.Suraev@fairwaves.co> X-Mailer: git-send-email 1.9.1 X-Spam-Score: 0.0 (/) 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 --- src/gsm/auth_milenage.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/gsm/auth_milenage.c b/src/gsm/auth_milenage.c index 5b2787d..1635ac6 100644 --- a/src/gsm/auth_milenage.c +++ b/src/gsm/auth_milenage.c @@ -21,39 +21,10 @@ */ #include +#include #include "milenage/common.h" #include "milenage/milenage.h" -static void sqn_u64_to_48bit(uint8_t *sqn, const uint64_t sqn64) -{ - sqn[5] = (sqn64 >> 0) & 0xff; - sqn[4] = (sqn64 >> 8) & 0xff; - sqn[3] = (sqn64 >> 16) & 0xff; - sqn[2] = (sqn64 >> 24) & 0xff; - sqn[1] = (sqn64 >> 32) & 0xff; - sqn[0] = (sqn64 >> 40) & 0xff; -} - -static uint64_t sqn_48bit_to_u64(const uint8_t *sqn) -{ - uint64_t sqn64; - - sqn64 = sqn[0]; - sqn64 <<= 8; - sqn64 |= sqn[1]; - sqn64 <<= 8; - sqn64 |= sqn[2]; - sqn64 <<= 8; - sqn64 |= sqn[3]; - sqn64 <<= 8; - sqn64 |= sqn[4]; - sqn64 <<= 8; - sqn64 |= sqn[5]; - - return sqn64; -} - - static int milenage_gen_vec(struct osmo_auth_vector *vec, struct osmo_sub_auth_data *aud, const uint8_t *_rand) @@ -62,7 +33,7 @@ static int milenage_gen_vec(struct osmo_auth_vector *vec, uint8_t sqn[6]; int rc; - sqn_u64_to_48bit(sqn, aud->u.umts.sqn); + osmo_store64be_ext(aud->u.umts.sqn, sqn, 6); milenage_generate(aud->u.umts.opc, aud->u.umts.amf, aud->u.umts.k, sqn, _rand, vec->autn, vec->ik, vec->ck, vec->res, &res_len); @@ -101,7 +72,7 @@ static int milenage_gen_vec_auts(struct osmo_auth_vector *vec, if (rc < 0) return rc; - aud->u.umts.sqn = sqn_48bit_to_u64(sqn_out) + 1; + aud->u.umts.sqn = 1 + (osmo_load64be_ext(sqn_out, 6) >> 16); return milenage_gen_vec(vec, aud, _rand); }