Skinny-C
 All Data Structures Files Functions Variables Groups Pages
Data Structures | Macros | Functions
Mantis API

MANTIS tweakable block cipher with 64-bit blocks. More...

Data Structures

union  MantisCells_t
 Union that describes a 64-bit 4x4 array of cells. More...
 
struct  MantisKey_t
 Key schedule for Mantis block ciphers. More...
 
struct  MantisCTR_t
 State information for Mantis in CTR mode. More...
 
struct  MantisParallelECB_t
 State information for Mantis in parallel ECB mode. More...
 

Macros

#define MANTIS_BLOCK_SIZE   8
 Size of a block for Mantis block ciphers.
 
#define MANTIS_KEY_SIZE   16
 Size of a Mantis block cipher key.
 
#define MANTIS_TWEAK_SIZE   8
 Size of a Mantis block cipher tweak.
 
#define MANTIS_MIN_ROUNDS   5
 Minimum number of rounds for Mantis block ciphers. More...
 
#define MANTIS_MAX_ROUNDS   8
 Maximum number of rounds for Mantis block ciphers.
 
#define MANTIS_ENCRYPT   1
 Mode that selects Mantis encryption when the key schedule is setup.
 
#define MANTIS_DECRYPT   0
 Mode that selects Mantis decryption when the key schedule is setup.
 

Functions

int mantis_set_key (MantisKey_t *ks, const void *key, unsigned size, unsigned rounds, int mode)
 Sets the key schedule for a Mantis block cipher. More...
 
int mantis_set_tweak (MantisKey_t *ks, const void *tweak, unsigned size)
 Sets the tweak value for a previously-initialized key schedule. More...
 
void mantis_swap_modes (MantisKey_t *ks)
 Swaps the encryption and decryption modes on a Mantis key schedule. More...
 
void mantis_ecb_crypt (void *output, const void *input, const MantisKey_t *ks)
 Encrypts or decrypts a single block using the Mantis block cipher in ECB mode. More...
 
void mantis_ecb_crypt_tweaked (void *output, const void *input, const void *tweak, const MantisKey_t *ks)
 Encrypts or decrypts a single block using the Mantis block cipher in ECB mode, with the tweak supplied explicitly. More...
 
int mantis_ctr_init (MantisCTR_t *ctr)
 Initializes Mantis in CTR mode. More...
 
void mantis_ctr_cleanup (MantisCTR_t *ctr)
 Cleans up a CTR control block for Mantis. More...
 
int mantis_ctr_set_key (MantisCTR_t *ctr, const void *key, unsigned size, unsigned rounds)
 Sets the key schedule for a Mantis block cipher in CTR mode. More...
 
int mantis_ctr_set_tweak (MantisCTR_t *ctr, const void *tweak, unsigned tweak_size)
 Changes the tweak value for a previously-initialized key schedule. More...
 
int mantis_ctr_set_counter (MantisCTR_t *ctr, const void *counter, unsigned size)
 Sets the counter value in a Mantis CTR control block. More...
 
int mantis_ctr_encrypt (void *output, const void *input, size_t size, MantisCTR_t *ctr)
 Encrypt a block of data using Mantis in CTR mode. More...
 
int mantis_parallel_ecb_init (MantisParallelECB_t *ecb)
 Initializes Mantis in parallel ECB mode. More...
 
void mantis_parallel_ecb_cleanup (MantisParallelECB_t *ecb)
 Cleans up a parallel ECB control block for Mantis. More...
 
int mantis_parallel_ecb_set_key (MantisParallelECB_t *ecb, const void *key, unsigned size, unsigned rounds, int mode)
 Sets the key schedule for a Mantis block cipher in parallel ECB mode. More...
 
void mantis_parallel_ecb_swap_modes (MantisParallelECB_t *ecb)
 Swaps the encryption and decryption modes on a parallel Mantis key schedule. More...
 
