mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-16 10:47:21 -05:00
DMR: PDU RC4 and BP Decryption;
This commit is contained in:
52
src/1.c
52
src/1.c
@@ -1,7 +1,53 @@
|
||||
/*-------------------------------------------------------------------------------
|
||||
* 1.c
|
||||
* Placeholder File 1 -- This file is for temporary code storage
|
||||
* RC4 and RC4 Block Output For Keystream Application
|
||||
*
|
||||
*
|
||||
*
|
||||
*-----------------------------------------------------------------------------*/
|
||||
*
|
||||
*-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "dsd.h"
|
||||
|
||||
//this is for PDU usage
|
||||
void rc4_block_output (int drop, int keylen, int meslen, uint8_t * key, uint8_t * output_blocks)
|
||||
{
|
||||
int i, j, x, count;
|
||||
unsigned int keylength = (unsigned int)keylen;
|
||||
unsigned int messagelength = (unsigned int)meslen;
|
||||
unsigned int S[256];
|
||||
|
||||
for(i=0; i<256; i++)
|
||||
S[i] = i;
|
||||
|
||||
j = 0;
|
||||
for(i = 0; i<256; i++)
|
||||
{
|
||||
j = (j + S[i] + key[i % keylength]) % 256;
|
||||
unsigned int temp = S[i];
|
||||
S[i] = S[j];
|
||||
S[j] = temp;
|
||||
}
|
||||
|
||||
//Generate Keystream
|
||||
i = 0;
|
||||
j = 0;
|
||||
x = 0;
|
||||
unsigned int byte;
|
||||
|
||||
// fprintf (stderr, " Keystream Octets = ");
|
||||
for(count = 0; count < (messagelength + drop); count++)
|
||||
{
|
||||
i = (i + 1) % 256;
|
||||
j = (j + S[i]) % 256;
|
||||
unsigned int temp = S[i];
|
||||
S[i] = S[j];
|
||||
S[j] = temp;
|
||||
byte = S[(S[i] + S[j]) % 256];
|
||||
|
||||
//Collect Output blocks
|
||||
if (count >= drop)
|
||||
output_blocks[x++] = byte;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user