Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
Data Structures | Functions
internal-grain128.h File Reference

Internal implementation of the Grain-128 stream cipher. More...

#include "internal-util.h"

Go to the source code of this file.

Data Structures

struct  grain128_state_t
 Representation of the state of Grain-128. More...
 

Functions

void grain128_core (grain128_state_t *state, uint32_t x, uint32_t x2)
 Performs 32 rounds of Grain-128 in parallel. More...
 
uint32_t grain128_preoutput (const grain128_state_t *state)
 Generates 32 bits of pre-output data. More...
 
void grain128_setup (grain128_state_t *state, const unsigned char *key, const unsigned char *nonce)
 Sets up the initial Grain-128 state with the key and nonce. More...
 
void grain128_authenticate (grain128_state_t *state, const unsigned char *data, unsigned long long len)
 Authenticates data with Grain-128. More...
 
void grain128_encrypt (grain128_state_t *state, unsigned char *c, const unsigned char *m, unsigned long long len)
 Encrypts and authenticates data with Grain-128. More...
 
void grain128_decrypt (grain128_state_t *state, unsigned char *m, const unsigned char *c, unsigned long long len)
 Decrypts and authenticates data with Grain-128. More...
 
void grain128_compute_tag (grain128_state_t *state)
 Computes the final authentiation tag. More...
 

Detailed Description

Internal implementation of the Grain-128 stream cipher.

References: https://grain-128aead.github.io/

Function Documentation

void grain128_authenticate ( grain128_state_t state,
const unsigned char *  data,
unsigned long long  len 
)

Authenticates data with Grain-128.

Parameters
stateGrain-128 state.
dataPoints to the data to be authenticated.
lenLength of the data to be authenticated.
void grain128_compute_tag ( grain128_state_t state)

Computes the final authentiation tag.

Parameters
stateGrain-128 state.

The final authentication tag is written to the first 8 bytes of state->ks.

void grain128_core ( grain128_state_t state,
uint32_t  x,
uint32_t  x2 
)

Performs 32 rounds of Grain-128 in parallel.

Parameters
stateGrain-128 state.
x32 bits of input to be incorporated into the LFSR state, or zero.
x2Another 32 bits to be incorporated into the NFSR state, or zero.
void grain128_decrypt ( grain128_state_t state,
unsigned char *  m,
const unsigned char *  c,
unsigned long long  len 
)

Decrypts and authenticates data with Grain-128.

Parameters
stateGrain-128 state.
mPoints to the plaintext output buffer.
cPoints to the ciphertext input buffer.
lenLength of the data to be decrypted.
void grain128_encrypt ( grain128_state_t state,
unsigned char *  c,
const unsigned char *  m,
unsigned long long  len 
)

Encrypts and authenticates data with Grain-128.

Parameters
stateGrain-128 state.
cPoints to the ciphertext output buffer.
mPoints to the plaintext input buffer.
lenLength of the data to be encrypted.
uint32_t grain128_preoutput ( const grain128_state_t state)

Generates 32 bits of pre-output data.

Parameters
stateGrain-128 state.
Returns
The generated 32 bits of pre-output data.
void grain128_setup ( grain128_state_t state,
const unsigned char *  key,
const unsigned char *  nonce 
)

Sets up the initial Grain-128 state with the key and nonce.

Parameters
stateGrain-128 state to be initialized.
keyPoints to the 128-bit key.
noncePoints to the 96-bit nonce.