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

GIFT-128 block cipher. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  gift128_key_schedule_t
 Structure of an expanded GIFT-128 key schedule. More...
 

Macros

#define GIFT128_KEY_SIZE   16
 Size of the key for GIFT-128.
 
#define GIFT128_BLOCK_SIZE   16
 Size of a single message block for GIFT-128.
 

Functions

size_t gift128_get_key_schedule_size (void)
 Gets the actual size of the GIFT-128 key schedule in the back end. More...
 
size_t gift128_get_parallel_size (void)
 Gets the best size to use for parallel encryption and decryption. More...
 
void gift128_setup_key (gift128_key_schedule_t *ks, const unsigned char *k)
 Sets up a key schedule for the original version of GIFT-128. More...
 
void gift128_ecb_encrypt (const gift128_key_schedule_t *ks, unsigned char *output, const unsigned char *input, size_t len)
 Encrypts a 128-bit block with the original version of GIFT-128. More...
 
void gift128_ecb_decrypt (const gift128_key_schedule_t *ks, unsigned char *output, const unsigned char *input, size_t len)
 Decrypts a 128-bit block with the original version of GIFT-128. More...
 
void gift128_le_setup_key (gift128_key_schedule_t *ks, const unsigned char *k)
 Sets up a key schedule for the little-endian version of GIFT-128. More...
 
void gift128_le_ecb_encrypt (const gift128_key_schedule_t *ks, unsigned char *output, const unsigned char *input, size_t len)
 Encrypts a 128-bit block with the little-endian version of GIFT-128. More...
 
void gift128_le_ecb_decrypt (const gift128_key_schedule_t *ks, unsigned char *output, const unsigned char *input, size_t len)
 Decrypts a 128-bit block with the little-endian version of GIFT-128. More...
 
void gift128b_setup_key (gift128_key_schedule_t *ks, const unsigned char *k)
 Sets up a key schedule for the bit-sliced version of GIFT-128. More...
 
void gift128b_ecb_encrypt (const gift128_key_schedule_t *ks, unsigned char *output, const unsigned char *input, size_t len)
 Encrypts a 128-bit block with the bit-sliced version of GIFT-128. More...
 
void gift128b_ecb_decrypt (const gift128_key_schedule_t *ks, unsigned char *output, const unsigned char *input, size_t len)
 Decrypts a 128-bit block with the bit-sliced version of GIFT-128. More...
 
void gift128_free_schedule (gift128_key_schedule_t *ks)
 Frees a GIFT-128 key schedule and destroys any sensitive data. More...
 

Detailed Description

GIFT-128 block cipher.

This API provides access to the raw GIFT-128 block cipher ECB operation to help applications implement higher-level modes around the cipher.

Three versions of the GIFT-128 key setup, encryption, and decryption functions are provided with different prefixes:

Internally the first two versions are implemented on top of the third, with the byte and nibble order re-arranged on input and output.

The ECB encryption and decryption functions can take multiple blocks as input which allows the back end to process multiple blocks in parallel on architectures with SIMD instructions. The function gift128_get_parallel_size() returns the best number of bytes to process in a parallel request. The input should be divided up into blocks of this size if possible.

Function Documentation

void gift128_ecb_decrypt ( const gift128_key_schedule_t ks,
unsigned char *  output,
const unsigned char *  input,
size_t  len 
)

Decrypts a 128-bit block with the original version of GIFT-128.

Parameters
ksPoints to the GIFT-128 key schedule.
outputOutput buffer which must be at least len bytes in length.
inputInput buffer which must be at least len bytes in length.
lenNumber of bytes to decrypt, which should be a multiple of GIFT128_BLOCK_SIZE bytes. If not, the last partial block will be ignored.

The input and output buffers can be the same buffer for in-place decryption.

See Also
gift128_ecb_encrypt(), gift128_setup_key()
void gift128_ecb_encrypt ( const gift128_key_schedule_t ks,
unsigned char *  output,
const unsigned char *  input,
size_t  len 
)

Encrypts a 128-bit block with the original version of GIFT-128.

Parameters
ksPoints to the GIFT-128 key schedule.
outputOutput buffer which must be at least len bytes in length.
inputInput buffer which must be at least len bytes in length.
lenNumber of bytes to encrypt, which should be a multiple of GIFT128_BLOCK_SIZE bytes. If not, the last partial block will be ignored.

The input and output buffers can be the same buffer for in-place encryption.

See Also
gift128_ecb_decrypt(), gift128_setup_key()
void gift128_free_schedule ( gift128_key_schedule_t ks)

Frees a GIFT-128 key schedule and destroys any sensitive data.

Parameters
ksPoints to the key schedule object.

