Lightweight Cryptography Primitives
|
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... | |
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:
gift128
- Nibble-based GIFT-128 with big endian byte order for the key and big endian nibble order for the message blocks. This is the version of GIFT-128 from the original paper. gift128_le
- Nibble-based GIFT-128 with little endian byte order for the key and little endian nibble order for the message blocks. This version is used in some AEAD modes that are built around GIFT-128. gift128b
- Bit-sliced GIFT-128 with big endian byte order for the key and message blocks. This version is used by GIFT-COFB and is the fastest version of the three.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.
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.
ks | Points to the GIFT-128 key schedule. |
output | Output buffer which must be at least len bytes in length. |
input | Input buffer which must be at least len bytes in length. |
len | Number 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.
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.
ks | Points to the GIFT-128 key schedule. |
output | Output buffer which must be at least len bytes in length. |
input | Input buffer which must be at least len bytes in length. |
len | Number 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.
void gift128_free_schedule | ( | gift128_key_schedule_t * | ks | ) |
Frees a GIFT-128 key schedule and destroys any sensitive data.
ks | Points 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.
size_t gift128_get_key_schedule_size | ( | void | ) |
Gets the actual size of the GIFT-128 key schedule in the back end.
size_t gift128_get_parallel_size | ( | void | ) |
Gets the best size to use for parallel encryption and decryption.
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.
ks | Points to the GIFT-128 key schedule. |
output | Output buffer which must be at least len bytes in length. |
input | Input buffer which must be at least len bytes in length. |
len | Number 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.
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.
ks | Points to the GIFT-128 key schedule. |
output | Output buffer which must be at least len bytes in length. |
input | Input buffer which must be at least len bytes in length. |
len | Number 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.
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.
ks | Points to the key schedule object to set up. |
k | Points to the GIFT128_KEY_SIZE bytes of the key. |
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.
ks | Points to the key schedule object to set up. |
k | Points to the GIFT128_KEY_SIZE bytes of the key. |
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.
ks | Points to the GIFT-128 key schedule. |
output | Output buffer which must be at least len bytes in length. |
input | Input buffer which must be at least len bytes in length. |
len | Number 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.
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.
ks | Points to the GIFT-128 key schedule. |
output | Output buffer which must be at least len bytes in length. |
input | Input buffer which must be at least len bytes in length. |
len | Number 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.
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.
ks | Points to the key schedule object to set up. |
k | Points to the GIFT128_KEY_SIZE bytes of the key. |