int mantis_parallel_ecb_crypt (void *output, const void *input, const void *tweak, size_t size, const MantisParallelECB_t *ecb)
 Encrypts or decrypts a block of data using Mantis in parallel ECB mode. More...
 

Detailed Description

MANTIS tweakable block cipher with 64-bit blocks.

Mantis is a tweakable block cipher with 64-bit blocks, a 128-bit key, and a 64-bit tweak. It is a variant of SKINNY that is designed for memory encryption. Typically, memory is encrypted in 8-byte blocks in ECB mode with the memory address of each block supplied to the cipher as the tweak.

Mantis comes in variants with round counts between 5 and 8. The authors advise that there is a known efficient attack against Mantis-5. They recommend using at least Mantis-7. For an even larger security margin, use Skinny-64 or Skinny-128 instead of Mantis.

In Mantis, ECB encryption and decryption are provided by the same function mantis_ecb_crypt(). The initial mode is selected by an argument to mantis_set_key() and can be changed to the other mode on the fly without a new key setup by calling mantis_swap_modes().

Macro Definition Documentation

#define MANTIS_MIN_ROUNDS   5

Minimum number of rounds for Mantis block ciphers.

Note
The authors advise that there is a known efficient attack against Mantis-5. They recommend using at least Mantis-7.

Definition at line 77 of file mantis-cipher.h.

Function Documentation

void mantis_ctr_cleanup ( MantisCTR_t ctr)

Cleans up a CTR control block for Mantis.

Parameters
ctrPoints to the CTR control block to clean up.

Definition at line 205 of file mantis-ctr.c.

int mantis_ctr_encrypt ( void *  output,
const void *  input,
size_t  size,
MantisCTR_t ctr 
)

Encrypt a block of data using Mantis in CTR mode.

Parameters
outputThe output buffer for the ciphertext.
inputThe input buffer containing the plaintext.
sizeThe number of bytes to be encrypted.
ctrThe CTR control block to use and update.
Returns
Zero if there is something wrong with the parameters, or 1 if the data was encrypted.

This function can also be used for CTR mode decryption.

Definition at line 245 of file mantis-ctr.c.

int mantis_ctr_init ( MantisCTR_t ctr)

Initializes Mantis in CTR mode.

Parameters
ctrPoints to the CTR control block to initialize.
Returns
Zero if ctr is NULL or there is insufficient memory to create internal data structures, or non-zero if everything is OK.

The counter block is initially set to all-zeroes.

See Also
mantis_ctr_set_counter(), mantis_ctr_encrypt()

Definition at line 187 of file mantis-ctr.c.

int mantis_ctr_set_counter ( MantisCTR_t ctr,
const void *  counter,
unsigned  size 
)

Sets the counter value in a Mantis CTR control block.

Parameters
ctrThe CTR control block to modify.
counterThe counter value to set, which may be NULL to specify an all-zeroes counter.
sizeThe size of the counter in bytes, between 0 and MANTIS_BLOCK_SIZE. Short counter blocks are padded on the left with zeroes to make up a full MANTIS_BLOCK_SIZE bytes.
Returns
Zero if there is something wrong with the parameters, or 1 if the counter has been set.

The counter is assumed to be in big-endian order, incremented from the right-most byte forward, as in the standard AES-CTR mode. Often the counter block will contain a packet sequence number or equivalent in the left-most bytes with the right-most bytes used to count blocks within the specified packet.

Calling this function will also reset the keystream position so that the next call to mantis_ctr_encrypt() will start with the new counter value. Usually this occurs at the start of a packet.

Definition at line 235 of file mantis-ctr.c.

int mantis_ctr_set_key ( MantisCTR_t ctr,
const void *  key,
unsigned  size,
unsigned  rounds 
)

Sets the key schedule for a Mantis block cipher in CTR mode.

