Encryption Routines

In these routines a big parameter can also be used wherever a flash is specified, but not visa-versa. Further information may be gleaned from the (lightly) commented source code. An asterisk after the name indicates that the function does not take a mip parameter if MR_GENERIC_MT is defined in mirdef.h .

Function:

mr_unsign32 aes_decrypt(a,buff)

aes *a;

char *buff;
Module Description Parameters Return value
mraes.c Decrypts a 16 or n byte input buffer in situ. Pointer to an initialised instance of an aes structure defined in miracl.h, and to the buffer of bytes to be decrypted. If the mode of operation is as a block cipher (MR_ECB or MR_CBC) then 16 bytes will be decrypted. If the mode of operation is as a stream cipher (MR_CFBn, MR_OFBn or MR_PCFBn) then n bytes will be decrypted. In MR_CFBn and MR_PCFBn modes the n byte(s) that were shifted off the end of the input register as result of decrypting the n input byte(s), otherwise 0.

Function:

mr_unsign32 aes_encrypt(a,buff)

aes *a;

char *buff;
Module Description Parameters Return value
mraes.c Encrypts a 16 or n byte input buffer in situ. Pointer to an initialised instance of an aes structure defined in miracl.h, and to the buffer of bytes to be encrypted. If the mode of operation is as a block cipher (MR_ECB or MR_CBC) then 16 bytes will be encrypted. If the mode of operation is as a stream cipher (MR_CFBn, MR_OFBn or MR_PCFBn) then a n bytes will be encrypted. In MR_CFBn and MR_PCFBn modes the n byte(s) that were shifted off the end of the input register as result of encrypting the n input byte(s), otherwise 0.

Function:

void aes_end(a)

aes *a;
Module Description Parameters Return value
mraes.c Ends an AES encryption session, and de-allocates the memory associated with it. The internal session key data is destroyed. Pointer to an initialised instance of an aes structure defined in miracl.h None

Function:

void aes_getreg(a,ir)

aes *a;

char *ir;
Module Description Parameters Return value
mraes.c Reads the current contents of the input chaining register associated with this instance of the AES. This is the register initialised by the IV in the calls to aes_init and aes_reset. Pointer to an instance of the aes structure, defined in miracl.h, and a character array to hold the extracted 16-byte data. None

Function:

BOOL aes_init(a,mode,nk,key,iv)

aes *a;

int mode,nk;

char key,iv;
Module Description Parameters Return value
mraes.c Initialises an Encryption/Decryption session using the Advanced Encryption Standard (AES). This is a block cipher system that encrypts data in 128-bit blocks using a key of 128, 192 or 256 bits. See [Stinson] for more background on block ciphers. Pointer to an instance of the aes structure defined in miracl.h, the mode of operation to be used, an integer nk which specifies the size of the Key in bytes, and pointers to the key itself and the optional Initialisation Vector (IV). The mode can be one of MR_ECB (Electronic Code Book), MR_CBC (Cipher Block Chaining), MR_CFBn (Cipher Feed-back where n is 1, 2 or 4), MR_PCFBn (error Propagating Cipher Feed-back where n is 1, 2 or 4) or MR_OFBn (Output Feed-back where n is 1, 2, 4, 8 or 16). The value of n indicates the number of bytes to be processed in each application. For more information on Modes of Operation, see [Stinson]. MR_PCFBn is an invention of our own [Scott93]. See diagram below. The value of nk can be 16, 24 or 32. A 16 bytes initialisation vector iv should be specified for all modes other than MR_ECB, in which case it can be NULL. TRUE if initialisation succeeded, otherwise FALSE.

Diagram

Function:

void aes_reset(a,mode,iv)

aes *a;

int mode;

char *iv;
Module Description Parameters Return value
mraes.c Resets the AES structure Pointer to an instance of the aes structure defined in miracl.h, an indication of the new mode of operation, and a pointer to a (possibly new) initialisation vector iv. See above for the modes allowed. None

Function:

void shs_init(psh)

sha *psh;
Module Description Parameters Return value
mrshs.c Initialises an instance of the Secure Hash Algorithm SHA-1. Must be called before new use. Pointer to an instance of a structure defined in miracl.h None

Function:

void shs_hash(psh,hash)

sha *psh;

char hash[20];
Module Description Parameters Return value
mrshs.c Generates a twenty byte (160 bit) hash value into the provided array. Pointer to the current instance, and pointer to array to be filled. None

Function:

void shs_process(psh,ch)

