diff --git a/include/dsd.h b/include/dsd.h index b917b43..09ad699 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -1713,7 +1713,7 @@ void ras_permute_order(uint32_t seed, int * order); void hytera_ota_keystream_setup(dsd_state * state, char * input); void hytera_ota_decrypt_bptc_96(dsd_state * state, uint8_t * input, uint8_t type); void hytera_ota_decrypt_emb_lc(dsd_state * state, uint8_t input[8][16]); -void hytera_ota_search_emb_lc(dsd_state * state, uint8_t input[8][16]); +void hytera_ota_search_emb_lc(dsd_state * state, uint8_t input[8][16], uint32_t len); void hytera_ota_decrypt_sb_rc(dsd_state * state, uint8_t * input); void hytera_ota_search_sb_rc(dsd_state * state, uint8_t * input, int ptype); void hytera_create_lc_ctx(dsd_state * state, uint8_t * input); diff --git a/src/crypt-rc4.c b/src/crypt-rc4.c index b1c8127..89fdad6 100644 --- a/src/crypt-rc4.c +++ b/src/crypt-rc4.c @@ -275,7 +275,7 @@ void vertex_40_keystream_creation(dsd_state * state, unsigned long long int key_ //skip constant verbosity on keyloading #else fprintf (stderr,"Vertex RC4 Bytes: "); - for (uint16_t i = 0; i < 8; i++) + for (uint16_t i = 0; i < 4; i++) fprintf (stderr, "%02X ", rc4_bytes[i]); fprintf (stderr, "Vertex Keystream: %016llX;", (unsigned long long int)vtx_key); fprintf (stderr, "\n"); @@ -853,17 +853,18 @@ void hytera_ota_decrypt_emb_lc(dsd_state * state, uint8_t input[8][16]) } -//This is a modified decrypt but to brute force an unknown 22-bit ctx value -//This should not be run on live systems, but useful for replay or debug -//This takes around 25 seconds on a full search and failure on Ryzen 5 2600 -void hytera_ota_search_emb_lc(dsd_state * state, uint8_t input[8][16]) +//This is a search to len for the ctx for an unknown embedded ctx value +//default len is 0xFFF (12-bit) to match common q0 == 0 or 1 + q1 11-bit full range +//full len is 0x3FFFFF (22-bit) to run full q0 and q1 values +//full len cannot run in real time, but the 12-bit search can +void hytera_ota_search_emb_lc(dsd_state * state, uint8_t input[8][16], uint32_t len) { #ifdef DEBUG_HOTA fprintf (stderr, "\n-----EMB LC and FEC CTX Search-----\n"); #endif - for (uint32_t ctx = 0; ctx < 0x3FFFFF; ctx++) + for (uint32_t ctx = 0; ctx < len; ctx++) { uint8_t bits[128]; @@ -1017,6 +1018,10 @@ void hytera_ota_search_emb_lc(dsd_state * state, uint8_t input[8][16]) } + #ifdef DEBUG_HOTA + fprintf (stderr, "-----EMB LC and FEC CTX Fail-------\n\n"); + #endif + } void hytera_ota_unit_testing(dsd_state * state) @@ -1339,6 +1344,10 @@ void hytera_ota_search_sb_rc(dsd_state * state, uint8_t * input, int ptype) } } + #ifdef DEBUG_HOTA + fprintf (stderr, "\n-----SB_RC KS Index Fail-------\n\n"); + #endif + } uint8_t hytera_ep_data_decrypt(dsd_opts * opts, dsd_state * state, uint8_t * input, int len) diff --git a/src/dmr_dburst.c b/src/dmr_dburst.c index 137d00d..013162b 100644 --- a/src/dmr_dburst.c +++ b/src/dmr_dburst.c @@ -491,8 +491,16 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 } /* End for(i = 0; i < 16; i++) */ //Hytera OTA Encryption + + //if the VLC CTX is missing, then run a partial search + if (state->hota_key_loaded && state->hota_ctx_ok[slot] == 0) + hytera_ota_search_emb_lc(state, BptcDataMatrix, 0xFFF); + + //full search cannot run in real time, but is available as debug // if (state->hota_key_loaded && state->hota_ctx_ok[slot] == 0) - // hytera_ota_search_emb_lc(state, BptcDataMatrix); //only run as a debug option + // hytera_ota_search_emb_lc(state, BptcDataMatrix, 0x3FFFFF); + + //Decrypt if a good CTX value is available if (state->hota_key_loaded && state->hota_ctx_ok[slot] == 1) hytera_ota_decrypt_emb_lc(state, BptcDataMatrix); @@ -508,14 +516,6 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 //just fill with all ones, would be garbage from FEC anyways memset(LC_DataBit, 1, sizeof(LC_DataBit)); IrrecoverableErrors = 1; - - //TODO: columns instead of rows to match application of keystream - #ifdef DEBUG_HOTA - fprintf(stderr, "\n BPTC 128: "); - for (int i = 0; i < 8; i++) - fprintf (stderr, "%04X", (uint16_t)convert_bits_into_output(BptcDataMatrix[i], 16)); - fprintf (stderr, "\n"); - #endif } else IrrecoverableErrors = BPTC_128x77_Extract_Data(BptcDataMatrix, LC_DataBit);