Normally this will simply clear the ks object to all zeroes as the caller is responsible for deallocating the memory used by ks. It is still a good idea to call this function when the key schedule is no longer required because future back ends might allocate dynamic memory for large key schedules in the key setup functions.

See Also
gift128_setup_key(), gift128_le_setup_key(), gift128b_setup_key()
size_t gift128_get_key_schedule_size ( void  )

Gets the actual size of the GIFT-128 key schedule in the back end.

Returns
The actual size of the key schedule.
size_t gift128_get_parallel_size ( void  )

Gets the best size to use for parallel encryption and decryption.

Returns
The best size in bytes to use for processing blocks in parallel. If the back end does not support parallel block processing, then this function will return GIFT128_BLOCK_SIZE.
void gift128_le_ecb_decrypt ( const gift128_key_schedule_t ks,
unsigned char *  output,
const unsigned char *  input,
size_t  len 
)

Decrypts a 128-bit block with the little-endian version of GIFT-128.

Parameters
ksPoints to the GIFT-128 key schedule.
outputOutput buffer which must be at least len bytes in length.
inputInput buffer which must be at least len bytes in length.
lenNumber of bytes to decrypt, which should be a multiple of GIFT128_BLOCK_SIZE bytes. If not, the last partial block will be ignored.

The input and output buffers can be the same buffer for in-place decryption.

See Also
gift128_le_ecb_encrypt(), gift128_le_setup_key()
void gift128_le_ecb_encrypt ( const gift128_key_schedule_t ks,
unsigned char *  output,
const unsigned char *  input,
size_t  len 
)

Encrypts a 128-bit block with the little-endian version of GIFT-128.

Parameters
ksPoints to the GIFT-128 key schedule.
outputOutput buffer which must be at least len bytes in length.
inputInput buffer which must be at least len bytes in length.
lenNumber of bytes to encrypt, which should be a multiple of GIFT128_BLOCK_SIZE bytes. If not, the last partial block will be ignored.

The input and output buffers can be the same buffer for in-place encryption.

See Also
gift128_le_ecb_decrypt(), gift128_le_setup_key()
void gift128_le_setup_key ( gift128_key_schedule_t ks,
const unsigned char *  k 
)

Sets up a key schedule for the little-endian version of GIFT-128.

Parameters
ksPoints to the key schedule object to set up.
kPoints to the GIFT128_KEY_SIZE bytes of the key.
See Also
gift128_le_ecb_encrypt(), gift128_le_ecb_decrypt(), gift128_free_schedule()
void gift128_setup_key ( gift128_key_schedule_t ks,
const unsigned char *  k 
)

Sets up a key schedule for the original version of GIFT-128.

Parameters
ksPoints to the key schedule object to set up.
kPoints to the GIFT128_KEY_SIZE bytes of the key.
See Also
gift128_ecb_encrypt(), gift128_ecb_decrypt(), gift128_free_schedule()
void gift128b_ecb_decrypt ( const gift128_key_schedule_t ks,
unsigned char *  output,
const unsigned char *  input,
size_t  len 
)

Decrypts a 128-bit block with the bit-sliced version of GIFT-128.

Parameters
ksPoints to the GIFT-128 key schedule.
outputOutput buffer which must be at least len bytes in length.
inputInput buffer which must be at least len bytes in length.
lenNumber of bytes to decrypt, which should be a multiple of GIFT128_BLOCK_SIZE bytes. If not, the last partial block will be ignored.

The input and output buffers can be the same buffer for in-place decryption.

See Also
gift128b_ecb_encrypt(), gift128b_setup_key()
void gift128b_ecb_encrypt ( const gift128_key_schedule_t ks,
unsigned char *  output,
const unsigned char *  input,
size_t  len 
)

Encrypts a 128-bit block with the bit-sliced version of GIFT-128.

Parameters
ksPoints to the GIFT-128 key schedule.
outputOutput buffer which must be at least len bytes in length.
inputInput buffer which must be at least len bytes in length.
lenNumber of bytes to encrypt, which should be a multiple of GIFT128_BLOCK_SIZE bytes. If not, the last partial block will be ignored.

The input and output buffers can be the same buffer for in-place encryption.

See Also
gift128b_ecb_decrypt(), gift128b_setup_key()
void gift128b_setup_key ( gift128_key_schedule_t ks,
const unsigned char *  k 
)

Sets up a key schedule for the bit-sliced version of GIFT-128.

Parameters
ksPoints to the key schedule object to set up.
kPoints to the GIFT128_KEY_SIZE bytes of the key.
See Also
gift128b_ecb_encrypt(), gift128b_ecb_decrypt(), gift128_free_schedule()