mirror of https://gerrit.osmocom.org/libosmocore
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:
parent
5248c47e1f
commit
a9c91cc0a1
|
@ -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);
|
||||
|
|
|
@ -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] */
|
||||
|
|
Loading…
Reference in New Issue