add scrambler key field in decoder block
parent
203850491b
commit
f9d2d7c7b1
|
@ -18,6 +18,10 @@ parameters:
|
||||||
dtype: bool
|
dtype: bool
|
||||||
default: 'False'
|
default: 'False'
|
||||||
options: ['True', 'False']
|
options: ['True', 'False']
|
||||||
|
- id: seed
|
||||||
|
label: Scrambler seed
|
||||||
|
dtype: string
|
||||||
|
default: ''
|
||||||
- id: key
|
- id: key
|
||||||
label: AES Key
|
label: AES Key
|
||||||
dtype: string
|
dtype: string
|
||||||
|
@ -43,7 +47,7 @@ asserts:
|
||||||
|
|
||||||
templates:
|
templates:
|
||||||
imports: from gnuradio import m17
|
imports: from gnuradio import m17
|
||||||
make: m17.m17_decoder(${debug_data},${debug_ctrl},${threshold},${callsign},${signed_str},${encr_type},${key})
|
make: m17.m17_decoder(${debug_data},${debug_ctrl},${threshold},${callsign},${signed_str},${encr_type},${key},${seed})
|
||||||
|
|
||||||
callbacks:
|
callbacks:
|
||||||
- set_debug_data(${debug_data})
|
- set_debug_data(${debug_data})
|
||||||
|
@ -53,6 +57,7 @@ templates:
|
||||||
- set_callsign(${callsign})
|
- set_callsign(${callsign})
|
||||||
- set_signed(${signed_str})
|
- set_signed(${signed_str})
|
||||||
- set_encr_type(${encr_type})
|
- set_encr_type(${encr_type})
|
||||||
|
- set_seed(${seed})
|
||||||
|
|
||||||
# Make one 'inputs' list entry per input and one 'outputs' list entry per output.
|
# Make one 'inputs' list entry per input and one 'outputs' list entry per output.
|
||||||
# Keys include:
|
# Keys include:
|
||||||
|
|
|
@ -43,13 +43,14 @@ namespace gr
|
||||||
*/
|
*/
|
||||||
static sptr make (bool debug_data, bool debug_ctrl, float threshold,
|
static sptr make (bool debug_data, bool debug_ctrl, float threshold,
|
||||||
bool callsign, bool signed_str, int encr_type,
|
bool callsign, bool signed_str, int encr_type,
|
||||||
std::string key);
|
std::string key, std::string seed);
|
||||||
virtual void set_debug_data (bool debug) = 0;
|
virtual void set_debug_data (bool debug) = 0;
|
||||||
virtual void set_debug_ctrl (bool debug) = 0;
|
virtual void set_debug_ctrl (bool debug) = 0;
|
||||||
virtual void set_callsign (bool callsign) = 0;
|
virtual void set_callsign (bool callsign) = 0;
|
||||||
virtual void set_threshold (float threshold) = 0;
|
virtual void set_threshold (float threshold) = 0;
|
||||||
virtual void set_signed (bool signed_str) = 0;
|
virtual void set_signed (bool signed_str) = 0;
|
||||||
virtual void set_key (std::string key) = 0;
|
virtual void set_key (std::string key) = 0;
|
||||||
|
virtual void set_seed (std::string seed) = 0;
|
||||||
virtual void parse_raw_key_string (uint8_t * dest, const char *inp) = 0;
|
virtual void parse_raw_key_string (uint8_t * dest, const char *inp) = 0;
|
||||||
virtual void scrambler_sequence_generator () = 0;
|
virtual void scrambler_sequence_generator () = 0;
|
||||||
virtual uint32_t scrambler_seed_calculation (int8_t subtype,
|
virtual uint32_t scrambler_seed_calculation (int8_t subtype,
|
||||||
|
|
|
@ -240,7 +240,7 @@ namespace gr
|
||||||
void m17_coder_impl::set_seed (std::string arg) // *UTF-8* encoded byte array
|
void m17_coder_impl::set_seed (std::string arg) // *UTF-8* encoded byte array
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
printf ("new key: ");
|
printf ("new seed: ");
|
||||||
length = arg.size ();
|
length = arg.size ();
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
while ((j < 3) && (i < length))
|
while ((j < 3) && (i < length))
|
||||||
|
|
|
@ -49,7 +49,6 @@ namespace gr
|
||||||
time_t epoch = 1577836800L; //Jan 1, 2020, 00:00:00 UTC
|
time_t epoch = 1577836800L; //Jan 1, 2020, 00:00:00 UTC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t _seed[3]; //24-bit is the largest seed value
|
|
||||||
int _encr_subtype, _can;
|
int _encr_subtype, _can;
|
||||||
lsf_t _lsf, _next_lsf;
|
lsf_t _lsf, _next_lsf;
|
||||||
std::string _meta;
|
std::string _meta;
|
||||||
|
@ -67,6 +66,7 @@ namespace gr
|
||||||
|
|
||||||
#ifdef ECC
|
#ifdef ECC
|
||||||
//Scrambler
|
//Scrambler
|
||||||
|
uint8_t _seed[3]; //24-bit is the largest seed value
|
||||||
uint8_t _scr_bytes[16];
|
uint8_t _scr_bytes[16];
|
||||||
uint8_t _scrambler_pn[128];
|
uint8_t _scrambler_pn[128];
|
||||||
uint32_t _scrambler_seed = 0;
|
uint32_t _scrambler_seed = 0;
|
||||||
|
|
|
@ -44,12 +44,12 @@ namespace gr
|
||||||
m17_decoder::sptr
|
m17_decoder::sptr
|
||||||
m17_decoder::make (bool debug_data, bool debug_ctrl, float threshold,
|
m17_decoder::make (bool debug_data, bool debug_ctrl, float threshold,
|
||||||
bool callsign, bool signed_str, int encr_type,
|
bool callsign, bool signed_str, int encr_type,
|
||||||
std::string key)
|
std::string key, std::string seed)
|
||||||
{
|
{
|
||||||
return gnuradio::get_initial_sptr
|
return gnuradio::get_initial_sptr
|
||||||
(new
|
(new
|
||||||
m17_decoder_impl (debug_data, debug_ctrl, threshold, callsign,
|
m17_decoder_impl (debug_data, debug_ctrl, threshold, callsign,
|
||||||
signed_str, encr_type, key));
|
signed_str, encr_type, key, seed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,8 +59,9 @@ namespace gr
|
||||||
m17_decoder_impl::m17_decoder_impl (bool debug_data, bool debug_ctrl,
|
m17_decoder_impl::m17_decoder_impl (bool debug_data, bool debug_ctrl,
|
||||||
float threshold, bool callsign,
|
float threshold, bool callsign,
|
||||||
bool signed_str, int encr_type,
|
bool signed_str, int encr_type,
|
||||||
std::string key):gr::
|
std::string key, std::string seed):
|
||||||
block ("m17_decoder", gr::io_signature::make (1, 1, sizeof (float)),
|
gr::block ("m17_decoder",
|
||||||
|
gr::io_signature::make (1, 1, sizeof (float)),
|
||||||
gr::io_signature::make (1, 1, sizeof (char))),
|
gr::io_signature::make (1, 1, sizeof (char))),
|
||||||
_debug_data (debug_data), _debug_ctrl (debug_ctrl),
|
_debug_data (debug_data), _debug_ctrl (debug_ctrl),
|
||||||
_threshold (threshold), _callsign (callsign), _signed_str (signed_str)
|
_threshold (threshold), _callsign (callsign), _signed_str (signed_str)
|
||||||
|
@ -165,6 +166,49 @@ namespace gr
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void m17_decoder_impl::set_seed (std::string arg) // *UTF-8* encoded byte array
|
||||||
|
{
|
||||||
|
int length;
|
||||||
|
printf ("new seed: ");
|
||||||
|
length = arg.size ();
|
||||||
|
int i = 0, j = 0;
|
||||||
|
while ((j < 3) && (i < length))
|
||||||
|
{
|
||||||
|
if ((unsigned int) arg.data ()[i] < 0xc2) // https://www.utf8-chartable.de/
|
||||||
|
{
|
||||||
|
_seed[j] = arg.data ()[i];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_seed[j] = (arg.data ()[i] - 0xc2) * 0x40 + arg.data ()[i + 1];
|
||||||
|
i += 2;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
length = j; // index from 0 to length-1
|
||||||
|
printf ("%d bytes: ", length);
|
||||||
|
for (i = 0; i < length; i++)
|
||||||
|
printf ("%02X ", _seed[i]);
|
||||||
|
printf ("\n");
|
||||||
|
fflush (stdout);
|
||||||
|
if(length<=2)
|
||||||
|
{
|
||||||
|
_scrambler_seed = _scrambler_seed >> 16;
|
||||||
|
fprintf(stderr, "Scrambler key: 0x%02X (8-bit)\n", _scrambler_seed);
|
||||||
|
}
|
||||||
|
else if(length<=4)
|
||||||
|
{
|
||||||
|
_scrambler_seed = _scrambler_seed >> 8;
|
||||||
|
fprintf(stderr, "Scrambler key: 0x%04X (16-bit)\n", _scrambler_seed);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fprintf(stderr, "Scrambler key: 0x%06X (24-bit)\n", _scrambler_seed);
|
||||||
|
|
||||||
|
_encr_type=ENCR_SCRAM; //Scrambler key was passed
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
m17_decoder_impl::forecast (int noutput_items,
|
m17_decoder_impl::forecast (int noutput_items,
|
||||||
gr_vector_int & ninput_items_required)
|
gr_vector_int & ninput_items_required)
|
||||||
|
@ -203,12 +247,12 @@ namespace gr
|
||||||
}
|
}
|
||||||
|
|
||||||
//truncate seed so subtype will continue to set properly on subsequent passes
|
//truncate seed so subtype will continue to set properly on subsequent passes
|
||||||
if (scrambler_subtype == 0)
|
if (_scrambler_subtype == 0)
|
||||||
scrambler_seed &= 0xFF;
|
_scrambler_seed &= 0xFF;
|
||||||
else if (scrambler_subtype == 1)
|
else if (_scrambler_subtype == 1)
|
||||||
scrambler_seed &= 0xFFFF;
|
_scrambler_seed &= 0xFFFF;
|
||||||
else if (scrambler_subtype == 2)
|
else if (_scrambler_subtype == 2)
|
||||||
scrambler_seed &= 0xFFFFFF;
|
_scrambler_seed &= 0xFFFFFF;
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
//fprintf (stderr, "\nScrambler Key: 0x%06X; Seed: 0x%06X; Subtype: %02d; FN: %05d; ", key, lfsr, subtype, fn);
|
//fprintf (stderr, "\nScrambler Key: 0x%06X; Seed: 0x%06X; Subtype: %02d; FN: %05d; ", key, lfsr, subtype, fn);
|
||||||
|
@ -221,20 +265,20 @@ namespace gr
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
uint32_t lfsr, bit;
|
uint32_t lfsr, bit;
|
||||||
lfsr = scrambler_seed;
|
lfsr = _scrambler_seed;
|
||||||
|
|
||||||
//only set if not initially set (first run), it is possible (and observed) that the scrambler_subtype can
|
//only set if not initially set (first run), it is possible (and observed) that the scrambler_subtype can
|
||||||
//change on subsequent passes if the current SEED for the LFSR falls below one of these thresholds
|
//change on subsequent passes if the current SEED for the LFSR falls below one of these thresholds
|
||||||
if (scrambler_subtype == -1)
|
if (_scrambler_subtype == -1)
|
||||||
{
|
{
|
||||||
if (lfsr > 0 && lfsr <= 0xFF)
|
if (lfsr > 0 && lfsr <= 0xFF)
|
||||||
scrambler_subtype = 0; // 8-bit key
|
_scrambler_subtype = 0; // 8-bit key
|
||||||
else if (lfsr > 0xFF && lfsr <= 0xFFFF)
|
else if (lfsr > 0xFF && lfsr <= 0xFFFF)
|
||||||
scrambler_subtype = 1; //16-bit key
|
_scrambler_subtype = 1; //16-bit key
|
||||||
else if (lfsr > 0xFFFF && lfsr <= 0xFFFFFF)
|
else if (lfsr > 0xFFFF && lfsr <= 0xFFFFFF)
|
||||||
scrambler_subtype = 2; //24-bit key
|
_scrambler_subtype = 2; //24-bit key
|
||||||
else
|
else
|
||||||
scrambler_subtype = 0; // 8-bit key (default)
|
_scrambler_subtype = 0; // 8-bit key (default)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Set Frame Type based on scrambler_subtype value
|
//TODO: Set Frame Type based on scrambler_subtype value
|
||||||
|
@ -242,7 +286,7 @@ namespace gr
|
||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"\nScrambler Key: 0x%06X; Seed: 0x%06X; Subtype: %02d;",
|
"\nScrambler Key: 0x%06X; Seed: 0x%06X; Subtype: %02d;",
|
||||||
scrambler_seed, lfsr, scrambler_subtype);
|
_scrambler_seed, lfsr, _scrambler_subtype);
|
||||||
fprintf (stderr, "\n pN: ");
|
fprintf (stderr, "\n pN: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,11 +294,11 @@ namespace gr
|
||||||
for (i = 0; i < 128; i++)
|
for (i = 0; i < 128; i++)
|
||||||
{
|
{
|
||||||
//get feedback bit with specified taps, depending on the scrambler_subtype
|
//get feedback bit with specified taps, depending on the scrambler_subtype
|
||||||
if (scrambler_subtype == 0)
|
if (_scrambler_subtype == 0)
|
||||||
bit = (lfsr >> 7) ^ (lfsr >> 5) ^ (lfsr >> 4) ^ (lfsr >> 3);
|
bit = (lfsr >> 7) ^ (lfsr >> 5) ^ (lfsr >> 4) ^ (lfsr >> 3);
|
||||||
else if (scrambler_subtype == 1)
|
else if (_scrambler_subtype == 1)
|
||||||
bit = (lfsr >> 15) ^ (lfsr >> 14) ^ (lfsr >> 12) ^ (lfsr >> 3);
|
bit = (lfsr >> 15) ^ (lfsr >> 14) ^ (lfsr >> 12) ^ (lfsr >> 3);
|
||||||
else if (scrambler_subtype == 2)
|
else if (_scrambler_subtype == 2)
|
||||||
bit = (lfsr >> 23) ^ (lfsr >> 22) ^ (lfsr >> 21) ^ (lfsr >> 16);
|
bit = (lfsr >> 23) ^ (lfsr >> 22) ^ (lfsr >> 21) ^ (lfsr >> 16);
|
||||||
else
|
else
|
||||||
bit = 0; //should never get here, but just in case
|
bit = 0; //should never get here, but just in case
|
||||||
|
@ -262,29 +306,29 @@ namespace gr
|
||||||
bit &= 1; //truncate bit to 1 bit (required since I didn't do it above)
|
bit &= 1; //truncate bit to 1 bit (required since I didn't do it above)
|
||||||
lfsr = (lfsr << 1) | bit; //shift LFSR left once and OR bit onto LFSR's LSB
|
lfsr = (lfsr << 1) | bit; //shift LFSR left once and OR bit onto LFSR's LSB
|
||||||
lfsr &= 0xFFFFFF; //truncate lfsr to 24-bit (really doesn't matter)
|
lfsr &= 0xFFFFFF; //truncate lfsr to 24-bit (really doesn't matter)
|
||||||
scrambler_pn[i] = bit;
|
_scrambler_pn[i] = bit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//pack bit array into byte array for easy data XOR
|
//pack bit array into byte array for easy data XOR
|
||||||
pack_bit_array_into_byte_array (scrambler_pn, scr_bytes, 16);
|
pack_bit_array_into_byte_array (_scrambler_pn, _scr_bytes, 16);
|
||||||
|
|
||||||
//save scrambler seed for next round
|
//save scrambler seed for next round
|
||||||
scrambler_seed = lfsr;
|
_scrambler_seed = lfsr;
|
||||||
|
|
||||||
//truncate seed so subtype will continue to set properly on subsequent passes
|
//truncate seed so subtype will continue to set properly on subsequent passes
|
||||||
if (scrambler_subtype == 0)
|
if (_scrambler_subtype == 0)
|
||||||
scrambler_seed &= 0xFF;
|
_scrambler_seed &= 0xFF;
|
||||||
else if (scrambler_subtype == 1)
|
else if (_scrambler_subtype == 1)
|
||||||
scrambler_seed &= 0xFFFF;
|
_scrambler_seed &= 0xFFFF;
|
||||||
else if (scrambler_subtype == 2)
|
else if (_scrambler_subtype == 2)
|
||||||
scrambler_seed &= 0xFFFFFF;
|
_scrambler_seed &= 0xFFFFFF;
|
||||||
|
|
||||||
if (_debug_ctrl == true)
|
if (_debug_ctrl == true)
|
||||||
{
|
{
|
||||||
//debug packed bytes
|
//debug packed bytes
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
fprintf (stderr, " %02X", scr_bytes[i]);
|
fprintf (stderr, " %02X", _scr_bytes[i]);
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,12 +534,12 @@ namespace gr
|
||||||
if (_encr_type == ENCR_SCRAM)
|
if (_encr_type == ENCR_SCRAM)
|
||||||
{
|
{
|
||||||
if (fn != 0 && (fn % 0x8000) != _expected_next_fn) //frame skip, etc
|
if (fn != 0 && (fn % 0x8000) != _expected_next_fn) //frame skip, etc
|
||||||
scrambler_seed =
|
_scrambler_seed =
|
||||||
scrambler_seed_calculation (scrambler_subtype,
|
scrambler_seed_calculation (_scrambler_subtype,
|
||||||
_scrambler_key,
|
_scrambler_key,
|
||||||
fn & 0x7FFF);
|
fn & 0x7FFF);
|
||||||
else if (fn == 0)
|
else if (fn == 0)
|
||||||
scrambler_seed = _scrambler_key; //reset back to key value
|
_scrambler_seed = _scrambler_key; //reset back to key value
|
||||||
|
|
||||||
if (_signed_str == true && (fn % 0x8000) < 0x7FFC) //signed stream
|
if (_signed_str == true && (fn % 0x8000) < 0x7FFC) //signed stream
|
||||||
scrambler_sequence_generator ();
|
scrambler_sequence_generator ();
|
||||||
|
@ -504,7 +548,7 @@ namespace gr
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 16; i++)
|
for (uint8_t i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
frame_data[i + 3] ^= scr_bytes[i];
|
frame_data[i + 3] ^= _scr_bytes[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,21 +74,22 @@ namespace gr
|
||||||
uint8_t d_dst[12], d_src[12]; //decoded strings
|
uint8_t d_dst[12], d_src[12]; //decoded strings
|
||||||
#ifdef ECC
|
#ifdef ECC
|
||||||
//Scrambler
|
//Scrambler
|
||||||
uint8_t scr_bytes[16];
|
uint8_t _seed[3]; //24-bit is the largest seed value
|
||||||
uint8_t scrambler_pn[128];
|
uint8_t _scr_bytes[16];
|
||||||
uint32_t scrambler_seed = 0;
|
uint8_t _scrambler_pn[128];
|
||||||
int8_t scrambler_subtype = -1;
|
uint32_t _scrambler_seed = 0;
|
||||||
|
int8_t _scrambler_subtype = -1;
|
||||||
#endif
|
#endif
|
||||||
const struct uECC_Curve_t *_curve = uECC_secp256r1 ();
|
const struct uECC_Curve_t *_curve = uECC_secp256r1 ();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
m17_decoder_impl (bool debug_data, bool debug_ctrl, float threshold,
|
m17_decoder_impl (bool debug_data, bool debug_ctrl, float threshold,
|
||||||
bool callsign, bool signed_str, int encr_type,
|
bool callsign, bool signed_str, int encr_type,
|
||||||
std::string key);
|
std::string key, std::string seed);
|
||||||
~m17_decoder_impl ();
|
~m17_decoder_impl ();
|
||||||
void set_debug_data (bool debug);
|
void set_debug_data (bool debug);
|
||||||
void set_key (std::string arg);
|
void set_key (std::string arg);
|
||||||
|
void set_seed (std::string seed);
|
||||||
void set_debug_ctrl (bool debug);
|
void set_debug_ctrl (bool debug);
|
||||||
void set_callsign (bool callsign);
|
void set_callsign (bool callsign);
|
||||||
void set_threshold (float threshold);
|
void set_threshold (float threshold);
|
||||||
|
|
Loading…
Reference in New Issue