Skinny-C
 All Data Structures Files Functions Variables Groups Pages
skinny128-cipher.h
1 /*
2  * Copyright (C) 2017 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef SKINNY128_CIPHER_h
24 #define SKINNY128_CIPHER_h
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
47 #define SKINNY128_BLOCK_SIZE 16
48 
52 #define SKINNY128_MAX_ROUNDS 56
53 
57 typedef union
58 {
59  uint32_t row[4];
60  uint64_t lrow[2];
63 
67 typedef union
68 {
69  uint32_t row[2];
70  uint64_t lrow;
73 
77 typedef struct
78 {
80  unsigned rounds;
81 
84 
86 
90 typedef struct
91 {
94 
96  uint8_t tweak[SKINNY128_BLOCK_SIZE];
97 
99 
103 typedef struct
104 {
106  const void *vtable;
107 
109  void *ctx;
110 
112 
126 int skinny128_set_key(Skinny128Key_t *ks, const void *key, unsigned size);
127 
149  (Skinny128TweakedKey_t *ks, const void *key, unsigned key_size);
150 
167  (Skinny128TweakedKey_t *ks, const void *tweak, unsigned tweak_size);
168 
181  (void *output, const void *input, const Skinny128Key_t *ks);
182 
195  (void *output, const void *input, const Skinny128Key_t *ks);
196 
210 
217 
235 int skinny128_ctr_set_key(Skinny128CTR_t *ctr, const void *key, unsigned size);
236 
262  (Skinny128CTR_t *ctr, const void *key, unsigned key_size);
263 
284  (Skinny128CTR_t *ctr, const void *tweak, unsigned tweak_size);
285 
310  (Skinny128CTR_t *ctr, const void *counter, unsigned size);
311 
326  (void *output, const void *input, size_t size, Skinny128CTR_t *ctr);
327 
330 #ifdef __cplusplus
331 }
332 #endif
333 
334 #endif
Union that describes a 64-bit 2x4 array of cells.
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.
#define SKINNY128_MAX_ROUNDS
Maximum number of rounds for Skinny128 block ciphers.
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.
const void * vtable
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.
Key schedule for Skinny128 block ciphers.
Union that describes a 128-bit 4x4 array of cells.
void skinny128_ecb_decrypt(void *output, const void *input, const Skinny128Key_t *ks)
Decrypts a single block using the Skinny128 block cipher in ECB mode.
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.
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.