DMR: Fix DES Alg (0x22) Set;

Fix Late Entry Mismatch Bug due to variable type change (int to ulli);

More Fixes Tweaks for Hytera Enhanced Encryption Setup;
This commit is contained in:
lwvmobile
2025-04-04 17:35:48 -04:00
parent 425d477168
commit 3312e14422
5 changed files with 35 additions and 22 deletions

View File

@@ -63,6 +63,11 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
sprintf (state->dmr_branding_sub, "XPT ");
}
//bug fix for Hytera Enhanced link control (go by the checksum in the message)
//a good checksum will set IrrecoverableErrors back to zero
if (fid == 0x68 && flco == 0x02 && *IrrecoverableErrors == 0)
*IrrecoverableErrors = 1;
//look at the dmr_branding_sub for the XPT string
//branding sub is set at CSBK(68-3A and 3B), SLCO 8, and here on 0x09
if (strcmp (state->dmr_branding_sub, "XPT ") == 0) is_xpt = 1;
@@ -307,7 +312,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
unsigned long long int mi = (unsigned long long int)ConvertBitIntoBytes(&lc_bits[24], 40);
fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Slot %d Alg: %02X; KEY ID: %02X; MI(40): %010llX;", slot+1, alg, key, mi);
fprintf (stderr, " Hytera Enhanced");
fprintf (stderr, " Hytera Enhanced;");
for (int i = 0; i < 8; i++)
{

View File

@@ -90,7 +90,7 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
}
}
int mi_final = 0;
unsigned long long int mi_final = 0;
mi_final = (mi_corrected >> 4) & 0xFFFFFFFF;
mi_crc_ext = (uint8_t)ConvertBitIntoBytes(&mi_bits[32], 4);
@@ -108,7 +108,7 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
if (state->payload_mi != mi_final)
{
fprintf (stderr, "%s", KCYN);
fprintf (stderr, " Slot 1 PI/LFSR and Late Entry MI Mismatch - %08X : %08X ", state->payload_mi, mi_final);
fprintf (stderr, " Slot 1 PI/LFSR and Late Entry MI Mismatch - %08llX : %08llX ", state->payload_mi, mi_final);
if (mi_crc_ok == 1) state->payload_mi = mi_final;
if (mi_crc_ok == 1) fprintf (stderr, "(CRC OK)");
else fprintf (stderr, "(CRC ERR)");
@@ -138,7 +138,7 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
if (state->payload_miR != mi_final)
{
fprintf (stderr, "%s", KCYN);
fprintf (stderr, " Slot 2 PI/LFSR and Late Entry MI Mismatch - %08X : %08X ", state->payload_miR, mi_final);
fprintf (stderr, " Slot 2 PI/LFSR and Late Entry MI Mismatch - %08llX : %08llX ", state->payload_miR, mi_final);
if (mi_crc_ok == 1) state->payload_miR = mi_final;
if (mi_crc_ok == 1) fprintf (stderr, "(CRC OK)");
else fprintf (stderr, "(CRC ERR)");

View File

@@ -48,9 +48,9 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC
fprintf (stderr, " DMR PI H- ALG ID: %02X; KEY ID: %02X; MI(40): %02X%02X%02X%02X%02X;",
PI_BYTE[0], PI_BYTE[2], PI_BYTE[3], PI_BYTE[4], PI_BYTE[5], PI_BYTE[6], PI_BYTE[7]);
//PI_BYTE[8] is a checksum of the other bytes combined and should be equal to zero
//PI_BYTE[9] is a checksum of the other bytes combined
uint8_t checksum = 0;
for (int i = 0; i < 10; i++)
for (int i = 0; i < 9; i++)
{
checksum += PI_BYTE[i];
checksum &= 0xFF;
@@ -59,15 +59,11 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC
checksum++;
//debug
// fprintf (stderr, " CHK: %02X / %02X;", checksum, PI_BYTE[8]);
// fprintf (stderr, " CHK: %02X / %02X;", checksum, PI_BYTE[9]);
if (checksum == PI_BYTE[8])
if (checksum == PI_BYTE[9])
{
fprintf (stderr, " Hytera Enhanced");
if (PI_BYTE[2] == 0x02)
fprintf (stderr, " RC4;");
else if (PI_BYTE[2] == 0x05)
fprintf (stderr, " AES-256;");
fprintf (stderr, " Hytera Enhanced;");
//disable late entry for DMRA (hopefully, there aren't any systems running both DMRA and Hytera Enhanced mixed together)
opts->dmr_le = 2;
@@ -113,7 +109,7 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC
else if ((state->payload_algid & 0x07) == 0x02)
{
fprintf (stderr, " DES;");
state->payload_algid = 0x21;
state->payload_algid = 0x22;
}
else if ((state->payload_algid & 0x07) == 0x04)
@@ -180,7 +176,7 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC
else if ((state->payload_algidR & 0x07) == 0x02)
{
fprintf (stderr, " DES;");
state->payload_algidR = 0x21;
state->payload_algidR = 0x22;
}
else if ((state->payload_algidR & 0x07) == 0x04)

View File

@@ -93,7 +93,7 @@ void playSynthesizedVoiceFS3 (dsd_opts * opts, dsd_state * state)
encL = 0;
}
}
else if (state->payload_algid == 0x21 || state->payload_algid == 0x22)
else if (state->payload_algid == 0x02 || state->payload_algid == 0x21 || state->payload_algid == 0x22)
{
if (state->R != 0)
{
@@ -119,7 +119,7 @@ void playSynthesizedVoiceFS3 (dsd_opts * opts, dsd_state * state)
encR = 0;
}
}
else if (state->payload_algidR == 0x21 || state->payload_algidR == 0x22)
else if (state->payload_algidR == 0x02 ||state->payload_algidR == 0x21 || state->payload_algidR == 0x22)
{
if (state->RR != 0)
{
@@ -1098,7 +1098,7 @@ void playSynthesizedVoiceSS3 (dsd_opts * opts, dsd_state * state)
encR = 0;
}
}
else if (state->payload_algid == 0x02 ||state->payload_algidR == 0x21 || state->payload_algidR == 0x22)
else if (state->payload_algidR == 0x02 ||state->payload_algidR == 0x21 || state->payload_algidR == 0x22)
{
if (state->RR != 0)
{

View File

@@ -742,7 +742,8 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
if ( (state->currentslot == 0 && state->payload_algid == 0x24 && state->aes_key_loaded[0] == 1 ) || //DMR AES128
(state->currentslot == 0 && state->payload_algid == 0x25 && state->aes_key_loaded[0] == 1 ) || //DMR AES256
(state->currentslot == 0 && state->payload_algid == 0x89 && state->aes_key_loaded[0] == 1 ) || //P25 AES128
(state->currentslot == 0 && state->payload_algid == 0x84 && state->aes_key_loaded[0] == 1) ) //P25 AES256
(state->currentslot == 0 && state->payload_algid == 0x84 && state->aes_key_loaded[0] == 1 ) || //P25 AES256
(state->currentslot == 0 && state->payload_algid == 0x02 && state->R != 0 ) ) //HYT ENHANCED
{
int j; int z = 0; int n = 16; uint8_t b = 0; //n=16 for AES-OFB discard round
@@ -771,8 +772,13 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
aes_ofb_keystream_output (state->aes_iv, aes_key, state->ks_octetL, 0, 10); //9 + 1 discard round
if(state->payload_algid == 0x25 || state->payload_algid == 0x84) //AES256
aes_ofb_keystream_output (state->aes_iv, aes_key, state->ks_octetL, 2, 10); //9 + 1 discard round
if(state->payload_algid == 0x02)
{
n = 0;
hytera_enhanced_enc_setup(opts, state, state->R, state->payload_mi);
}
//Load Keystream Octet Bytes directly into keystream array
//Load Keystream Octet Bytes directly into keystream array //TODO: Convert to unpack function
for (i = 0; i < 9 * 16; i++) //9 rounds at 16 octets
{
for (j = 0; j < 8; j++)
@@ -1113,7 +1119,8 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
if ( (state->currentslot == 1 && state->payload_algidR == 0x24 && state->aes_key_loaded[1] == 1 ) || //DMR AES128
(state->currentslot == 1 && state->payload_algidR == 0x25 && state->aes_key_loaded[1] == 1 ) || //DMR AES256
(state->currentslot == 1 && state->payload_algidR == 0x89 && state->aes_key_loaded[1] == 1 ) || //P25 AES128
(state->currentslot == 1 && state->payload_algidR == 0x84 && state->aes_key_loaded[1] == 1) ) //P25 AES256
(state->currentslot == 1 && state->payload_algidR == 0x84 && state->aes_key_loaded[1] == 1 ) || //P25 AES256
(state->currentslot == 1 && state->payload_algidR == 0x02 && state->RR != 0 ) ) //HYT ENHANCED
{
int j; int z = 0; int n = 16; uint8_t b = 0; //n=16 for AES-OFB discard round
@@ -1142,9 +1149,14 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
aes_ofb_keystream_output (state->aes_ivR, aes_key, state->ks_octetR, 0, 10); //9 + 1 discard round
if (state->payload_algidR == 0x25 || state->payload_algidR == 0x84)
aes_ofb_keystream_output (state->aes_ivR, aes_key, state->ks_octetR, 2, 10); //9 + 1 discard round
if(state->payload_algidR == 0x02)
{
n = 0;
hytera_enhanced_enc_setup(opts, state, state->RR, state->payload_miR);
}
//Load Keystream Octet Bytes directly into keystream array
for (i = 0; i < 9 * 16; i++) //9 rounds at 16 octets
for (i = 0; i < 9 * 16; i++) //9 rounds at 16 octets //TODO: Convert to unpack function
{
for (j = 0; j < 8; j++)
{