[PATCH] osmo-hlr[master]: tests: auc_3g_test: implement vector generation test

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Wed Feb 1 13:00:50 UTC 2017


Review at  https://gerrit.osmocom.org/1720

tests: auc_3g_test: implement vector generation test

Change-Id: I291bccd62661ff5790dc43d91dc63a9e4b0e0ff2
---
M src/auc.c
M tests/auc/auc_3g_test.c
M tests/auc/auc_3g_test.err
3 files changed, 371 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/20/1720/1

diff --git a/src/auc.c b/src/auc.c
index 7d8597a..bec3ea6 100644
--- a/src/auc.c
+++ b/src/auc.c
@@ -47,6 +47,7 @@
 	/* compute quintuples */
 	for (i = 0; i < num_vec; i++) {
 		rc = rand_get(rand, sizeof(rand));
+		DEBUGP(DAUC, "rand %s\n", osmo_hexdump_nospc(rand, sizeof(rand)));
 		if (rc != sizeof(rand)) {
 			LOGP(DAUC, LOGL_ERROR, "Unable to read %zu random "
 			     "bytes: rc=%d\n", sizeof(rand), rc);
@@ -65,8 +66,9 @@
 			}
 		} else if (aud3g) {
 			/* 3G or 3G + 2G case */
-			DEBUGP(DAUC, "compute vector [%u]/%u: 3G or 3G + 2G\n",
-			       i, num_vec);
+			if (!aud2g)
+				DEBUGP(DAUC, "compute vector [%u]/%u: 3G only\n",
+				       i, num_vec);
 			if (rand_auts && auts)
 				rc = osmo_auth_gen_vec_auts(vec+i, aud3g,
 							    rand_auts,
diff --git a/tests/auc/auc_3g_test.c b/tests/auc/auc_3g_test.c
index 1444f46..bfca39f 100644
--- a/tests/auc/auc_3g_test.c
+++ b/tests/auc/auc_3g_test.c
@@ -25,10 +25,66 @@
 #include <osmocom/core/utils.h>
 #include <osmocom/core/logging.h>
 
-#include "logging.h"
+#include <osmocom/crypt/auth.h>
 
-#define comment_start() fprintf(stderr, "===== %s\n", __func__);
+#include "logging.h"
+#include "auc.h"
+
+#define comment_start() fprintf(stderr, "\n===== %s\n", __func__);
 #define comment_end() fprintf(stderr, "===== %s: SUCCESS\n\n", __func__);
+
+#define VERBOSE_ASSERT(val, expect_op, fmt) \
+	do { \
+		fprintf(stderr, #val " == " fmt "\n", (val)); \
+		OSMO_ASSERT((val) expect_op); \
+	} while (0);
+
+const char *vec_str(const struct osmo_auth_vector *vec)
+{
+	static char buf[1024];
+	char *pos = buf;
+	char *end = buf + sizeof(buf);
+
+#define append(what) \
+	if (pos >= end) \
+		return buf; \
+	pos += snprintf(pos, sizeof(buf) - (pos - buf), \
+                        "  " #what ": %s\n", \
+			osmo_hexdump_nospc((void*)&vec->what, sizeof(vec->what)))
+
+	append(rand);
+	append(autn);
+	append(ck);
+	append(ik);
+	append(res);
+	append(res_len);
+	append(kc);
+	append(sres);
+	append(auth_types);
+#undef append
+
+	return buf;
+}
+
+#define VEC_IS(vec, expect) do { \
+		const char *_is = vec_str(vec); \
+		fprintf(stderr, "auth vector ==\n%s\n", _is); \
+	        if (strcmp(_is, expect)) { \
+			fprintf(stderr, "MISMATCH! expected ==\n%s\n", \
+				expect); \
+			char *a = _is; \
+			char *b = expect; \
+			for (; *a && *b; a++, b++) { \
+				if (*a != *b) { \
+					while (a > _is && *(a-1) != '\n') a--; \
+					fprintf(stderr, "mismatch at %d:\n" \
+						"%s", a - _is, a); \
+					break; \
+				} \
+			} \
+			OSMO_ASSERT(false); \
+		} \
+	} while (0)
 
 uint8_t fake_rand[16] = { 0 };
 
@@ -39,9 +95,213 @@
 	return len;
 }
 
+static void test_gen_vectors_2g_only(void)
+{
+	struct osmo_sub_auth_data aud2g;
+	struct osmo_sub_auth_data aud3g;
+	struct osmo_auth_vector vec;
+	int rc;
+
+	comment_start();
+
+	aud2g = (struct osmo_sub_auth_data){
+		.type = OSMO_AUTH_TYPE_GSM,
+		.algo = OSMO_AUTH_ALG_COMP128v1,
+	};
+
+	osmo_hexparse("EB215756028D60E3275E613320AEC880",
+		      aud2g.u.gsm.ki, sizeof(aud2g.u.gsm.ki));
+
+	aud3g = (struct osmo_sub_auth_data){ {0} };
+
+	osmo_hexparse("39fa2f4e3d523d8619a73b4f65c3e14d",
+		      fake_rand, sizeof(fake_rand));
+
+	vec = (struct osmo_auth_vector){ {0} };
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%d");
+	rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
+	VERBOSE_ASSERT(rc, == 1, "%d");
+
+	VEC_IS(&vec,
+	       "  rand: 39fa2f4e3d523d8619a73b4f65c3e14d\n"
+	       "  autn: 00000000000000000000000000000000\n"
+	       "  ck: 00000000000000000000000000000000\n"
+	       "  ik: 00000000000000000000000000000000\n"
+	       "  res: 00000000000000000000000000000000\n"
+	       "  res_len: 00\n"
+	       "  kc: 241a5b16aeb8e400\n"
+	       "  sres: 429d5b27\n"
+	       "  auth_types: 01000000\n"
+	      );
+
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%d");
+
+	/* even though vec is not zero-initialized, it should produce the same
+	 * result (regardless of the umts sequence nr) */
+	aud3g.u.umts.sqn = 123;
+	rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
+	VERBOSE_ASSERT(rc, == 1, "%d");
+
+	VEC_IS(&vec,
+	       "  rand: 39fa2f4e3d523d8619a73b4f65c3e14d\n"
+	       "  autn: 00000000000000000000000000000000\n"
+	       "  ck: 00000000000000000000000000000000\n"
+	       "  ik: 00000000000000000000000000000000\n"
+	       "  res: 00000000000000000000000000000000\n"
+	       "  res_len: 00\n"
+	       "  kc: 241a5b16aeb8e400\n"
+	       "  sres: 429d5b27\n"
+	       "  auth_types: 01000000\n"
+	      );
+
+	comment_end();
+}
+
+static void test_gen_vectors_2g_plus_3g(void)
+{
+	struct osmo_sub_auth_data aud2g;
+	struct osmo_sub_auth_data aud3g;
+	struct osmo_auth_vector vec;
+	int rc;
+
+	comment_start();
+
+	aud2g = (struct osmo_sub_auth_data){
+		.type = OSMO_AUTH_TYPE_GSM,
+		.algo = OSMO_AUTH_ALG_COMP128v1,
+	};
+
+	osmo_hexparse("EB215756028D60E3275E613320AEC880",
+		      aud2g.u.gsm.ki, sizeof(aud2g.u.gsm.ki));
+
+	aud3g = (struct osmo_sub_auth_data){
+		.type = OSMO_AUTH_TYPE_UMTS,
+		.algo = OSMO_AUTH_ALG_MILENAGE,
+	};
+
+	osmo_hexparse("EB215756028D60E3275E613320AEC880",
+		      aud3g.u.umts.k, sizeof(aud3g.u.umts.k));
+	osmo_hexparse("FB2A3D1B360F599ABAB99DB8669F8308",
+		      aud3g.u.umts.opc, sizeof(aud3g.u.umts.opc));
+
+	osmo_hexparse("39fa2f4e3d523d8619a73b4f65c3e14d",
+		      fake_rand, sizeof(fake_rand));
+
+	vec = (struct osmo_auth_vector){ {0} };
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%d");
+	rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
+	VERBOSE_ASSERT(rc, == 1, "%d");
+
+	VEC_IS(&vec,
+	       "  rand: 39fa2f4e3d523d8619a73b4f65c3e14d\n"
+	       "  autn: 8704f5ba55f30000d2ee44b22c8ea919\n"
+	       "  ck: f64735036e5871319c679f4742a75ea1\n"
+	       "  ik: 27497388b6cb044648f396aa155b95ef\n"
+	       "  res: e229c19e791f2e410000000000000000\n"
+	       "  res_len: 08\n"
+	       "  kc: 241a5b16aeb8e400\n"
+	       "  sres: 429d5b27\n"
+	       "  auth_types: 03000000\n"
+	      );
+
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 1, "%d");
+
+	/* even though vec is not zero-initialized, it should produce the same
+	 * result with the same sequence nr */
+	aud3g.u.umts.sqn = 0;
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%d");
+	rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
+	VERBOSE_ASSERT(rc, == 1, "%d");
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 1, "%d");
+
+	VEC_IS(&vec,
+	       "  rand: 39fa2f4e3d523d8619a73b4f65c3e14d\n"
+	       "  autn: 8704f5ba55f30000d2ee44b22c8ea919\n"
+	       "  ck: f64735036e5871319c679f4742a75ea1\n"
+	       "  ik: 27497388b6cb044648f396aa155b95ef\n"
+	       "  res: e229c19e791f2e410000000000000000\n"
+	       "  res_len: 08\n"
+	       "  kc: 241a5b16aeb8e400\n"
+	       "  sres: 429d5b27\n"
+	       "  auth_types: 03000000\n"
+	      );
+
+	comment_end();
+}
+
 static void test_gen_vectors_3g_only(void)
 {
+	struct osmo_sub_auth_data aud2g;
+	struct osmo_sub_auth_data aud3g;
+	struct osmo_auth_vector vec;
+	int rc;
+
 	comment_start();
+
+	aud2g = (struct osmo_sub_auth_data){ 0 };
+
+	aud3g = (struct osmo_sub_auth_data){
+		.type = OSMO_AUTH_TYPE_UMTS,
+		.algo = OSMO_AUTH_ALG_MILENAGE,
+	};
+
+	osmo_hexparse("EB215756028D60E3275E613320AEC880",
+		      aud3g.u.umts.k, sizeof(aud3g.u.umts.k));
+	osmo_hexparse("FB2A3D1B360F599ABAB99DB8669F8308",
+		      aud3g.u.umts.opc, sizeof(aud3g.u.umts.opc));
+
+	osmo_hexparse("39fa2f4e3d523d8619a73b4f65c3e14d",
+		      fake_rand, sizeof(fake_rand));
+
+	vec = (struct osmo_auth_vector){ {0} };
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%d");
+	rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
+	VERBOSE_ASSERT(rc, == 1, "%d");
+
+	VEC_IS(&vec,
+	       "  rand: 39fa2f4e3d523d8619a73b4f65c3e14d\n"
+	       "  autn: 8704f5ba55f30000d2ee44b22c8ea919\n"
+	       "  ck: f64735036e5871319c679f4742a75ea1\n"
+	       "  ik: 27497388b6cb044648f396aa155b95ef\n"
+	       "  res: e229c19e791f2e410000000000000000\n"
+	       "  res_len: 08\n"
+	       "  kc: 059a4f668f6fbe39\n"
+	       "  sres: 9b36efdf\n"
+	       "  auth_types: 03000000\n"
+	      );
+
+	/* Note: 3GPP TS 33.102 6.8.1.2: c3 function to get GSM auth is
+	 * KC[0..7] == CK[0..7] ^ CK[8..15] ^ IK[0..7] ^ IK[8..15]
+	 * In [16]: hex(  0xf64735036e587131
+	 *              ^ 0x9c679f4742a75ea1
+	 *              ^ 0x27497388b6cb0446
+	 *              ^ 0x48f396aa155b95ef)
+	 * Out[16]: '0x59a4f668f6fbe39L'
+	 * hence expecting kc: 059a4f668f6fbe39
+	 */
+
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 1, "%d");
+
+	/* even though vec is not zero-initialized, it should produce the same
+	 * result with the same sequence nr */
+	aud3g.u.umts.sqn = 0;
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 0, "%d");
+	rc = auc_compute_vectors(&vec, 1, &aud2g, &aud3g, NULL, NULL);
+	VERBOSE_ASSERT(rc, == 1, "%d");
+	VERBOSE_ASSERT(aud3g.u.umts.sqn, == 1, "%d");
+
+	VEC_IS(&vec,
+	       "  rand: 39fa2f4e3d523d8619a73b4f65c3e14d\n"
+	       "  autn: 8704f5ba55f30000d2ee44b22c8ea919\n"
+	       "  ck: f64735036e5871319c679f4742a75ea1\n"
+	       "  ik: 27497388b6cb044648f396aa155b95ef\n"
+	       "  res: e229c19e791f2e410000000000000000\n"
+	       "  res_len: 08\n"
+	       "  kc: 059a4f668f6fbe39\n"
+	       "  sres: 9b36efdf\n"
+	       "  auth_types: 03000000\n"
+	      );
+
 	comment_end();
 }
 
