mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-17 03:07:24 -05:00
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "dsd.h"
|
||||
#include "dmr_const.h"
|
||||
#include "pc4.h"
|
||||
|
||||
//interleaved code words for AMBE+2
|
||||
//interleaved code words for AMBE+2 (as it arrives over the air)
|
||||
void ambe2_codeword_print_i (dsd_opts * opts, char ambe_fr[4][24])
|
||||
{
|
||||
uint8_t interleaved[72];
|
||||
@@ -94,8 +95,8 @@ void ambe2_codeword_print_f (dsd_opts * opts, char ambe_fr[4][24])
|
||||
|
||||
}
|
||||
|
||||
//tested working perfectly fine on some Tytera BP samples, but not on others
|
||||
//is there two or more different Tytera (or CCR) BP modes depending on FW?
|
||||
//NOTE: This mode DOES NOT work over a repeater, simplex only
|
||||
//repeaters may or will attempt to correct the frame errors
|
||||
void tyt16_ambe2_codeword_keystream(dsd_state * state, char ambe_fr[4][24], int fnum)
|
||||
{
|
||||
|
||||
@@ -154,4 +155,87 @@ void tyt16_ambe2_codeword_keystream(dsd_state * state, char ambe_fr[4][24], int
|
||||
z++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void tyt_ap_pc4_keystream_creation(dsd_state * state, char * input)
|
||||
{
|
||||
unsigned char key1[16] = {0};
|
||||
unsigned char key2[16] = {0};
|
||||
|
||||
char buf[1024];
|
||||
strncpy(buf, input, sizeof(buf) - 1);
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
|
||||
char *pEnd;
|
||||
uint64_t K1 = strtoull(buf, &pEnd, 16);
|
||||
uint64_t K2 = strtoull(pEnd, &pEnd, 16);
|
||||
|
||||
u64_to_bytes_be(K1, &key1[0]);
|
||||
u64_to_bytes_be(K2, &key1[8]);
|
||||
|
||||
for (int i=0;i<16;i++) key2[i] = key1[15-i];
|
||||
|
||||
/* Create key schedule */
|
||||
create_keys(&ctx, key2, sizeof(key2));
|
||||
ctx.rounds = nbround;
|
||||
|
||||
fprintf (stderr,"DMR TYT AP (PC4) 128-bit Key %016llX%016llX with Forced Application\n", (unsigned long long int)K1, (unsigned long long int)K2);
|
||||
state->tyt_ap = 1;
|
||||
|
||||
}
|
||||
|
||||
void tyt_ep_aes_keystream_creation(dsd_state * state, char * input)
|
||||
{
|
||||
char buf[1024];
|
||||
strncpy(buf, input, 1023);
|
||||
buf[1023] = '\0';
|
||||
|
||||
char *pEnd;
|
||||
unsigned long long int K1 = strtoull (buf, &pEnd, 16);
|
||||
unsigned long long int K2 = strtoull (pEnd, &pEnd, 16);
|
||||
|
||||
//
|
||||
uint8_t static_key[32];
|
||||
memset(static_key, 0, sizeof(static_key));
|
||||
|
||||
//static key value
|
||||
static_key[0]=0x6e; static_key[1]=0x02; static_key[2]=0x8d; static_key[3]=0x8a;
|
||||
static_key[4]=0xca; static_key[5]=0xeb; static_key[6]=0x9b; static_key[7]=0xbe;
|
||||
static_key[8]=0x42; static_key[9]=0x72; static_key[10]=0xfb; static_key[11]=0x82;
|
||||
static_key[12]=0x64; static_key[13]=0x56; static_key[14]=0x31; static_key[15]=0xfa;
|
||||
|
||||
//the key value provided by user
|
||||
uint8_t user_key[16];
|
||||
memset(user_key, 0, sizeof(user_key));
|
||||
|
||||
//Load user key into array to manipulate
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
user_key[i+0] = (K1 >> (56-(i*8))) & 0xFF;
|
||||
user_key[i+8] = (K2 >> (56-(i*8))) & 0xFF;
|
||||
}
|
||||
|
||||
uint8_t input_register[16];
|
||||
memset(input_register, 0, sizeof(input_register));
|
||||
|
||||
//manipulate user provided key by loading bytes in reverse order into the input_register
|
||||
for (int i = 0; i < 16; i++)
|
||||
input_register[15-i] = user_key[i];
|
||||
|
||||
uint8_t ks_bytes[16];
|
||||
memset(ks_bytes, 0, sizeof(ks_bytes));
|
||||
|
||||
//create keystream
|
||||
aes_ofb_keystream_output(input_register, static_key, ks_bytes, 0, 1);
|
||||
uint8_t ks_bits[128];
|
||||
memset(ks_bits, 0, sizeof(ks_bits));
|
||||
unpack_byte_array_into_bit_array(ks_bytes, ks_bits, 16);
|
||||
|
||||
//load static keystream into ctx.bits since that isn't ever zeroed out
|
||||
for (int i = 0; i < 49; i++)
|
||||
ctx.bits[i] = ks_bits[i];
|
||||
|
||||
fprintf (stderr,"DMR TYT EP (AES-128) Key %016llX%016llX with Forced Application\n", K1, K2);
|
||||
state->tyt_ep = 1;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user