FreeCalypso > hg > fc-sim-tools
changeset 82:28fae57b3e29
fcsim1-mkprov: add OTA_C and OTA_D key generation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 10 Apr 2021 23:21:47 +0000 |
parents | 8c23d2a9c013 |
children | 3055d5c9e7a3 |
files | utils/fcsim1-mkprov.c |
diffstat | 1 files changed, 26 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/utils/fcsim1-mkprov.c Fri Apr 09 08:35:54 2021 +0000 +++ b/utils/fcsim1-mkprov.c Sat Apr 10 23:21:47 2021 +0000 @@ -93,8 +93,23 @@ set_imsi(argv[optind+1]); } +static unsigned +make_odd_parity(byte) + unsigned byte; +{ + unsigned mask, p; + + p = 0; + for (mask = 0x80; mask; mask >>= 1) + if (byte & mask) + p = !p; + if (!p) + byte ^= 0x01; + return byte; +} + static void -get_random_ki(strbuf) +get_random_key(strbuf, oddpar) char *strbuf; { u_char bin[16]; @@ -107,6 +122,10 @@ fprintf(stderr, "error reading from %s\n", random_file); exit(1); } + if (oddpar) { + for (n = 0; n < 16; n++) + bin[n] = make_odd_parity(bin[n]); + } dp = strbuf; for (n = 0; n < 16; n++) { sprintf(dp, "%02X", bin[n]); @@ -120,14 +139,16 @@ { unsigned acc_mask; char iccid_str[20], imsi_str[16], ki_str[33]; - char msisdn_str[21]; + char msisdn_str[21], otac_str[33], otad_str[33]; nibbles_to_ascii(iccid_bin, 19, iccid_str); nibbles_to_ascii(imsi_bin, 15, imsi_str); acc_mask = 1 << access_class; - get_random_ki(ki_str); - printf("ICCID=%s IMSI=%s ACC=%04X Ki=%s", iccid_str, imsi_str, - acc_mask, ki_str); + get_random_key(ki_str, 0); + get_random_key(otac_str, 1); + get_random_key(otad_str, 1); + printf("ICCID=%s IMSI=%s ACC=%04X Ki=%s OTA_C=%s OTA_D=%s", iccid_str, + imsi_str, acc_mask, ki_str, otac_str, otad_str); if (msisdn_set) { fputs(" MSISDN=", stdout); if (msisdn_plus)