sha *psh;

int ch;
Module Description Parameters Return value
mrshs.c Processes a single byte. Typically called many times to provide input to the hashing process. The hash value of all the processed bytes can be retrieved by a subsequent call to shs_hash. Pointer to the current instance, and character to be processed. None

Function:

void shs256_init(psh)

sha256 *psh;
Module Description Parameters Return value
mrshs256.c Initialises an instance of the Secure Hash Algorithm SHA-256. Must be called before new use. Pointer to an instance of a structure defined in miracl.h None

Function:

void shs256_hash(psh,hash)

sha256 *psh;

char hash[32];
Module Description Parameters Return value
mrshs256.c Generates a 32 byte (256 bit) hash value into the provided array. Pointer to the current instance, and pointer to array to be filled. None

Function:

void shs256_process(psh,ch)

sha256 *psh;

int ch;
Module Description Parameters Return value
mrshs256.c Processes a single byte. Typically called many times to provide input to the hashing process. The hash value of all the processed bytes can be retrieved by a subsequent call to shs256_hash. Pointer to the current instance, and character to be processed. None

Function:

void shs384_init(psh)

sha384 *psh;
Module Description Parameters Return value Restrictions
mrshs512.c Initialises an instance of the Secure Hash Algorithm SHA-384. Must be called before new use. Pointer to an instance of a structure defined in miracl.h None The SHA-384 algorithm is only available if 64-bit data-type is defined.

Function:

void shs384_hash(psh,hash)

sha384 *psh;

char hash[48];
Module Description Parameters Return value
mrshs512.c Generates a 48 byte (384 bit) hash value into the provided array. Pointer to the current instance, and pointer to array to be filled. None

Function:

void shs512_process(psh,ch)

sha384 *psh;

int ch;
Module Description Parameters Return value
mrshs512.c Processes a single byte. Typically called many times to provide input to the hashing process. The hash value of all the processed bytes can be retrieved by a subsequent call to shs384_hash. Pointer to the current instance, and character to be processes. None

Function:

void shs512_init(psh)

sha512 *psh;
Module Description Parameters Return value Restrictions
mrshs512.c Initialises an instance of the Secure Hash Algorithm SHA-512. Must be called before new use. Pointer to an instance of a structure defined in miracl.h None The SHA-512 algorithm is only available if 64-bit data-type is defined.

Function:

void shs512_hash(psh,hash)

sha512 *psh;

char hash[64];
Module Description Parameters Return value
mrshs512.c Generates a 64 byte (512 bit) hash value into the provided array. Pointer to the current instance, and pointer to array to be filled. None

Function:

void shs512_process(psh,ch)

sha512 *psh;

int ch;
Module Description Parameters Return value
mrshs512.c Processes a single byte. Typically called many times to provide input to the hashing process. The hash value of all the processed bytes can be retrieved by a subsequent call to shs512_hash. Pointer to the current instance, and character to be processed. None

Function:

void strong_bigdig(rng,n,b,x)

csprng *rng;

int n,b;

big x;
Module Description Parameters Return value Restrictions
mrstrong.c Generates a big random number of given length from the cryptographically strong generator rng. A pointer to the random number generator rng. A big number x and two integers n and b. On exit x contains a big random number n digits long to base b. None The base b must be printable, that is 2 £ b £ 256.

Function:

void strong_bigrand(rng,w,x)

csprng *rng;

big w,x;
Module Description Parameters Return value
mrstrong.c Generates a cryptographically strong random big number x using the random number generator rng such that 0£x<w Two big numbers w and x, and a random number generator rng None

Function:

void strong_init(rng,rawlen,raw,tod)

csprng *rng;

int rawlen;

char *raw;

long tod;
Module Description Parameters Return value
mrstrong.c Initialize the cryptographically strong random number generator rng. A pointer to the random number generator rng. An array raw of length rawlen and a 32-bit time-of-day value tod. These two sources are used together to seed the generator. The former might be provided from random keystrokes, the latter from an internal clock. Subsequent calls to strong_rng will provide random bytes. None

Example:

See test1363.c and p1363.c for an example of use.

Function:

void strong_kill(rng)

csprng *rng;
Module Description Parameters Return value
mrstrong.c Kills the internal state of the random number generator rng A pointer to a random number generator None

Function:

int strong_rng(rng)

csprng *rng;
Module Description Parameters Return value
mrstrong.c Generates a sequence of cryptographically strong random bytes. A pointer to a random number A random byte