mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-09 15:27:22 -05:00
DMR TYT BP (16-bit) Encryption Mode; #302
Above Commit is by Anonymous Submission;
This commit is contained in:
@@ -1162,6 +1162,7 @@ void keyring(dsd_opts * opts, dsd_state * state);
|
||||
void read_sdrtrunk_json_format (dsd_opts * opts, dsd_state * state);
|
||||
void ambe2_codeword_print_f (dsd_opts * opts, char ambe_fr[4][24]);
|
||||
void ambe2_codeword_print_b (dsd_opts * opts, char ambe_fr[4][24]);
|
||||
void ambe2_codeword_print_i (dsd_opts * opts, char ambe_fr[4][24]);
|
||||
void openMbeInFile (dsd_opts * opts, dsd_state * state);
|
||||
void closeMbeOutFile (dsd_opts * opts, dsd_state * state);
|
||||
void closeMbeOutFileR (dsd_opts * opts, dsd_state * state); //tdma slot 2
|
||||
@@ -1613,7 +1614,7 @@ void aes_ctr_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payl
|
||||
void aes_ctr_bitwise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payload, int type);
|
||||
|
||||
//Tytera Encryption Modes
|
||||
int tyt16_ambe2_codeword_keystream(dsd_state * state, char ambe_fr[4][24], int idx, int fnum);
|
||||
void tyt16_ambe2_codeword_keystream(dsd_state * state, char ambe_fr[4][24], int fnum);
|
||||
|
||||
//Hytera Enhanced
|
||||
void hytera_enhanced_rc4_setup(dsd_opts * opts, dsd_state * state, unsigned long long int key_value, unsigned long long int mi_value);
|
||||
|
||||
147
src/crypt-tyt.c
147
src/crypt-tyt.c
@@ -1,4 +1,41 @@
|
||||
#include "dsd.h"
|
||||
#include "dmr_const.h"
|
||||
|
||||
//interleaved code words for AMBE+2
|
||||
void ambe2_codeword_print_i (dsd_opts * opts, char ambe_fr[4][24])
|
||||
{
|
||||
uint8_t interleaved[72];
|
||||
memset (interleaved, 0, sizeof(interleaved));
|
||||
|
||||
//reinterleave the frame
|
||||
const int *w, *x, *y, *z;
|
||||
w = rW; x = rX; y = rY; z = rZ;
|
||||
|
||||
for (int8_t i = 0; i < 36; i++)
|
||||
{
|
||||
interleaved[(i*2)+0] = (uint8_t)ambe_fr[*w][*x];
|
||||
interleaved[(i*2)+1] = (uint8_t)ambe_fr[*y][*z];
|
||||
|
||||
w++;
|
||||
x++;
|
||||
y++;
|
||||
z++;
|
||||
}
|
||||
|
||||
uint8_t bytes[9]; memset(bytes, 0, sizeof(bytes));
|
||||
|
||||
//pack
|
||||
pack_bit_array_into_byte_array(interleaved, bytes, 9);
|
||||
|
||||
if (opts->payload == 1)
|
||||
{
|
||||
fprintf (stderr, " AMBE HEX(72) INT: ");
|
||||
for (int8_t i = 0; i < 9; i++)
|
||||
fprintf (stderr, "%02X", bytes[i]);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//de-interleaved code words for AMBE+2
|
||||
void ambe2_codeword_print_b (dsd_opts * opts, char ambe_fr[4][24])
|
||||
@@ -57,86 +94,64 @@ void ambe2_codeword_print_f (dsd_opts * opts, char ambe_fr[4][24])
|
||||
|
||||
}
|
||||
|
||||
//test application of keystream to codewords instead of ambe_d (tytera / retevis, etc)
|
||||
int tyt16_ambe2_codeword_keystream(dsd_state * state, char ambe_fr[4][24], int idx, int fnum)
|
||||
//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?
|
||||
void tyt16_ambe2_codeword_keystream(dsd_state * state, char ambe_fr[4][24], int fnum)
|
||||
{
|
||||
uint8_t ks_bytes[28]; memset(ks_bytes, 0, sizeof(ks_bytes));
|
||||
uint8_t ks[224]; memset(ks, 0, sizeof(ks));
|
||||
|
||||
UNUSED(fnum);
|
||||
char interleaved[72];
|
||||
memset (interleaved, 0, sizeof(interleaved));
|
||||
|
||||
//interleave the frame
|
||||
const int *w, *x, *y, *z;
|
||||
w = rW; x = rX; y = rY; z = rZ;
|
||||
|
||||
for (int8_t i = 0; i < 36; i++)
|
||||
{
|
||||
interleaved[(i*2)+0] = ambe_fr[*w][*x];
|
||||
interleaved[(i*2)+1] = ambe_fr[*y][*z];
|
||||
|
||||
w++;
|
||||
x++;
|
||||
y++;
|
||||
z++;
|
||||
}
|
||||
|
||||
uint8_t ks_bytes[10]; memset(ks_bytes, 0, sizeof(ks_bytes));
|
||||
uint8_t ks[80]; memset(ks, 0, sizeof(ks));
|
||||
|
||||
ks_bytes[0] = (state->H >> 8) & 0xFF;
|
||||
ks_bytes[1] = (state->H >> 0) & 0xFF;
|
||||
|
||||
//copy same bytes into rest of byte array
|
||||
for (int16_t i = 2; i < 28; i++)
|
||||
for (int16_t i = 2; i < 10; i++)
|
||||
ks_bytes[i] = ks_bytes[i%2];
|
||||
|
||||
//debug ks_bytes
|
||||
// fprintf (stderr, " KB: ");
|
||||
// for (int16_t i = 0; i < 28; i++)
|
||||
// fprintf (stderr, "%02X ", ks_bytes[i]);
|
||||
// fprintf (stderr, "\n");
|
||||
|
||||
//convert byte array into a bit array
|
||||
unpack_byte_array_into_bit_array(ks_bytes, ks, 28);
|
||||
|
||||
//debug ks
|
||||
// fprintf (stderr, " KS: ");
|
||||
// for (int16_t i = 0; i < 28; i++)
|
||||
// fprintf (stderr, "%02X ", (uint8_t)convert_bits_into_output(ks+(i*8), 8));
|
||||
// fprintf (stderr, "\n");
|
||||
|
||||
//debug to test application to ambe_fr result
|
||||
// memset(ambe_fr, 0, 4*24*sizeof(char));
|
||||
unpack_byte_array_into_bit_array(ks_bytes, ks, 10);
|
||||
|
||||
//set ks idx position (-1)
|
||||
int idx = 0;
|
||||
if (fnum == 0)
|
||||
idx = 0;
|
||||
else idx = 8;
|
||||
idx = 79;
|
||||
else idx = 71;
|
||||
|
||||
//straight?
|
||||
for (int16_t i = 0; i < 24; i++)
|
||||
ambe_fr[0][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
//apply keystream to interleave
|
||||
for (int8_t i = 0; i < 72; i++)
|
||||
interleaved[i] ^= ks[idx--];
|
||||
|
||||
for (int16_t i = 0; i < 23; i++)
|
||||
ambe_fr[1][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
for (int16_t i = 0; i < 11; i++)
|
||||
ambe_fr[2][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
for (int16_t i = 0; i < 14; i++)
|
||||
ambe_fr[3][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
//backwards?
|
||||
// for (int16_t i = 13; i >= 0; i--)
|
||||
// ambe_fr[3][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
// for (int16_t i = 10; i >= 0; i--)
|
||||
// ambe_fr[2][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
// for (int16_t i = 22; i >= 0; i--)
|
||||
// ambe_fr[1][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
// for (int16_t i = 23; i >= 0; i--)
|
||||
// ambe_fr[0][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
//forwards?
|
||||
// for (int16_t i = 23; i >= 0; i--)
|
||||
// ambe_fr[0][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
// for (int16_t i = 22; i >= 0; i--)
|
||||
// ambe_fr[1][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
// for (int16_t i = 10; i >= 0; i--)
|
||||
// ambe_fr[2][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
// for (int16_t i = 13; i >= 0; i--)
|
||||
// ambe_fr[3][i] ^= ks[((idx++)%216)] ^ 1; //%216
|
||||
|
||||
//debug idx value
|
||||
fprintf (stderr, " KS IDX: %04d; \n", idx);
|
||||
|
||||
return idx;
|
||||
//deinterleave back into ambe_fr frame
|
||||
w = rW; x = rX; y = rY; z = rZ;
|
||||
int k = 0;
|
||||
for (int8_t i = 0; i < 36; i++)
|
||||
{
|
||||
ambe_fr[*w][*x] = interleaved[k++];
|
||||
ambe_fr[*y][*z] = interleaved[k++];
|
||||
|
||||
w++;
|
||||
x++;
|
||||
y++;
|
||||
z++;
|
||||
}
|
||||
|
||||
}
|
||||
34
src/dmr_bs.c
34
src/dmr_bs.c
@@ -22,10 +22,6 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
char ambe_fr2[4][24];
|
||||
char ambe_fr3[4][24];
|
||||
|
||||
int ks_idx[2];
|
||||
ks_idx[0] = 0;
|
||||
ks_idx[1] = 0;
|
||||
|
||||
//redundancy check (carrier signal loss event)
|
||||
char redundancyA[36];
|
||||
char redundancyB[36];
|
||||
@@ -501,16 +497,15 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||
|
||||
if (state->tyt_bp == 1)
|
||||
{
|
||||
ks_idx[internalslot] = tyt16_ambe2_codeword_keystream(state, ambe_fr, ks_idx[internalslot], 0);
|
||||
ks_idx[internalslot] = tyt16_ambe2_codeword_keystream(state, ambe_fr2, ks_idx[internalslot], 1);
|
||||
ks_idx[internalslot] = tyt16_ambe2_codeword_keystream(state, ambe_fr3, ks_idx[internalslot], 0);
|
||||
// ks_idx[internalslot] = 0; //move, or needed elsewhere?
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr, 0);
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr2, 1);
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr3, 0);
|
||||
}
|
||||
|
||||
#ifdef PRINT_AMBE72
|
||||
ambe2_codeword_print_b(opts, ambe_fr);
|
||||
ambe2_codeword_print_b(opts, ambe_fr2);
|
||||
ambe2_codeword_print_b(opts, ambe_fr3);
|
||||
ambe2_codeword_print_i(opts, ambe_fr);
|
||||
ambe2_codeword_print_i(opts, ambe_fr2);
|
||||
ambe2_codeword_print_i(opts, ambe_fr3);
|
||||
#endif
|
||||
|
||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||
@@ -736,10 +731,6 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||
char ambe_fr2[4][24];
|
||||
char ambe_fr3[4][24];
|
||||
|
||||
int ks_idx[2];
|
||||
ks_idx[0] = 0;
|
||||
ks_idx[1] = 0;
|
||||
|
||||
memset (ambe_fr, 0, sizeof(ambe_fr));
|
||||
memset (ambe_fr2, 0, sizeof(ambe_fr2));
|
||||
memset (ambe_fr3, 0, sizeof(ambe_fr3));
|
||||
@@ -948,16 +939,15 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||
|
||||
if (state->tyt_bp == 1)
|
||||
{
|
||||
ks_idx[internalslot] = tyt16_ambe2_codeword_keystream(state, ambe_fr, ks_idx[internalslot], 0);
|
||||
ks_idx[internalslot] = tyt16_ambe2_codeword_keystream(state, ambe_fr2, ks_idx[internalslot], 1);
|
||||
ks_idx[internalslot] = tyt16_ambe2_codeword_keystream(state, ambe_fr3, ks_idx[internalslot], 0);
|
||||
ks_idx[internalslot] = 0; //doesn't matter in this location
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr, 0);
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr2, 1);
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr3, 0);
|
||||
}
|
||||
|
||||
#ifdef PRINT_AMBE72
|
||||
ambe2_codeword_print_b(opts, ambe_fr);
|
||||
ambe2_codeword_print_b(opts, ambe_fr2);
|
||||
ambe2_codeword_print_b(opts, ambe_fr3);
|
||||
ambe2_codeword_print_i(opts, ambe_fr);
|
||||
ambe2_codeword_print_i(opts, ambe_fr2);
|
||||
ambe2_codeword_print_i(opts, ambe_fr3);
|
||||
#endif
|
||||
|
||||
if (opts->payload == 1) fprintf (stderr, "\n"); //extra line break necessary here
|
||||
|
||||
30
src/dmr_ms.c
30
src/dmr_ms.c
@@ -23,8 +23,6 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
||||
char ambe_fr3[4][24];
|
||||
char ambe_fr4[4][24];
|
||||
|
||||
int ks_idx = 0;
|
||||
|
||||
//memcpy of ambe_fr for late entry
|
||||
uint8_t m1[4][24];
|
||||
uint8_t m2[4][24];
|
||||
@@ -250,16 +248,15 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
||||
|
||||
if (state->tyt_bp == 1)
|
||||
{
|
||||
ks_idx = tyt16_ambe2_codeword_keystream(state, ambe_fr, ks_idx, 0);
|
||||
ks_idx = tyt16_ambe2_codeword_keystream(state, ambe_fr2, ks_idx, 1);
|
||||
ks_idx = tyt16_ambe2_codeword_keystream(state, ambe_fr3, ks_idx, 0);
|
||||
// ks_idx = 0; //needed?
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr, 0);
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr2, 1);
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr3, 0);
|
||||
}
|
||||
|
||||
#ifdef PRINT_AMBE72
|
||||
ambe2_codeword_print_b(opts, ambe_fr);
|
||||
ambe2_codeword_print_b(opts, ambe_fr2);
|
||||
ambe2_codeword_print_b(opts, ambe_fr3);
|
||||
ambe2_codeword_print_i(opts, ambe_fr);
|
||||
ambe2_codeword_print_i(opts, ambe_fr2);
|
||||
ambe2_codeword_print_i(opts, ambe_fr3);
|
||||
#endif
|
||||
|
||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||
@@ -384,8 +381,6 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||
memset (ambe_fr2, 0, sizeof(ambe_fr2));
|
||||
memset (ambe_fr3, 0, sizeof(ambe_fr3));
|
||||
|
||||
int ks_idx = 0;
|
||||
|
||||
//memcpy of ambe_fr for late entry
|
||||
uint8_t m1[4][24];
|
||||
uint8_t m2[4][24];
|
||||
@@ -558,16 +553,15 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||
|
||||
if (state->tyt_bp == 1)
|
||||
{
|
||||
ks_idx = tyt16_ambe2_codeword_keystream(state, ambe_fr, ks_idx, 0);
|
||||
ks_idx = tyt16_ambe2_codeword_keystream(state, ambe_fr2, ks_idx, 1);
|
||||
ks_idx = tyt16_ambe2_codeword_keystream(state, ambe_fr3, ks_idx, 0);
|
||||
// ks_idx = 0; //needed?
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr, 0);
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr2, 1);
|
||||
tyt16_ambe2_codeword_keystream(state, ambe_fr3, 0);
|
||||
}
|
||||
|
||||
#ifdef PRINT_AMBE72
|
||||
ambe2_codeword_print_b(opts, ambe_fr);
|
||||
ambe2_codeword_print_b(opts, ambe_fr2);
|
||||
ambe2_codeword_print_b(opts, ambe_fr3);
|
||||
ambe2_codeword_print_i(opts, ambe_fr);
|
||||
ambe2_codeword_print_i(opts, ambe_fr2);
|
||||
ambe2_codeword_print_i(opts, ambe_fr3);
|
||||
#endif
|
||||
|
||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||
|
||||
Reference in New Issue
Block a user