aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2023-05-30 11:09:17 +0200
committerlaforge <laforge@osmocom.org>2023-06-02 08:29:55 +0000
commit5248c47e1f51e0f34bdf78bac150f9c3599f14a2 (patch)
treec978d3d0f05ca2504b16f8c00193a49390d28e48
parent08450c9ec6a2be9f58a9882e2ad0e78c61426254 (diff)
libosmogsm: Add OSMO_ASSERT() to ensure correct algorithm
Let's make sure that nobody ever ends up calling the algo_impl call-backs with data of a non-matching algorithm. This should never happen at all, as all normal users should go through the auth_core.c:osmo_auth_gen_vec* API, which dispatches based on algorithm. Change-Id: I22b504b6cffb4999b2f14772fffcb2f6f02c198c
-rw-r--r--src/gsm/auth_comp128v1.c1
-rw-r--r--src/gsm/auth_comp128v23.c2
-rw-r--r--src/gsm/auth_milenage.c4
-rw-r--r--src/gsm/auth_xor.c4
-rw-r--r--src/gsm/auth_xor_2g.c2
5 files changed, 13 insertions, 0 deletions
diff --git a/src/gsm/auth_comp128v1.c b/src/gsm/auth_comp128v1.c
index a314dc24..ded3f8a6 100644
--- a/src/gsm/auth_comp128v1.c
+++ b/src/gsm/auth_comp128v1.c
@@ -30,6 +30,7 @@ static int c128v1_gen_vec(struct osmo_auth_vector *vec,
struct osmo_sub_auth_data2 *aud,
const uint8_t *_rand)
{
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_COMP128v1);
comp128v1(aud->u.gsm.ki, _rand, vec->sres, vec->kc);
vec->auth_types = OSMO_AUTH_TYPE_GSM;
diff --git a/src/gsm/auth_comp128v23.c b/src/gsm/auth_comp128v23.c
index 697858a0..f942bc02 100644
--- a/src/gsm/auth_comp128v23.c
+++ b/src/gsm/auth_comp128v23.c
@@ -32,6 +32,7 @@ static int c128v2_gen_vec(struct osmo_auth_vector *vec,
struct osmo_sub_auth_data2 *aud,
const uint8_t *_rand)
{
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_COMP128v2);
comp128v2(aud->u.gsm.ki, _rand, vec->sres, vec->kc);
vec->auth_types = OSMO_AUTH_TYPE_GSM;
@@ -49,6 +50,7 @@ static int c128v3_gen_vec(struct osmo_auth_vector *vec,
struct osmo_sub_auth_data2 *aud,
const uint8_t *_rand)
{
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_COMP128v3);
comp128v3(aud->u.gsm.ki, _rand, vec->sres, vec->kc);
vec->auth_types = OSMO_AUTH_TYPE_GSM;
diff --git a/src/gsm/auth_milenage.c b/src/gsm/auth_milenage.c
index 36fbb064..84780c6b 100644
--- a/src/gsm/auth_milenage.c
+++ b/src/gsm/auth_milenage.c
@@ -55,6 +55,8 @@ static int milenage_gen_vec(struct osmo_auth_vector *vec,
uint64_t seq_1;
int rc;
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_MILENAGE);
+
opc = gen_opc_if_needed(aud, gen_opc);
if (!opc)
return -1;
@@ -150,6 +152,8 @@ static int milenage_gen_vec_auts(struct osmo_auth_vector *vec,
const uint8_t *opc;
int rc;
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_MILENAGE);
+
opc = gen_opc_if_needed(aud, gen_opc);
rc = milenage_auts(opc, aud->u.umts.k, rand_auts, auts, sqn_out);
diff --git a/src/gsm/auth_xor.c b/src/gsm/auth_xor.c
index 35525682..c94b02f7 100644
--- a/src/gsm/auth_xor.c
+++ b/src/gsm/auth_xor.c
@@ -50,6 +50,8 @@ static int xor_gen_vec(struct osmo_auth_vector *vec,
uint8_t ak[6], xmac[8];
int i;
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_XOR_3G);
+
/* Step 1: xdout = (ki or k) ^ rand */
if (aud->type == OSMO_AUTH_TYPE_GSM)
xor(xdout, aud->u.gsm.ki, _rand, sizeof(xdout));
@@ -134,6 +136,8 @@ static int xor_gen_vec_auts(struct osmo_auth_vector *vec,
uint8_t ak[6], xmac[8];
uint8_t sqnms[6];
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_XOR_3G);
+
/* Step 1: xdout = (ki or k) ^ rand */
if (aud->type == OSMO_AUTH_TYPE_GSM)
xor(xdout, aud->u.gsm.ki, _rand, sizeof(xdout));
diff --git a/src/gsm/auth_xor_2g.c b/src/gsm/auth_xor_2g.c
index 1a96b4a2..367c79d4 100644
--- a/src/gsm/auth_xor_2g.c
+++ b/src/gsm/auth_xor_2g.c
@@ -48,6 +48,8 @@ static int xor2g_gen_vec(struct osmo_auth_vector *vec,
{
uint8_t res1[16];
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_XOR_2G);
+
if (aud->type != OSMO_AUTH_TYPE_GSM)
return -ENOTSUP;