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
diff --git a/src/gsm/auth_comp128v1.c b/src/gsm/auth_comp128v1.c
index a314dc2..ded3f8a 100644
--- a/src/gsm/auth_comp128v1.c
+++ b/src/gsm/auth_comp128v1.c
@@ -30,6 +30,7 @@
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 697858a..f942bc0 100644
--- a/src/gsm/auth_comp128v23.c
+++ b/src/gsm/auth_comp128v23.c
@@ -32,6 +32,7 @@
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 @@
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 36fbb06..84780c6 100644
--- a/src/gsm/auth_milenage.c
+++ b/src/gsm/auth_milenage.c
@@ -55,6 +55,8 @@
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 @@
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 3552568..c94b02f 100644
--- a/src/gsm/auth_xor.c
+++ b/src/gsm/auth_xor.c
@@ -50,6 +50,8 @@
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 @@
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 1a96b4a..367c79d 100644
--- a/src/gsm/auth_xor_2g.c
+++ b/src/gsm/auth_xor_2g.c
@@ -48,6 +48,8 @@
{
uint8_t res1[16];
+ OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_XOR_2G);
+
if (aud->type != OSMO_AUTH_TYPE_GSM)
return -ENOTSUP;