Parameters
ctrThe CTR control block to set the key on.
keyPoints to the key.
sizeSize of the key, which must be MANTIS_KEY_SIZE.
roundsThe number of rounds to use, between MANTIS_MIN_ROUNDS and MANTIS_MAX_ROUNDS.
Returns
Zero if there is something wrong with the parameters, or 1 if the key has been set. The tweak will be set to zero.

Calling this function will also reset the keystream position so that the next call to mantis_ctr_encrypt() will start with the new key. Usually this occurs at the start of a packet.

See Also
mantis_ctr_set_tweak()

Definition at line 215 of file mantis-ctr.c.

int mantis_ctr_set_tweak ( MantisCTR_t ctr,
const void *  tweak,
unsigned  tweak_size 
)

Changes the tweak value for a previously-initialized key schedule.

Parameters
ctrThe CTR control block to set the tweak on.
tweakThe new tweak value, or NULL for a zero tweak.
tweak_sizeSize of the new tweak value; between 1 and 16 bytes.
Returns
Zero if there is something wrong with the parameters, or 1 if the tweak was changed.

This function modifies the key schedule to change the tweak from its previous value to the new value given by tweak.

Calling this function will also reset the keystream position so that the next call to mantis_ctr_encrypt() will start with the new counter value. Usually this occurs at the start of a packet.

See Also
mantis_ctr_set_key()

Definition at line 225 of file mantis-ctr.c.

void mantis_ecb_crypt ( void *  output,
const void *  input,
const MantisKey_t ks 
)

Encrypts or decrypts a single block using the Mantis block cipher in ECB mode.

Parameters
outputThe output block, which must contain at least MANTIS_BLOCK_SIZE bytes of space for the ciphertext.
inputThe input block, which must contain at least MANTIS_BLOCK_SIZE bytes of plaintext data.
ksThe key schedule that was set up by mantis_set_key().

The input and output blocks are allowed to overlap.

The encryption or decryption mode is selected when the key schedule is setup by mantis_set_key(). The mode can also be altered on the fly by calling mantis_swap_modes().

See Also
mantis_ecb_crypt_tweaked()

Definition at line 400 of file mantis-cipher.c.

void mantis_ecb_crypt_tweaked ( void *  output,
const void *  input,
const void *  tweak,
const MantisKey_t ks 
)

Encrypts or decrypts a single block using the Mantis block cipher in ECB mode, with the tweak supplied explicitly.

Parameters
outputThe output block, which must contain at least MANTIS_BLOCK_SIZE bytes of space for the ciphertext.
inputThe input block, which must contain at least MANTIS_BLOCK_SIZE bytes of plaintext data.
tweakThe tweak block, which must contain at least MANTIS_BLOCK_SIZE bytes of tweak data.
ksThe key schedule that was set up by mantis_set_key().

The input and output blocks are allowed to overlap.

The encryption or decryption mode is selected when the key schedule is setup by mantis_set_key(). The mode can also be altered on the fly by calling mantis_swap_modes().

This function differs from mantis_ecb_crypt() in that the tweak is supplied explicitly to the function rather than via mantis_set_tweak(). This can be useful if every block that is encrypted or decrypted has its own block-specific tweak.

See Also
mantis_ecb_crypt()

Definition at line 574 of file mantis-cipher.c.

void mantis_parallel_ecb_cleanup ( MantisParallelECB_t ecb)

Cleans up a parallel ECB control block for Mantis.

Parameters
ecbPoints to the parallel ECB control block to clean up.

Definition at line 62 of file mantis-parallel.c.

int mantis_parallel_ecb_crypt ( void *  output,
const void *  input,
const void *  tweak,
size_t  size,
const MantisParallelECB_t ecb 
)

Encrypts or decrypts a block of data using Mantis in parallel ECB mode.

