mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-22 13:45:40 -05:00
DMR: Code Tweaks to Hytera OTA Encryption; #373
Enable Partial EMB LC CTX search if missing VLC header;
This commit is contained in:
@@ -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_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_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_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_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_ota_search_sb_rc(dsd_state * state, uint8_t * input, int ptype);
|
||||||
void hytera_create_lc_ctx(dsd_state * state, uint8_t * input);
|
void hytera_create_lc_ctx(dsd_state * state, uint8_t * input);
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ void vertex_40_keystream_creation(dsd_state * state, unsigned long long int key_
|
|||||||
//skip constant verbosity on keyloading
|
//skip constant verbosity on keyloading
|
||||||
#else
|
#else
|
||||||
fprintf (stderr,"Vertex RC4 Bytes: ");
|
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, "%02X ", rc4_bytes[i]);
|
||||||
fprintf (stderr, "Vertex Keystream: %016llX;", (unsigned long long int)vtx_key);
|
fprintf (stderr, "Vertex Keystream: %016llX;", (unsigned long long int)vtx_key);
|
||||||
fprintf (stderr, "\n");
|
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 is a search to len for the ctx for an unknown embedded ctx value
|
||||||
//This should not be run on live systems, but useful for replay or debug
|
//default len is 0xFFF (12-bit) to match common q0 == 0 or 1 + q1 11-bit full range
|
||||||
//This takes around 25 seconds on a full search and failure on Ryzen 5 2600
|
//full len is 0x3FFFFF (22-bit) to run full q0 and q1 values
|
||||||
void hytera_ota_search_emb_lc(dsd_state * state, uint8_t input[8][16])
|
//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
|
#ifdef DEBUG_HOTA
|
||||||
fprintf (stderr, "\n-----EMB LC and FEC CTX Search-----\n");
|
fprintf (stderr, "\n-----EMB LC and FEC CTX Search-----\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (uint32_t ctx = 0; ctx < 0x3FFFFF; ctx++)
|
for (uint32_t ctx = 0; ctx < len; ctx++)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t bits[128];
|
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)
|
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)
|
uint8_t hytera_ep_data_decrypt(dsd_opts * opts, dsd_state * state, uint8_t * input, int len)
|
||||||
|
|||||||
@@ -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++) */
|
} /* End for(i = 0; i < 16; i++) */
|
||||||
|
|
||||||
//Hytera OTA Encryption
|
//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)
|
// 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)
|
if (state->hota_key_loaded && state->hota_ctx_ok[slot] == 1)
|
||||||
hytera_ota_decrypt_emb_lc(state, BptcDataMatrix);
|
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
|
//just fill with all ones, would be garbage from FEC anyways
|
||||||
memset(LC_DataBit, 1, sizeof(LC_DataBit));
|
memset(LC_DataBit, 1, sizeof(LC_DataBit));
|
||||||
IrrecoverableErrors = 1;
|
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);
|
else IrrecoverableErrors = BPTC_128x77_Extract_Data(BptcDataMatrix, LC_DataBit);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user