* Added AES and AES-CTR modules. AES-CTR conforms to the same counter mode used with AES in *OpenSSL*. * All algorithms now work on Big-Endian architectures. * Now uses CMake for building rather than make files and Visual Studio projects. CMake will generate whatever system is required. * Input function parameters are now marked `const` * File names have been changed to have the prefix `CryptLib_` rather than `Lib`. * Various formatting changes to the files.
92 lines
2.9 KiB
C
92 lines
2.9 KiB
C
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Rc4String
|
|
//
|
|
// Outputs bytes from an RC4 stream. Key is taken from command line. Bytes are output as hex
|
|
//
|
|
// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// IMPORTS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include "CryptLib_Rc4.h"
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// DEFINITIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef __min
|
|
#define __min( x, y ) (((x) < (y))?(x):(y))
|
|
#endif
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// CONSTANTS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define BUFFER_SIZE 1024
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// FUNCTIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// main
|
|
//
|
|
// Program entry point
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int
|
|
main
|
|
(
|
|
int ArgC,
|
|
char** ArgV
|
|
)
|
|
{
|
|
char* string;
|
|
uint32_t numBytes;
|
|
uint32_t i;
|
|
uint8_t buffer [BUFFER_SIZE];
|
|
uint32_t amountLeft;
|
|
uint32_t chunk;
|
|
Rc4Context rc4 = {0};
|
|
uint32_t dropN = 0;
|
|
|
|
if( 3 != ArgC && 4 != ArgC )
|
|
{
|
|
printf(
|
|
"Syntax\n"
|
|
" Rc4Output <Key> <NumBytes> [DropN]\n" );
|
|
return 1;
|
|
}
|
|
|
|
string = ArgV[1];
|
|
numBytes = atoi( ArgV[2] );
|
|
if( 4 == ArgC )
|
|
{
|
|
dropN = atoi( ArgV[3] );
|
|
}
|
|
|
|
Rc4Initialise( &rc4, string, (uint32_t)strlen(string), dropN );
|
|
|
|
amountLeft = numBytes;
|
|
while( amountLeft > 0 )
|
|
{
|
|
chunk = __min( amountLeft, BUFFER_SIZE );
|
|
Rc4Output( &rc4, buffer, chunk );
|
|
amountLeft -= chunk;
|
|
|
|
for( i=0; i<chunk; i++ )
|
|
{
|
|
printf( "%2.2x", buffer[i] );
|
|
}
|
|
}
|
|
|
|
printf( "\n" );
|
|
|
|
return 0;
|
|
}
|