mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-21 13:15:40 -05:00
Fix Some Tab Alignment Issues;
NXDN: Make seperate AES IV expansion function;
This commit is contained in:
@@ -1519,8 +1519,9 @@ void aes_cfb_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * in,
|
|||||||
void aes_ctr_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payload, int type);
|
void aes_ctr_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payload, int type);
|
||||||
void aes_ctr_bitwise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payload, int type);
|
void aes_ctr_bitwise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payload, int type);
|
||||||
|
|
||||||
//LFSR to expand either a DMR 32-bit or P25 64-bit MI into a 128-bit IV for AES
|
//LFSR to expand either a DMR 32-bit or P25/NXDN 64-bit MI into a 128-bit IV for AES
|
||||||
void LFSR128(dsd_state * state);
|
void LFSR128(dsd_state * state);
|
||||||
|
void LFSR128n(dsd_state * state);
|
||||||
void LFSR128d(dsd_state * state);
|
void LFSR128d(dsd_state * state);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -516,12 +516,12 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
|
|||||||
{
|
{
|
||||||
|
|
||||||
//more debug
|
//more debug
|
||||||
fprintf (stderr, " IV: %016llX; Key: %016llX", state->payload_miN, state->R);
|
// fprintf (stderr, " IV: %016llX; Key: %016llX", state->payload_miN, state->R);
|
||||||
|
|
||||||
memset (state->ks_octetL, 0, sizeof(state->ks_octetL));
|
memset (state->ks_octetL, 0, sizeof(state->ks_octetL));
|
||||||
memset (state->ks_bitstreamL, 0, sizeof(state->ks_bitstreamL));
|
memset (state->ks_bitstreamL, 0, sizeof(state->ks_bitstreamL));
|
||||||
|
|
||||||
aes_ofb_keystream_output (state->aes_ivR, state->aes_key, state->ks_octetL, 2, 15); //14 + 1 discard round
|
aes_ofb_keystream_output (state->aes_iv, state->aes_key, state->ks_octetL, 2, 15); //14 + 1 discard round
|
||||||
|
|
||||||
//reset bit_counter
|
//reset bit_counter
|
||||||
state->bit_counterL = 0;
|
state->bit_counterL = 0;
|
||||||
|
|||||||
@@ -1336,3 +1336,43 @@ uint8_t crc7_scch(uint8_t bits[], int len)
|
|||||||
}
|
}
|
||||||
return load_i(s, 7);
|
return load_i(s, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LFSR128n(dsd_state * state)
|
||||||
|
{
|
||||||
|
//generate a 128-bit IV from a 64-bit IV for AES blocks
|
||||||
|
unsigned long long int lfsr = state->payload_miN;
|
||||||
|
|
||||||
|
//start packing aes_iv
|
||||||
|
state->aes_iv[0] = (lfsr >> 56) & 0xFF;
|
||||||
|
state->aes_iv[1] = (lfsr >> 48) & 0xFF;
|
||||||
|
state->aes_iv[2] = (lfsr >> 40) & 0xFF;
|
||||||
|
state->aes_iv[3] = (lfsr >> 32) & 0xFF;
|
||||||
|
state->aes_iv[4] = (lfsr >> 24) & 0xFF;
|
||||||
|
state->aes_iv[5] = (lfsr >> 16) & 0xFF;
|
||||||
|
state->aes_iv[6] = (lfsr >> 8 ) & 0xFF;
|
||||||
|
state->aes_iv[7] = (lfsr >> 0 ) & 0xFF;
|
||||||
|
|
||||||
|
|
||||||
|
int cnt = 0; int x = 64;
|
||||||
|
unsigned long long int bit;
|
||||||
|
//polynomial P(x) = 1 + X15 + X27 + X38 + X46 + X62 + X64
|
||||||
|
for(cnt=0;cnt<64;cnt++)
|
||||||
|
{
|
||||||
|
//63,61,45,37,27,14
|
||||||
|
// Polynomial is C(x) = x^64 + x^62 + x^46 + x^38 + x^27 + x^15 + 1
|
||||||
|
bit = ((lfsr >> 63) ^ (lfsr >> 61) ^ (lfsr >> 45) ^ (lfsr >> 37) ^ (lfsr >> 26) ^ (lfsr >> 14)) & 0x1;
|
||||||
|
lfsr = (lfsr << 1) | bit;
|
||||||
|
|
||||||
|
//continue packing aes_iv
|
||||||
|
state->aes_iv[x/8] = (state->aes_iv[x/8] << 1) + bit;
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, " IV(128): 0x");
|
||||||
|
for (x = 0; x < 16; x++)
|
||||||
|
fprintf (stderr, "%02X", state->aes_iv[x]);
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1420,14 +1420,9 @@ void NXDN_decode_VCALL_IV(dsd_opts * opts, dsd_state * state, uint8_t * Message)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//use the P25 Slot 1 LFSR128 to generate a 128-bit IV (state->payload_miN is on slot1)
|
//expand the IV into 128-bit
|
||||||
if (state->nxdn_cipher_type == 0x03)
|
if (state->nxdn_cipher_type == 0x03)
|
||||||
{
|
LFSR128n(state);
|
||||||
state->currentslot = 1; //quickly change to slot 1
|
|
||||||
fprintf (stderr, "\n NXDN -- ");
|
|
||||||
LFSR128(state); //TODO: Make a different function so we don't see the LDU2/ESS-B info and null key values, or something
|
|
||||||
state->currentslot = 0; //change back to slot 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state->nxdn_cipher_type == 0x02 && state->keyloader == 1)
|
if (state->nxdn_cipher_type == 0x02 && state->keyloader == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user