Parameters
outputThe output buffer for the ciphertext.
inputThe input buffer containing the plaintext.
tweakA buffer containing the tweak values to use for each block in the input.
sizeThe number of bytes to be encrypted, which must be a multiple of MANTIS_BLOCK_SIZE.
ecbThe parallel ECB control block to use and update.
Returns
Zero if there is something wrong with the parameters, or 1 if the data was encrypted.

For best performance, size should be a multiple of the parallel_size value in to the ecb structure.

The encryption or decryption mode is selected when the key schedule is setup by mantis_set_key(). The mode can also be altered on the fly by calling mantis_parallel_ecb_swap_modes().

Definition at line 92 of file mantis-parallel.c.

int mantis_parallel_ecb_init ( MantisParallelECB_t ecb)

Initializes Mantis in parallel ECB mode.

Parameters
ecbPoints to the parallel ECB control block to initialize.
Returns
Zero if ecb is NULL or there is insufficient memory to create internal data structures, or non-zero if everything is OK.
See Also
mantis_ecb_set_key(), mantis_ecb_encrypt()

Definition at line 49 of file mantis-parallel.c.

int mantis_parallel_ecb_set_key ( MantisParallelECB_t ecb,
const void *  key,
unsigned  size,
unsigned  rounds,
int  mode 
)

Sets the key schedule for a Mantis block cipher in parallel ECB mode.

Parameters
ecbThe parallel ECB control block to set the key on.
keyPoints to the key.
sizeSize of the key, which must be MANTIS_KEY_SIZE.
roundsThe number of rounds to use, between MANTIS_MIN_ROUNDS and MANTIS_MAX_ROUNDS.
modeMANTIS_ENCRYPT or MANTIS_DECRYPT to select the mode the use when mantis_ecb_crypt() is called. The mode can be altered later by calling mantis_parallel_ecb_swap_modes().
Returns
Zero if there is something wrong with the parameters, or 1 if the key has been set.

Definition at line 72 of file mantis-parallel.c.

void mantis_parallel_ecb_swap_modes ( MantisParallelECB_t ecb)

Swaps the encryption and decryption modes on a parallel Mantis key schedule.

Parameters
ecbThe parallel ECB control block to modify.

Definition at line 82 of file mantis-parallel.c.

int mantis_set_key ( MantisKey_t ks,
const void *  key,
unsigned  size,
unsigned  rounds,
int  mode 
)

Sets the key schedule for a Mantis block cipher.

Parameters
ksThe key schedule structure to populate.
keyPoints to the key.
sizeSize of the key, which must be MANTIS_KEY_SIZE.
roundsThe number of rounds to use, between MANTIS_MIN_ROUNDS and MANTIS_MAX_ROUNDS.
modeMANTIS_ENCRYPT or MANTIS_DECRYPT to select the mode the use when mantis_ecb_crypt() is called. The mode can be altered later by calling mantis_swap_modes().
Returns
Zero if there is something wrong with the parameters, or 1 if the key has been set.

The initial tweak value will be all-zeroes. Call mantis_set_tweak() after this function to set a different tweak.

Note
The rounds value will be doubled to get the actual round count. Mantis consists of a set of forward rounds followed by an equal number of reverse rounds.
See Also
mantis_set_tweak(), mantis_swap_modes()

Definition at line 157 of file mantis-cipher.c.

int mantis_set_tweak ( MantisKey_t ks,
const void *  tweak,
unsigned  size 
)

Sets the tweak value for a previously-initialized key schedule.

Parameters
ksThe key schedule to change.
tweakThe new tweak value, or NULL for a zero tweak.
sizeSize of the tweak value; must be MANTIS_TWEAK_SIZE.
Returns
Zero if there is something wrong with the parameters, or 1 if the tweak was changed.
See Also
mantis_set_key()

Definition at line 205 of file mantis-cipher.c.

void mantis_swap_modes ( MantisKey_t ks)

Swaps the encryption and decryption modes on a Mantis key schedule.

Parameters
ksThe key schedule to change.

Definition at line 225 of file mantis-cipher.c.