libosmogsm: Ensure MILENAGE + XOR-3G K length is 128 bit

Since Change-Id Ie775fedba4a3fa12314c0f7c8a369662ef6a40df we are
supporting K-lengths != 128 bit.  However, our existing MILENAGE
and XOR-3G algorithms only support that key length, so let's add
some explicit checks for that.

Change-Id: Iae8b93cf059abda087101cdd01bbcf92d355753b
This commit is contained in:
Harald Welte 2023-05-30 11:58:28 +02:00 committed by laforge
parent 5248c47e1f
commit a9c91cc0a1
2 changed files with 19 additions and 4 deletions

View File

@ -19,6 +19,7 @@
*
*/
#include <errno.h>
#include <osmocom/crypt/auth.h>
#include <osmocom/core/bits.h>
#include "milenage/common.h"
@ -57,6 +58,11 @@ static int milenage_gen_vec(struct osmo_auth_vector *vec,
OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_MILENAGE);
if (aud->u.umts.k_len != 16)
return -EINVAL;
if (aud->u.umts.opc_len != 16)
return -EINVAL;
opc = gen_opc_if_needed(aud, gen_opc);
if (!opc)
return -1;
@ -154,6 +160,11 @@ static int milenage_gen_vec_auts(struct osmo_auth_vector *vec,
OSMO_ASSERT(aud->algo == OSMO_AUTH_ALG_MILENAGE);
if (aud->u.umts.k_len != 16)
return -EINVAL;
if (aud->u.umts.opc_len != 16)
return -EINVAL;
opc = gen_opc_if_needed(aud, gen_opc);
rc = milenage_auts(opc, aud->u.umts.k, rand_auts, auts, sqn_out);

View File

@ -55,9 +55,11 @@ static int xor_gen_vec(struct osmo_auth_vector *vec,
/* Step 1: xdout = (ki or k) ^ rand */
if (aud->type == OSMO_AUTH_TYPE_GSM)
xor(xdout, aud->u.gsm.ki, _rand, sizeof(xdout));
else if (aud->type == OSMO_AUTH_TYPE_UMTS)
else if (aud->type == OSMO_AUTH_TYPE_UMTS) {
if (aud->u.umts.k_len != 16)
return -EINVAL;
xor(xdout, aud->u.umts.k, _rand, sizeof(xdout));
else
} else
return -ENOTSUP;
/**
@ -141,9 +143,11 @@ static int xor_gen_vec_auts(struct osmo_auth_vector *vec,
/* Step 1: xdout = (ki or k) ^ rand */
if (aud->type == OSMO_AUTH_TYPE_GSM)
xor(xdout, aud->u.gsm.ki, _rand, sizeof(xdout));
else if (aud->type == OSMO_AUTH_TYPE_UMTS)
else if (aud->type == OSMO_AUTH_TYPE_UMTS) {
if (aud->u.umts.k_len != 16)
return -EINVAL;
xor(xdout, aud->u.umts.k, _rand, sizeof(xdout));
else
} else
return -ENOTSUP;
/* Step 2: ak = xdout[2-8] */