Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
internal-gift128.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 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 LW_INTERNAL_GIFT128_H
24 #define LW_INTERNAL_GIFT128_H
25 
54 #include <stddef.h>
55 #include <stdint.h>
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
65 #define GIFT128_BLOCK_SIZE 16
66 
71 #if GIFT128_VARIANT == GIFT128_VARIANT_TINY
72 #define GIFT128_ROUND_KEYS 4
73 #elif GIFT128_VARIANT == GIFT128_VARIANT_SMALL
74 #define GIFT128_ROUND_KEYS 20
75 #else
76 #define GIFT128_ROUND_KEYS 80
77 #endif
78 
82 typedef struct
83 {
85  uint32_t k[GIFT128_ROUND_KEYS];
86 
88 
95 void gift128b_init(gift128b_key_schedule_t *ks, const unsigned char *key);
96 
107 void gift128b_encrypt
108  (const gift128b_key_schedule_t *ks, unsigned char *output,
109  const unsigned char *input);
110 
126  (const gift128b_key_schedule_t *ks, uint32_t output[4],
127  const uint32_t input[4]);
128 
139 void gift128b_decrypt
140  (const gift128b_key_schedule_t *ks, unsigned char *output,
141  const unsigned char *input);
142 
147 
154 void gift128n_init(gift128n_key_schedule_t *ks, const unsigned char *key);
155 
166 void gift128n_encrypt
167  (const gift128n_key_schedule_t *ks, unsigned char *output,
168  const unsigned char *input);
169 
180 void gift128n_decrypt
181  (const gift128n_key_schedule_t *ks, unsigned char *output,
182  const unsigned char *input);
183 
184 /* 4-bit tweak values expanded to 32-bit for TweGIFT-128 */
185 #define GIFT128T_TWEAK_0 0x00000000
186 #define GIFT128T_TWEAK_1 0xe1e1e1e1
187 #define GIFT128T_TWEAK_2 0xd2d2d2d2
188 #define GIFT128T_TWEAK_3 0x33333333
189 #define GIFT128T_TWEAK_4 0xb4b4b4b4
190 #define GIFT128T_TWEAK_5 0x55555555
191 #define GIFT128T_TWEAK_6 0x66666666
192 #define GIFT128T_TWEAK_7 0x87878787
193 #define GIFT128T_TWEAK_8 0x78787878
194 #define GIFT128T_TWEAK_9 0x99999999
195 #define GIFT128T_TWEAK_10 0xaaaaaaaa
196 #define GIFT128T_TWEAK_11 0x4b4b4b4b
197 #define GIFT128T_TWEAK_12 0xcccccccc
198 #define GIFT128T_TWEAK_13 0x2d2d2d2d
199 #define GIFT128T_TWEAK_14 0x1e1e1e1e
200 #define GIFT128T_TWEAK_15 0xffffffff
218 void gift128t_encrypt
219  (const gift128n_key_schedule_t *ks, unsigned char *output,
220  const unsigned char *input, uint32_t tweak);
221 
238 void gift128t_decrypt
239  (const gift128n_key_schedule_t *ks, unsigned char *output,
240  const unsigned char *input, uint32_t tweak);
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif
void gift128n_decrypt(const gift128n_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Decrypts a 128-bit block with GIFT-128 (nibble-based).
Definition: internal-gift128.c:271
Structure of the key schedule for GIFT-128 (bit-sliced).
Definition: internal-gift128.h:82
void gift128n_init(gift128n_key_schedule_t *ks, const unsigned char *key)
Initializes the key schedule for GIFT-128 (nibble-based).
Definition: internal-gift128.c:464
void gift128n_encrypt(const gift128n_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Encrypts a 128-bit block with GIFT-128 (nibble-based).
Definition: internal-gift128.c:262
#define GIFT128_ROUND_KEYS
Number of round keys for the GIFT-128 key schedule.
Definition: internal-gift128.h:76
void gift128b_init(gift128b_key_schedule_t *ks, const unsigned char *key)
Initializes the key schedule for GIFT-128 (bit-sliced).
Definition: internal-gift128.c:457
void gift128b_decrypt(const gift128b_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Decrypts a 128-bit block with GIFT-128 (bit-sliced).
Definition: internal-gift128.c:1215
Configures the variant of GIFT-128 to use.
void gift128b_encrypt_preloaded(const gift128b_key_schedule_t *ks, uint32_t output[4], const uint32_t input[4])
Encrypts a 128-bit block with GIFT-128 (bit-sliced and pre-loaded).
Definition: internal-gift128.c:949
void gift128t_decrypt(const gift128n_key_schedule_t *ks, unsigned char *output, const unsigned char *input, uint32_t tweak)
Decrypts a 128-bit block with TweGIFT-128 (tweakable variant).
Definition: internal-gift128.c:1244
gift128b_key_schedule_t gift128n_key_schedule_t
Structure of the key schedule for GIFT-128 (nibble-based).
Definition: internal-gift128.h:146
void gift128b_encrypt(const gift128b_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Encrypts a 128-bit block with GIFT-128 (bit-sliced).
Definition: internal-gift128.c:920