1 /* GSM/GPRS/3G authentication core infrastructure */
3 /* (C) 2011 by Harald Welte <laforge@gnumonks.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <osmocom/crypt/auth.h>
20 #include "milenage/common.h"
21 #include "milenage/milenage.h"
23 static void sqn_u64_to_48bit(uint8_t *sqn
, const uint64_t sqn64
)
25 sqn
[5] = (sqn64
>> 0) & 0xff;
26 sqn
[4] = (sqn64
>> 8) & 0xff;
27 sqn
[3] = (sqn64
>> 16) & 0xff;
28 sqn
[2] = (sqn64
>> 24) & 0xff;
29 sqn
[1] = (sqn64
>> 32) & 0xff;
30 sqn
[0] = (sqn64
>> 40) & 0xff;
33 static uint64_t sqn_48bit_to_u64(const uint8_t *sqn
)
53 static int milenage_gen_vec(struct osmo_auth_vector
*vec
,
54 struct osmo_sub_auth_data
*aud
,
57 size_t res_len
= sizeof(vec
->res
);
61 sqn_u64_to_48bit(sqn
, aud
->u
.umts
.sqn
);
62 milenage_generate(aud
->u
.umts
.opc
, aud
->u
.umts
.amf
, aud
->u
.umts
.k
,
64 vec
->autn
, vec
->ik
, vec
->ck
, vec
->res
, &res_len
);
65 vec
->res_len
= res_len
;
66 rc
= gsm_milenage(aud
->u
.umts
.opc
, aud
->u
.umts
.k
, _rand
, vec
->sres
, vec
->kc
);
70 vec
->auth_types
= OSMO_AUTH_TYPE_UMTS
| OSMO_AUTH_TYPE_GSM
;
76 static int milenage_gen_vec_auts(struct osmo_auth_vector
*vec
,
77 struct osmo_sub_auth_data
*aud
,
78 const uint8_t *auts
, const uint8_t *rand_auts
,
86 /* Check if we only know OP and compute OPC if required */
87 if (aud
->type
== OSMO_AUTH_TYPE_UMTS
&& aud
->u
.umts
.opc_is_op
) {
88 rc
= milenage_opc_gen(gen_opc
, aud
->u
.umts
.k
,
94 opc
= aud
->u
.umts
.opc
;
96 rc
= milenage_auts(opc
, aud
->u
.umts
.k
, rand_auts
, auts
, sqn_out
);
100 aud
->u
.umts
.sqn
= sqn_48bit_to_u64(sqn_out
) + 1;
102 return milenage_gen_vec(vec
, aud
, _rand
);
105 static struct osmo_auth_impl milenage_alg
= {
106 .algo
= OSMO_AUTH_ALG_MILENAGE
,
107 .name
= "MILENAGE (libosmogsm built-in)",
109 .gen_vec
= &milenage_gen_vec
,
110 .gen_vec_auts
= &milenage_gen_vec_auts
,
113 static __attribute__((constructor
)) void on_dso_load_milenage(void)
115 osmo_auth_register(&milenage_alg
);