From aead05da321e3accaffec471d547d3a7174091b2 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 21 Apr 2016 15:57:52 +0200 Subject: Improve code reuse Use generic functions covered by testsuit for SQN calculations. --- src/gsm/auth_milenage.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/gsm/auth_milenage.c b/src/gsm/auth_milenage.c index 5b2787dd..1635ac6b 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); } -- cgit v1.2.3