mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-16 10:47:21 -05:00
DMR: Add Support for Callta BP 10/32/64; #360
DMR: Add optional discard value to -S straight_xor keystream application;
This commit is contained in:
146
src/dsd_mbe.c
146
src/dsd_mbe.c
@@ -640,72 +640,87 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
|
||||
opts->dmr_mute_encL = 0; //shim to unmute
|
||||
}
|
||||
|
||||
//Hytera BP //TODO: Clean this mess up
|
||||
if ( (state->K1 > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x68) ||
|
||||
(state->K1 > 0 && state->forced_alg_id == 1) )
|
||||
{
|
||||
|
||||
int pos = 0;
|
||||
int pos = 0;
|
||||
|
||||
unsigned long long int k1 = state->K1;
|
||||
unsigned long long int k2 = state->K2;
|
||||
unsigned long long int k3 = state->K3;
|
||||
unsigned long long int k4 = state->K4;
|
||||
unsigned long long int k1 = state->K1;
|
||||
unsigned long long int k2 = state->K2;
|
||||
unsigned long long int k3 = state->K3;
|
||||
unsigned long long int k4 = state->K4;
|
||||
|
||||
int T_Key[256] = {0};
|
||||
int pN[882] = {0};
|
||||
int T_Key[256] = {0};
|
||||
int pN[882] = {0};
|
||||
|
||||
int len = 0;
|
||||
int len = 0;
|
||||
|
||||
if (k2 == 0)
|
||||
{
|
||||
len = 39;
|
||||
k1 = k1 << 24;
|
||||
}
|
||||
if (k2 != 0)
|
||||
{
|
||||
len = 127;
|
||||
}
|
||||
if (k4 != 0)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
for (i = 0; i < 64; i++)
|
||||
{
|
||||
T_Key[i] = ( ((k1 << i) & 0x8000000000000000) >> 63 );
|
||||
T_Key[i+64] = ( ((k2 << i) & 0x8000000000000000) >> 63 );
|
||||
T_Key[i+128] = ( ((k3 << i) & 0x8000000000000000) >> 63 );
|
||||
T_Key[i+192] = ( ((k4 << i) & 0x8000000000000000) >> 63 );
|
||||
}
|
||||
|
||||
for (i = 0; i < 882; i++)
|
||||
{
|
||||
pN[i] = T_Key[pos];
|
||||
pos++;
|
||||
if (pos > len)
|
||||
if (k2 == 0)
|
||||
{
|
||||
pos = 0;
|
||||
len = 39;
|
||||
k1 = k1 << 24;
|
||||
}
|
||||
}
|
||||
|
||||
//sanity check
|
||||
if (state->DMRvcL > 17) //18
|
||||
{
|
||||
state->DMRvcL = 17; //18
|
||||
}
|
||||
|
||||
pos = state->DMRvcL * 49;
|
||||
if (memcmp(ambe_d, ambe_silence, 49) == 0)
|
||||
pos += 49;
|
||||
else
|
||||
{
|
||||
for(i = 0; i < 49; i++)
|
||||
if (k2 != 0)
|
||||
{
|
||||
ambe_d[i] ^= pN[pos];
|
||||
len = 127;
|
||||
}
|
||||
if (k4 != 0)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
for (i = 0; i < 64; i++)
|
||||
{
|
||||
T_Key[i] = ( ((k1 << i) & 0x8000000000000000) >> 63 );
|
||||
T_Key[i+64] = ( ((k2 << i) & 0x8000000000000000) >> 63 );
|
||||
T_Key[i+128] = ( ((k3 << i) & 0x8000000000000000) >> 63 );
|
||||
T_Key[i+192] = ( ((k4 << i) & 0x8000000000000000) >> 63 );
|
||||
}
|
||||
|
||||
for (i = 0; i < 882; i++)
|
||||
{
|
||||
pN[i] = T_Key[pos];
|
||||
pos++;
|
||||
if (pos > len)
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//sanity check
|
||||
if (state->DMRvcL > 17) //18
|
||||
{
|
||||
state->DMRvcL = 17; //18
|
||||
}
|
||||
|
||||
pos = state->DMRvcL * 49;
|
||||
if (memcmp(ambe_d, ambe_silence, 49) == 0)
|
||||
pos += 49;
|
||||
else
|
||||
{
|
||||
for(i = 0; i < 49; i++)
|
||||
{
|
||||
ambe_d[i] ^= pN[pos];
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
state->DMRvcL++;
|
||||
}
|
||||
state->DMRvcL++;
|
||||
|
||||
//Caltta BP
|
||||
if ( (state->straight_ks == 0x26 && state->dmr_so & 0x40 && state->payload_algid == 0x26) || //&& state->payload_keyid != 0
|
||||
(state->straight_ks == 0x26 && state->forced_alg_id == 0x26) )
|
||||
{
|
||||
if (memcmp(ambe_d, ambe_silence, 49) == 0)
|
||||
state->static_ks_counter[state->currentslot] += 56;
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 49; i++)
|
||||
ambe_d[i] ^= (uint8_t)(state->static_ks_bits[state->currentslot][(state->static_ks_counter[state->currentslot]++)%state->straight_mod] & 1); //Yikes!
|
||||
state->static_ks_counter[state->currentslot] += 7;
|
||||
}
|
||||
}
|
||||
|
||||
//DMR and P25p2 DES-OFB 56 Handling, Slot 1, VCH 0 -- consider moving into the AES handler
|
||||
@@ -1037,6 +1052,9 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
|
||||
state->payload_algid = 0;
|
||||
for (int i = 0; i < 49; i++)
|
||||
ambe_d[i] ^= (uint8_t)(state->static_ks_bits[state->currentslot][(state->static_ks_counter[state->currentslot]++)%state->straight_mod] & 1); //Yikes!
|
||||
//apply optional discard (i.e., caltta bp)
|
||||
if (state->straight_discard != 0)
|
||||
state->static_ks_counter[state->currentslot] += state->straight_discard;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1128,6 +1146,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
|
||||
opts->dmr_mute_encR = 0; //shim to unmute
|
||||
}
|
||||
|
||||
//Hytera BP //TODO: Clean this mess up
|
||||
if ( (state->K1 > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x68) ||
|
||||
(state->K1 > 0 && state->forced_alg_id == 1))
|
||||
{
|
||||
@@ -1196,6 +1215,20 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
|
||||
state->DMRvcR++;
|
||||
}
|
||||
|
||||
//Caltta BP
|
||||
if ( (state->straight_ks == 0x26 && state->dmr_soR & 0x40 && state->payload_algidR == 0x26) || //&& state->payload_keyidR != 0
|
||||
(state->straight_ks == 0x26 && state->forced_alg_id == 0x26) )
|
||||
{
|
||||
if (memcmp(ambe_d, ambe_silence, 49) == 0)
|
||||
state->static_ks_counter[state->currentslot] += 56;
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 49; i++)
|
||||
ambe_d[i] ^= (uint8_t)(state->static_ks_bits[state->currentslot][(state->static_ks_counter[state->currentslot]++)%state->straight_mod] & 1); //Yikes!
|
||||
state->static_ks_counter[state->currentslot] += 7;
|
||||
}
|
||||
}
|
||||
|
||||
//DMR and P25p2 DES-OFB 56 Handling, Slot 2, VCH 1 -- Consider moving into AES handler
|
||||
if ( (state->currentslot == 1 && state->payload_algidR == 0x22 && state->RR != 0) ||
|
||||
(state->currentslot == 1 && state->payload_algidR == 0x81 && state->RR != 0) )
|
||||
@@ -1524,6 +1557,9 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
|
||||
state->payload_algidR = 0;
|
||||
for (int i = 0; i < 49; i++)
|
||||
ambe_d[i] ^= (uint8_t)(state->static_ks_bits[state->currentslot][(state->static_ks_counter[state->currentslot]++)%state->straight_mod] & 1); //Yikes!
|
||||
//apply optional discard (i.e., caltta bp)
|
||||
if (state->straight_discard != 0)
|
||||
state->static_ks_counter[state->currentslot] += state->straight_discard;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1580,6 +1616,9 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
|
||||
if (state->ken_sc == 1)
|
||||
state->dmr_encL = 0;
|
||||
|
||||
if (state->payload_algid == 0x26 && state->straight_ks == 0x26)
|
||||
state->dmr_encL = 0;
|
||||
|
||||
//reverse mute testing, only mute unencrypted traffic (slave piggyback dsd+ method)
|
||||
if (opts->reverse_mute == 1)
|
||||
{
|
||||
@@ -1660,6 +1699,9 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
|
||||
if (state->ken_sc == 1)
|
||||
state->dmr_encR = 0;
|
||||
|
||||
if (state->payload_algidR == 0x26 && state->straight_ks == 0x26)
|
||||
state->dmr_encR = 0;
|
||||
|
||||
//reverse mute testing, only mute unencrypted traffic (slave piggyback dsd+ method)
|
||||
if (opts->reverse_mute == 1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user