Project

General

Profile

Feature #2475 ยป 0001-WIP-Add-support-for-XOR-authentication.patch

WIP patch for XOR support - daniel, 09/07/2017 03:22 PM

View differences:

src/gsm/Makefile.am
25 25
			gprs_cipher_core.c gprs_rlc.c gsm0480.c abis_nm.c gsm0502.c \
26 26
			gsm0411_utils.c gsm0411_smc.c gsm0411_smr.c gsm0414.c \
27 27
			lapd_core.c lapdm.c kasumi.c gsm_04_08_gprs.c \
28
			auth_core.c auth_comp128v1.c auth_comp128v23.c \
28
			auth_core.c auth_comp128v1.c auth_comp128v23.c auth_xor.c \
29 29
			auth_milenage.c milenage/aes-encblock.c gea.c \
30 30
			milenage/aes-internal.c milenage/aes-internal-enc.c \
31 31
			milenage/milenage.c gan.c ipa.c gsm0341.c apn.c \
src/gsm/auth_xor.c
1
/*! \file auth_xor.c
2
 * GSM/GPRS/3G authentication core infrastructure */
3
/*
4
 * (C) 2017 by sysmocom s.f.m.c. GmbH
5
 * All Rights Reserved
6
 *
7
 * Author: Daniel Willmann <dwillmann@sysmocom.de>
8
 *
9
 * All Rights Reserved
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License along
22
 * with this program; if not, write to the Free Software Foundation, Inc.,
23
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
 *
25
 */
26

  
27
#include <osmocom/crypt/auth.h>
28
#include <string.h>
29

  
30
/*! \addtogroup auth
31
 *  @{
32
 */
33

  
34
static void xor(uint8_t *out, const uint8_t *a, const uint8_t *b, int len)
35
{
36
	int i;
37

  
38
	for (i = 0; i < len; i++) {
39
		out[i] = a[i] ^ b[i];
40
	}
41
}
42

  
43
/* 3GPP TS 34.108 8.1.2.1 XOR auth proceture */
44
static int xor_gen_vec(struct osmo_auth_vector *vec,
45
			  struct osmo_sub_auth_data *aud,
46
			  const uint8_t *_rand)
47
{
48
	int i;
49
	uint8_t xdout[16], ak[6], cdout[8], xmac[8];
50
	/* res[16], ck[16], ik[16],*/
51

  
52

  
53
	// s1: xdout = ki XOR rand
54
	xor(xdout, aud->u.umts.k, _rand, sizeof(xdout));
55
	
56
	// s2: res = xdout
57
	memcpy(vec->res, xdout, sizeof(xdout));
58
	vec->res_len = 16;
59
	// ck = xdout[1-15,0]
60
	memcpy(vec->ck, xdout+1, sizeof(xdout)-1);
61
	vec->ck[15] = xdout[0];
62
	// ik = xdout[2-15,0-1]
63
	memcpy(vec->ik, xdout+2, sizeof(xdout)-2);
64
	memcpy(vec->ik + 14, xdout, 2);
65
	// ak = xdout[3-8]
66
	memcpy(ak, xdout + 3, sizeof(ak));
67
	// kc = c3(ck, ik)
68
	for (i = 0; i < 8; i++)
69
		vec->kc[i] = vec->ck[i] ^ vec->ck[i + 8] ^ vec->ik[i] ^ vec->ik[i + 8];
70

  
71
	for (i = 0; i < 4; i++)
72
		vec->sres[i] = vec->res[i] ^ vec->res[i + 4];
73

  
74
	// s3: cdout = sqn || amf
75
	memcpy(cdout, &aud->u.umts.sqn, 6);
76
	0ggmemcpy(cdout + 6, aud->u.umts.amf, sizeof(aud->u.umts.amf));
77
	// s4: xmac = xdout[0-8] XOR cdout[0-8]
78
	xor(xmac, xdout, cdout, sizeof(xmac));
79
	// s5: autn = sqn XOR ak || amv || mac
80
	xor(vec->autn, &aud->u.umts.sqn, ak, sizeof(ak));
81
	memcpy(vec->autn + 6, aud->u.umts.amf, sizeof(aud->u.umts.amf));
82
	memcpy(vec->autn + 8, xmac, sizeof(xmac));
83

  
84
	vec->auth_types = OSMO_AUTH_TYPE_UMTS | OSMO_AUTH_TYPE_GSM;
85

  
86
	return 0;
87
}
88

  
89
static struct osmo_auth_impl xor_alg = {
90
	.algo = OSMO_AUTH_ALG_XOR,
91
	.name = "XOR (libosmogsm built-in)",
92
	.priority = 1000,
93
	.gen_vec = &xor_gen_vec,
94
};
95

  
96
static __attribute__((constructor)) void on_dso_load_xor(void)
97
{
98
	osmo_auth_register(&xor_alg);
99
}
100

  
101
/*! @} */
    (1-1/1)
    Add picture from clipboard (Maximum size: 48.8 MB)