test_secu_knas.c 4.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22 23 24 25 26 27 28 29 30 31 32 33 34
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>

#include "test_util.h"

#include "secu_defs.h"

static
void derive_knas_keys(algorithm_type_dist_t atd, uint8_t *kasme, unsigned length,
                      uint8_t *knas_enc_exp, uint8_t *knas_int_exp)
{
gauthier's avatar
gauthier committed
35 36
  uint8_t *knas_enc = NULL;
  uint8_t *knas_int = NULL;
37

gauthier's avatar
gauthier committed
38 39 40 41 42
  knas_enc = calloc(1, 32);
  knas_int = calloc(1, 32);

  derive_key_nas_enc(atd, kasme, knas_enc);
  derive_key_nas_int(atd, kasme, knas_int);
43

44
  /* Compare both keys with expected */
gauthier's avatar
gauthier committed
45
  if (compare_buffer(knas_enc, 16, &knas_enc_exp[16], 16) != 0) {
46 47
    fail("Fail: knas_enc derivation\n");
  }
48

gauthier's avatar
gauthier committed
49
  if (compare_buffer(knas_int, 16, &knas_int_exp[16], 16) != 0) {
50 51 52 53
    fail("Fail: knas_int derivation\n");
  }
  free(knas_enc);
  free(knas_int);
54 55 56 57
}

void doit(void)
{
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  derive_knas_keys(EIA0_ALG_ID,
                   HL("70D7071AA016A087F9D888AD51F3A83E2C83443AB27843B35BD1B4923615091C"),
                   H("64BA839B29C451085C552F4DE9D278B263CB5BDD7FC21A38120637B2A9E5CD39"),
                   H("A66A2D198AF2A8D6A5FF2FAA51676037DF204187C61EDD3AAA70F3B7D8B59E8B"));
  derive_knas_keys(EIA1_128_ALG_ID,
                   HL("70D7071AA016A087F9D888AD51F3A83E2C83443AB27843B35BD1B4923615091C"),
                   H("DF8FEBA477891617C42FB16F750E572C9E59ED7564879150F6BB0DAEF5932E89"),
                   H("EA1158BA3F387BC96C967BC32FB43F65AE172A3267343479CAA826034A90A250"));
  derive_knas_keys(EIA2_128_ALG_ID,
                   HL("70D7071AA016A087F9D888AD51F3A83E2C83443AB27843B35BD1B4923615091C"),
                   H("99D63BD2D43AF81EBB7599F7E8F8B3E81CF7897F31D6270C19C4836070FE11F0"),
                   H("FC7A3850D19AE29EC7000B9DF98787F11A4329FD23FD3A93C9D2D92D853EC9DB"));
  derive_knas_keys(EIA0_ALG_ID,
                   HL("9EA141DA4B24CDEBC8F5FB3F61A0511216681F121199B23EBCFACC75B358BE43"),
                   H("1E48E1B5EDF98DEDF339DE686544AA1088C8E5616EDB706201837AA106D37691"),
                   H("C83DC420F97AA42D1B8488FA5D8F74865D833416D5851556100B41FEC8E38139"));
  derive_knas_keys(EIA1_128_ALG_ID,
                   HL("9EA141DA4B24CDEBC8F5FB3F61A0511216681F121199B23EBCFACC75B358BE43"),
                   H("207700CD92B4635B439E40176F92F7ADA824B9D699ABE15F86F3346C25343A33"),
                   H("FAA39E382611CDFED52042E72AF8CECDF92CCD799141857B77B6901741E486B2"));
  derive_knas_keys(EIA2_128_ALG_ID,
                   HL("9EA141DA4B24CDEBC8F5FB3F61A0511216681F121199B23EBCFACC75B358BE43"),
                   H("2A6854D25282FFD738FA8BBCFDCE853C0C4DFB9F559DCBB71D5120DB2CAC66A6"),
                   H("5EDCAE62A35BC42399C55F64ECAE7B17524BED1ED1601218D2772E55DDFAD959"));
  derive_knas_keys(EIA0_ALG_ID,
                   HL("546A79BC6D1613A72A4D631EE0351D66036B2A0C44A3831BE6D365E24F023013"),
                   H("7F684F909A5910DED6E4B4CE02AC92DF4690EB3788068600E9CB2C3EF8F0956E"),
                   H("51F3B142D357371726873FAC5E853CE0EEEFC52A695DE45FA6F4A23D20C13155"));
  derive_knas_keys(EIA1_128_ALG_ID,
                   HL("546A79BC6D1613A72A4D631EE0351D66036B2A0C44A3831BE6D365E24F023013"),
                   H("B6B222E9C07C56D15176C8E95EC1805561492682E4B9CD7228237A6C78702347"),
                   H("4DC5ABF6896DA460473288D16DE83C480388C6FD9E803C7EA88090F311354A15"));
  derive_knas_keys(EIA2_128_ALG_ID,
                   HL("546A79BC6D1613A72A4D631EE0351D66036B2A0C44A3831BE6D365E24F023013"),
                   H("7BD2A0864452D3D9EDE3B2E38A9958777F231AC4F4B9AF3FC8CE0E1EAAB425A7"),
                   H("89E8049EBE9374F238B0F3278EEA47D9BF8877111D99D6378FFF66FEBB06F3F8"));
94
}