@@ -54,6 +314,8 @@
 	log_set_use_color(osmo_stderr_target, 0);
 	log_set_print_category(osmo_stderr_target, 1);
 
+	test_gen_vectors_2g_only();
+	test_gen_vectors_2g_plus_3g();
 	test_gen_vectors_3g_only();
 
 	printf("Done\n");
diff --git a/tests/auc/auc_3g_test.err b/tests/auc/auc_3g_test.err
index c29640a..ec5ba28 100644
--- a/tests/auc/auc_3g_test.err
+++ b/tests/auc/auc_3g_test.err
@@ -1,3 +1,106 @@
+
+===== test_gen_vectors_2g_only
+aud3g.u.umts.sqn == 0
+DAUC rand 39fa2f4e3d523d8619a73b4f65c3e14d
+DAUC compute vector [0]/1: 2G only
+rc == 1
+auth vector ==
+  rand: 39fa2f4e3d523d8619a73b4f65c3e14d
+  autn: 00000000000000000000000000000000
+  ck: 00000000000000000000000000000000
+  ik: 00000000000000000000000000000000
+  res: 00000000000000000000000000000000
+  res_len: 00
+  kc: 241a5b16aeb8e400
+  sres: 429d5b27
+  auth_types: 01000000
+
+aud3g.u.umts.sqn == 0
+DAUC rand 39fa2f4e3d523d8619a73b4f65c3e14d
+DAUC compute vector [0]/1: 2G only
+rc == 1
+auth vector ==
+  rand: 39fa2f4e3d523d8619a73b4f65c3e14d
+  autn: 00000000000000000000000000000000
+  ck: 00000000000000000000000000000000
+  ik: 00000000000000000000000000000000
+  res: 00000000000000000000000000000000
+  res_len: 00
+  kc: 241a5b16aeb8e400
+  sres: 429d5b27
+  auth_types: 01000000
+
+===== test_gen_vectors_2g_only: SUCCESS
+
+
+===== test_gen_vectors_2g_plus_3g
+aud3g.u.umts.sqn == 0
+DAUC rand 39fa2f4e3d523d8619a73b4f65c3e14d
+DAUC compute vector [0]/1: separate 2G + 3G
+rc == 1
+auth vector ==
+  rand: 39fa2f4e3d523d8619a73b4f65c3e14d
+  autn: 8704f5ba55f30000d2ee44b22c8ea919
+  ck: f64735036e5871319c679f4742a75ea1
+  ik: 27497388b6cb044648f396aa155b95ef
+  res: e229c19e791f2e410000000000000000
+  res_len: 08
+  kc: 241a5b16aeb8e400
+  sres: 429d5b27
+  auth_types: 03000000
+
+aud3g.u.umts.sqn == 1
+aud3g.u.umts.sqn == 0
+DAUC rand 39fa2f4e3d523d8619a73b4f65c3e14d
+DAUC compute vector [0]/1: separate 2G + 3G
+rc == 1
+aud3g.u.umts.sqn == 1
+auth vector ==
+  rand: 39fa2f4e3d523d8619a73b4f65c3e14d
+  autn: 8704f5ba55f30000d2ee44b22c8ea919
+  ck: f64735036e5871319c679f4742a75ea1
+  ik: 27497388b6cb044648f396aa155b95ef
+  res: e229c19e791f2e410000000000000000
+  res_len: 08
+  kc: 241a5b16aeb8e400
+  sres: 429d5b27
+  auth_types: 03000000
+
+===== test_gen_vectors_2g_plus_3g: SUCCESS
+
+
 ===== test_gen_vectors_3g_only
