23 #include "mantis-cipher.h"
24 #include "mantis-ctr-internal.h"
25 #include "skinny-internal.h"
55 static void mantis_ctr_def_cleanup(
MantisCTR_t *ctr)
64 static int mantis_ctr_def_set_key
65 (
MantisCTR_t *ctr,
const void *key,
unsigned size,
unsigned rounds)
85 static int mantis_ctr_def_set_tweak
86 (
MantisCTR_t *ctr,
const void *tweak,
unsigned tweak_size)
104 static int mantis_ctr_def_set_counter
105 (
MantisCTR_t *ctr,
const void *counter,
unsigned size)
127 static int mantis_ctr_def_encrypt
128 (
void *output,
const void *input,
size_t size,
MantisCTR_t *ctr)
131 uint8_t *out = (uint8_t *)output;
132 const uint8_t *in = (
const uint8_t *)input;
135 if (!output || !input)
146 skinny64_inc_counter(ctx->
counter, 1);
150 skinny64_xor(out, in, ctx->
ecounter);
156 skinny_xor(out, in, ctx->
ecounter, size);
176 static MantisCTRVtable_t
const mantis_ctr_def = {
178 mantis_ctr_def_cleanup,
179 mantis_ctr_def_set_key,
180 mantis_ctr_def_set_tweak,
181 mantis_ctr_def_set_counter,
182 mantis_ctr_def_encrypt
189 const MantisCTRVtable_t *vtable;
196 vtable = &mantis_ctr_def;
197 if (_skinny_has_vec128())
198 vtable = &_mantis_ctr_vec128;
202 return (*(vtable->init))(ctr);
208 const MantisCTRVtable_t *vtable = ctr->
vtable;
209 (*(vtable->cleanup))(ctr);
215 (
MantisCTR_t *ctr,
const void *key,
unsigned size,
unsigned rounds)
218 const MantisCTRVtable_t *vtable = ctr->
vtable;
219 return (*(vtable->set_key))(ctr, key, size, rounds);
228 const MantisCTRVtable_t *vtable = ctr->
vtable;
229 return (*(vtable->set_tweak))(ctr, tweak, tweak_size);
238 const MantisCTRVtable_t *vtable = ctr->
vtable;
239 return (*(vtable->set_counter))(ctr, counter, size);
248 const MantisCTRVtable_t *vtable = ctr->
vtable;
249 return (*(vtable->encrypt))(output, input, size, ctr);
#define MANTIS_ENCRYPT
Mode that selects Mantis encryption when the key schedule is setup.
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.
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.
int mantis_set_tweak(MantisKey_t *ks, const void *tweak, unsigned size)
Sets the tweak value for a previously-initialized key schedule.
#define MANTIS_BLOCK_SIZE
Size of a block for Mantis block ciphers.
void mantis_ctr_cleanup(MantisCTR_t *ctr)
Cleans up a CTR control block for Mantis.
int mantis_ctr_init(MantisCTR_t *ctr)
Initializes Mantis in CTR mode.
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.
State information for Mantis in CTR mode.
int mantis_ctr_set_counter(MantisCTR_t *ctr, const void *counter, unsigned size)
Sets the counter value in a Mantis CTR control block.
int mantis_ctr_set_tweak(MantisCTR_t *ctr, const void *tweak, unsigned tweak_size)
Changes the tweak value for a previously-initialized key schedule.
Key schedule for Mantis block ciphers.
unsigned char ecounter[MANTIS_BLOCK_SIZE]
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.
unsigned char counter[MANTIS_BLOCK_SIZE]