Skinny-C
 All Data Structures Files Functions Variables Groups Pages
skinny64-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 SKINNY64_CIPHER_h
24 #define SKINNY64_CIPHER_h
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
47 #define SKINNY64_BLOCK_SIZE 8
48 
52 #define SKINNY64_MAX_ROUNDS 40
53 
57 typedef union
58 {
59  uint16_t row[4];
60  uint32_t lrow[2];
61  uint64_t llrow;
64 
68 typedef union
69 {
70  uint16_t row[2];
71  uint32_t lrow;
74 
78 typedef struct
79 {
81  unsigned rounds;
82 
85 
87 
91 typedef struct
92 {
95 
97  uint8_t tweak[SKINNY64_BLOCK_SIZE];
98 
100 
104 typedef struct
105 {
107  const void *vtable;
108 
110  void *ctx;
111 
112 } Skinny64CTR_t;
113 
127 int skinny64_set_key(Skinny64Key_t *ks, const void *key, unsigned size);
128 
150  (Skinny64TweakedKey_t *ks, const void *key, unsigned key_size);
151 
168  (Skinny64TweakedKey_t *ks, const void *tweak, unsigned tweak_size);
169 
182  (void *output, const void *input, const Skinny64Key_t *ks);
183 
196  (void *output, const void *input, const Skinny64Key_t *ks);
197 
211 
218 
236 int skinny64_ctr_set_key(Skinny64CTR_t *ctr, const void *key, unsigned size);
237 
263  (Skinny64CTR_t *ctr, const void *key, unsigned key_size);
264 
285  (Skinny64CTR_t *ctr, const void *tweak, unsigned tweak_size);
286 
311  (Skinny64CTR_t *ctr, const void *counter, unsigned size);
312 
327  (void *output, const void *input, size_t size, Skinny64CTR_t *ctr);
328 
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 #endif
const void * vtable
void skinny64_ctr_cleanup(Skinny64CTR_t *ctr)
Cleans up a CTR control block for Skinny-64.
Definition: skinny64-ctr.c:227
int skinny64_set_tweak(Skinny64TweakedKey_t *ks, const void *tweak, unsigned tweak_size)
Changes the tweak value for a previously-initialized key schedule.
int skinny64_ctr_set_key(Skinny64CTR_t *ctr, const void *key, unsigned size)
Sets the key schedule for a Skinny64 block cipher in CTR mode.
Definition: skinny64-ctr.c:236
int skinny64_set_key(Skinny64Key_t *ks, const void *key, unsigned size)
Sets the key schedule for a Skinny64 block cipher.
int skinny64_ctr_init(Skinny64CTR_t *ctr)
Initializes Skinny-64 in CTR mode.
Definition: skinny64-ctr.c:209
int skinny64_ctr_encrypt(void *output, const void *input, size_t size, Skinny64CTR_t *ctr)
Encrypt a block of data using Skinny-64 in CTR mode.
Definition: skinny64-ctr.c:276
int skinny64_set_tweaked_key(Skinny64TweakedKey_t *ks, const void *key, unsigned key_size)
Sets the key schedule for a Skinny64 block cipher, and prepare for tweaked encryption.
Key schedule for Skinny64 block ciphers when a tweak is in use.
void skinny64_ecb_decrypt(void *output, const void *input, const Skinny64Key_t *ks)
Decrypts a single block using the Skinny64 block cipher in ECB mode.
#define SKINNY64_MAX_ROUNDS
Maximum number of rounds for Skinny64 block ciphers.
void skinny64_ecb_encrypt(void *output, const void *input, const Skinny64Key_t *ks)
Encrypts a single block using the Skinny64 block cipher in ECB mode.
int skinny64_ctr_set_counter(Skinny64CTR_t *ctr, const void *counter, unsigned size)
Sets the counter value in a Skinny-64 CTR control block.
Definition: skinny64-ctr.c:266
Key schedule for Skinny64 block ciphers.
Union that describes a 32-bit 2x4 array of cells.
#define SKINNY64_BLOCK_SIZE
Size of a block for Skinny64 block ciphers.
State information for Skinny-64 in CTR mode.
int skinny64_ctr_set_tweak(Skinny64CTR_t *ctr, const void *tweak, unsigned tweak_size)
Changes the tweak value for a previously-initialized key schedule.
Definition: skinny64-ctr.c:256
Union that describes a 64-bit 4x4 array of cells.
int skinny64_ctr_set_tweaked_key(Skinny64CTR_t *ctr, const void *key, unsigned key_size)
Sets the key schedule for a Skinny64 block cipher in CTR mode, and prepare for tweaked encryption...
Definition: skinny64-ctr.c:246