mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-22 13:45:40 -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:
122
src/crypt-etc.c
122
src/crypt-etc.c
@@ -93,6 +93,9 @@ void straight_mod_xor_keystream_creation(dsd_state * state, char * input)
|
||||
}
|
||||
else goto END_KS;
|
||||
|
||||
//debug
|
||||
// fprintf (stderr, "\ncurr: %s\n", curr);
|
||||
|
||||
uint8_t ks_bytes[112];
|
||||
memset (ks_bytes, 0, sizeof(ks_bytes));
|
||||
parse_raw_user_string(curr, ks_bytes);
|
||||
@@ -123,6 +126,125 @@ void straight_mod_xor_keystream_creation(dsd_state * state, char * input)
|
||||
|
||||
if (curr == NULL)
|
||||
fprintf (stderr, "Straight KS String Malformed! No KS Created!\n");
|
||||
else
|
||||
{
|
||||
curr = strtok(NULL, ":"); //optional discard value
|
||||
if (curr != NULL)
|
||||
{
|
||||
len = 0;
|
||||
sscanf (curr, "%hd", &len);
|
||||
if (len != 0 && len < 8)
|
||||
{
|
||||
state->straight_discard = (int)len;
|
||||
fprintf (stderr, "Optional Straight XOR Keystream Discard: %d; \n", len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void caltta_bp_keystream_creation(dsd_state * state, char * input)
|
||||
{
|
||||
uint16_t len = 0;
|
||||
char * curr;
|
||||
curr = strtok(input, ":"); //should be len (mod) of key (decimal)
|
||||
if (curr != NULL)
|
||||
sscanf (curr, "%hd", &len);
|
||||
else goto END_KS;
|
||||
|
||||
//len sanity check, can't be greater than 882
|
||||
if (len > 256)
|
||||
len = 256;
|
||||
|
||||
curr = strtok(NULL, ":"); //should be key in hex
|
||||
if (curr != NULL)
|
||||
{
|
||||
//continue
|
||||
}
|
||||
else goto END_KS;
|
||||
|
||||
uint8_t ks_bytes[112];
|
||||
memset (ks_bytes, 0, sizeof(ks_bytes));
|
||||
parse_raw_user_string(curr, ks_bytes);
|
||||
|
||||
uint8_t ks_bits[896];
|
||||
memset(ks_bits, 0, sizeof(ks_bits));
|
||||
|
||||
uint16_t unpack_len = len / 8;
|
||||
if (len % 8)
|
||||
unpack_len++;
|
||||
unpack_byte_array_into_bit_array(ks_bytes, ks_bits, unpack_len);
|
||||
|
||||
for (uint16_t i = 0; i < len; i++)
|
||||
{
|
||||
state->static_ks_bits[0][i] = ks_bits[i];
|
||||
state->static_ks_bits[1][i] = ks_bits[i];
|
||||
}
|
||||
|
||||
fprintf (stderr,"Caltta BP %d-bit Keystream: ", len);
|
||||
for (uint16_t i = 0; i < unpack_len; i++)
|
||||
fprintf (stderr, "%02X", ks_bytes[i]);
|
||||
fprintf (stderr, "\n");
|
||||
|
||||
state->straight_ks = 0x26;
|
||||
state->straight_mod = (int)len;
|
||||
|
||||
END_KS:
|
||||
|
||||
if (curr == NULL)
|
||||
fprintf (stderr, "Caltta BP KS String Malformed! No KS Created!\n");
|
||||
|
||||
}
|
||||
|
||||
void hytera_bp_keystream_creation(dsd_state * state, char * input)
|
||||
{
|
||||
uint16_t len = 0;
|
||||
char * curr;
|
||||
curr = strtok(input, ":"); //should be len (mod) of key (decimal)
|
||||
if (curr != NULL)
|
||||
sscanf (curr, "%hd", &len);
|
||||
else goto END_KS;
|
||||
|
||||
//len sanity check, can't be greater than 882
|
||||
if (len > 256)
|
||||
len = 256;
|
||||
|
||||
curr = strtok(NULL, ":"); //should be key in hex
|
||||
if (curr != NULL)
|
||||
{
|
||||
//continue
|
||||
}
|
||||
else goto END_KS;
|
||||
|
||||
uint8_t ks_bytes[112];
|
||||
memset (ks_bytes, 0, sizeof(ks_bytes));
|
||||
parse_raw_user_string(curr, ks_bytes);
|
||||
|
||||
uint8_t ks_bits[896];
|
||||
memset(ks_bits, 0, sizeof(ks_bits));
|
||||
|
||||
uint16_t unpack_len = len / 8;
|
||||
if (len % 8)
|
||||
unpack_len++;
|
||||
unpack_byte_array_into_bit_array(ks_bytes, ks_bits, unpack_len);
|
||||
|
||||
for (uint16_t i = 0; i < len; i++)
|
||||
{
|
||||
state->static_ks_bits[0][i] = ks_bits[i];
|
||||
state->static_ks_bits[1][i] = ks_bits[i];
|
||||
}
|
||||
|
||||
fprintf (stderr,"Hytera BP %d-bit Keystream: ", len);
|
||||
for (uint16_t i = 0; i < unpack_len; i++)
|
||||
fprintf (stderr, "%02X", ks_bytes[i]);
|
||||
|
||||
state->straight_ks = 0x68;
|
||||
state->straight_mod = (int)len;
|
||||
|
||||
END_KS:
|
||||
|
||||
if (curr == NULL)
|
||||
fprintf (stderr, "Hytera BP KS String Malformed! No KS Created!\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user