+aud3g.u.umts.sqn == 0
+DAUC rand 39fa2f4e3d523d8619a73b4f65c3e14d
+DAUC compute vector [0]/1: 3G only
+rc == 1
+auth vector ==
+  rand: 39fa2f4e3d523d8619a73b4f65c3e14d
+  autn: 8704f5ba55f30000d2ee44b22c8ea919
+  ck: f64735036e5871319c679f4742a75ea1
+  ik: 27497388b6cb044648f396aa155b95ef
+  res: e229c19e791f2e410000000000000000
+  res_len: 08
+  kc: 059a4f668f6fbe39
+  sres: 9b36efdf
+  auth_types: 03000000
+
+aud3g.u.umts.sqn == 1
+aud3g.u.umts.sqn == 0
+DAUC rand 39fa2f4e3d523d8619a73b4f65c3e14d
+DAUC compute vector [0]/1: 3G only
+rc == 1
+aud3g.u.umts.sqn == 1
+auth vector ==
+  rand: 39fa2f4e3d523d8619a73b4f65c3e14d
+  autn: 8704f5ba55f30000d2ee44b22c8ea919
+  ck: f64735036e5871319c679f4742a75ea1
+  ik: 27497388b6cb044648f396aa155b95ef
+  res: e229c19e791f2e410000000000000000
+  res_len: 08
+  kc: 059a4f668f6fbe39
+  sres: 9b36efdf
+  auth_types: 03000000
+
 ===== test_gen_vectors_3g_only: SUCCESS
 

-- 
To view, visit https://gerrit.osmocom.org/1720
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I291bccd62661ff5790dc43d91dc63a9e4b0e0ff2
Gerrit-PatchSet: 1
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list