23 #include "skinny128-cipher.h"
24 #include "skinny128-ctr-internal.h"
25 #include "skinny-internal.h"
64 static int skinny128_ctr_def_set_key(
Skinny128CTR_t *ctr,
const void *key,
unsigned size)
84 static int skinny128_ctr_def_set_tweaked_key
105 static int skinny128_ctr_def_set_tweak
124 static int skinny128_ctr_def_set_counter
147 static int skinny128_ctr_def_encrypt
148 (
void *output,
const void *input,
size_t size,
Skinny128CTR_t *ctr)
151 uint8_t *out = (uint8_t *)output;
152 const uint8_t *in = (
const uint8_t *)input;
155 if (!output || !input)
166 skinny128_inc_counter(ctx->
counter, 1);
170 skinny128_xor(out, in, ctx->
ecounter);
176 skinny_xor(out, in, ctx->
ecounter, size);
196 static Skinny128CTRVtable_t
const skinny128_ctr_def = {
197 skinny128_ctr_def_init,
198 skinny128_ctr_def_cleanup,
199 skinny128_ctr_def_set_key,
200 skinny128_ctr_def_set_tweaked_key,
201 skinny128_ctr_def_set_tweak,
202 skinny128_ctr_def_set_counter,
203 skinny128_ctr_def_encrypt
210 const Skinny128CTRVtable_t *vtable;
217 vtable = &skinny128_ctr_def;
218 if (_skinny_has_vec128())
219 vtable = &_skinny128_ctr_vec128;
220 if (_skinny_has_vec256())
221 vtable = &_skinny128_ctr_vec256;
225 return (*(vtable->init))(ctr);
231 const Skinny128CTRVtable_t *vtable = ctr->
vtable;
232 (*(vtable->cleanup))(ctr);
240 const Skinny128CTRVtable_t *vtable = ctr->
vtable;
241 return (*(vtable->set_key))(ctr, key, size);
250 const Skinny128CTRVtable_t *vtable = ctr->
vtable;
251 return (*(vtable->set_tweaked_key))(ctr, key, key_size);
260 const Skinny128CTRVtable_t *vtable = ctr->
vtable;
261 return (*(vtable->set_tweak))(ctr, tweak, tweak_size);
270 const Skinny128CTRVtable_t *vtable = ctr->
vtable;
271 return (*(vtable->set_counter))(ctr, counter, size);
280 const Skinny128CTRVtable_t *vtable = ctr->
vtable;
281 return (*(vtable->encrypt))(output, input, size, ctr);
State information for Skinny-128 in CTR mode.
int skinny128_ctr_set_key(Skinny128CTR_t *ctr, const void *key, unsigned size)
Sets the key schedule for a Skinny128 block cipher in CTR mode.
Key schedule for Skinny128 block ciphers when a tweak is in use.
int skinny128_ctr_encrypt(void *output, const void *input, size_t size, Skinny128CTR_t *ctr)
Encrypt a block of data using Skinny-128 in CTR mode.
int skinny128_set_tweaked_key(Skinny128TweakedKey_t *ks, const void *key, unsigned key_size)
Sets the key schedule for a Skinny128 block cipher, and prepare for tweaked encryption.
int skinny128_ctr_set_tweak(Skinny128CTR_t *ctr, const void *tweak, unsigned tweak_size)
Changes the tweak value for a previously-initialized key schedule.
void skinny128_ecb_encrypt(void *output, const void *input, const Skinny128Key_t *ks)
Encrypts a single block using the Skinny128 block cipher in ECB mode.
unsigned char ecounter[SKINNY128_BLOCK_SIZE]
int skinny128_set_key(Skinny128Key_t *ks, const void *key, unsigned size)
Sets the key schedule for a Skinny128 block cipher.
int skinny128_ctr_init(Skinny128CTR_t *ctr)
Initializes Skinny-128 in CTR mode.
#define SKINNY128_BLOCK_SIZE
Size of a block for Skinny128 block ciphers.
int skinny128_ctr_set_counter(Skinny128CTR_t *ctr, const void *counter, unsigned size)
Sets the counter value in a Skinny-128 CTR control block.
unsigned char counter[SKINNY128_BLOCK_SIZE]
int skinny128_set_tweak(Skinny128TweakedKey_t *ks, const void *tweak, unsigned tweak_size)
Changes the tweak value for a previously-initialized key schedule.
int skinny128_ctr_set_tweaked_key(Skinny128CTR_t *ctr, const void *key, unsigned key_size)
Sets the key schedule for a Skinny128 block cipher in CTR mode, and prepare for tweaked encryption...
void skinny128_ctr_cleanup(Skinny128CTR_t *ctr)
Cleans up a CTR control block for Skinny-128.