* 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.
74 lines
3.0 KiB
C
74 lines
3.0 KiB
C
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// CryptLib_RC4
|
|
//
|
|
// An implementation of RC4 stream cipher
|
|
//
|
|
// This is free and unencumbered software released into the public domain - June 2013 waterjuice.org
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma once
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// IMPORTS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include <stdint.h>
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// TYPES
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Rc4Context - This must be initialised using Rc4Initialised. Do not modify the contents of this structure directly.
|
|
typedef struct
|
|
{
|
|
uint32_t i;
|
|
uint32_t j;
|
|
uint8_t S[256];
|
|
} Rc4Context;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// PUBLIC FUNCTIONS
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Rc4Initialise
|
|
//
|
|
// Initialises an RC4 cipher and discards the specified number of first bytes.
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void
|
|
Rc4Initialise
|
|
(
|
|
Rc4Context* Context,
|
|
void const* Key,
|
|
uint32_t KeySize,
|
|
uint32_t DropN
|
|
);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Rc4Output
|
|
//
|
|
// Outputs the requested number of bytes from the RC4 stream
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void
|
|
Rc4Output
|
|
(
|
|
Rc4Context* Context,
|
|
void* Buffer,
|
|
uint32_t Size
|
|
);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Rc4Xor
|
|
//
|
|
// XORs the RC4 stream with an input buffer and puts the results in an output buffer. This is used for encrypting
|
|
// and decrypting data. InBuffer and OutBuffer can point to the same location for inplace encrypting/decrypting
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void
|
|
Rc4Xor
|
|
(
|
|
Rc4Context* Context,
|
|
void const* InBuffer,
|
|
void* OutBuffer,
|
|
uint32_t Size
|
|
);
|