Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
internal-gift128-m.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_M_H
24 #define LW_INTERNAL_GIFT128_M_H
25 
31 #include "internal-masking.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
41 #define GIFT128_MASKED_BLOCK_SIZE 16
42 
47 #if GIFT128_VARIANT == GIFT128_VARIANT_TINY
48 #define GIFT128_MASKED_ROUND_KEYS 4
49 #elif GIFT128_VARIANT == GIFT128_VARIANT_SMALL
50 #define GIFT128_MASKED_ROUND_KEYS 20
51 #else
52 #define GIFT128_MASKED_ROUND_KEYS 80
53 #endif
54 
58 typedef struct
59 {
62 
64 
72  (gift128b_masked_key_schedule_t *ks, const unsigned char *key);
73 
85  (const gift128b_masked_key_schedule_t *ks, unsigned char *output,
86  const unsigned char *input);
87 
103  (const gift128b_masked_key_schedule_t *ks, mask_uint32_t output[4],
104  const mask_uint32_t input[4]);
105 
117  (const gift128b_masked_key_schedule_t *ks, unsigned char *output,
118  const unsigned char *input);
119 
124 
132  (gift128n_masked_key_schedule_t *ks, const unsigned char *key);
133 
145  (const gift128n_masked_key_schedule_t *ks, unsigned char *output,
146  const unsigned char *input);
147 
159  (const gift128n_masked_key_schedule_t *ks, unsigned char *output,
160  const unsigned char *input);
161 
162 /* 4-bit tweak values expanded to 32-bit for TweGIFT-128 */
163 #define GIFT128TM_TWEAK_0 0x00000000
164 #define GIFT128TM_TWEAK_1 0xe1e1e1e1
165 #define GIFT128TM_TWEAK_2 0xd2d2d2d2
166 #define GIFT128TM_TWEAK_3 0x33333333
167 #define GIFT128TM_TWEAK_4 0xb4b4b4b4
168 #define GIFT128TM_TWEAK_5 0x55555555
169 #define GIFT128TM_TWEAK_6 0x66666666
170 #define GIFT128TM_TWEAK_7 0x87878787
171 #define GIFT128TM_TWEAK_8 0x78787878
172 #define GIFT128TM_TWEAK_9 0x99999999
173 #define GIFT128TM_TWEAK_10 0xaaaaaaaa
174 #define GIFT128TM_TWEAK_11 0x4b4b4b4b
175 #define GIFT128TM_TWEAK_12 0xcccccccc
176 #define GIFT128TM_TWEAK_13 0x2d2d2d2d
177 #define GIFT128TM_TWEAK_14 0x1e1e1e1e
178 #define GIFT128TM_TWEAK_15 0xffffffff
196 void gift128t_encrypt_masked
197  (const gift128n_masked_key_schedule_t *ks, unsigned char *output,
198  const unsigned char *input, uint32_t tweak);
199 
217  (const gift128n_masked_key_schedule_t *ks, unsigned char *output,
218  const unsigned char *input, uint32_t tweak);
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif
void gift128n_decrypt_masked(const gift128n_masked_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Decrypts a 128-bit block with masked GIFT-128 (nibble-based).
Definition: internal-gift128-m.c:355
gift128b_masked_key_schedule_t gift128n_masked_key_schedule_t
Structure of the key schedule for masked GIFT-128 (nibble-based).
Definition: internal-gift128-m.h:123
void gift128n_encrypt_masked(const gift128n_masked_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Encrypts a 128-bit block with masked GIFT-128 (nibble-based).
Definition: internal-gift128-m.c:346
void gift128b_decrypt_masked(const gift128b_masked_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Decrypts a 128-bit block with masked GIFT-128 (bit-sliced).
Definition: internal-gift128-m.c:1300
#define GIFT128_MASKED_ROUND_KEYS
Number of round keys for the GIFT-128 key schedule.
Definition: internal-gift128-m.h:52
void gift128b_init_masked(gift128b_masked_key_schedule_t *ks, const unsigned char *key)
Initializes the key schedule for masked GIFT-128 (bit-sliced).
Definition: internal-gift128-m.c:568
Utilities that help to implement masked ciphers.
void gift128t_decrypt_masked(const gift128n_masked_key_schedule_t *ks, unsigned char *output, const unsigned char *input, uint32_t tweak)
Decrypts a 128-bit block with masked TweGIFT-128 (tweakable variant).
Definition: internal-gift128-m.c:1327
Masked 32-bit word with four shares.
Definition: internal-masking.h:152
Configures the variant of GIFT-128 to use.
Structure of the key schedule for masked GIFT-128 (bit-sliced).
Definition: internal-gift128-m.h:58
void gift128b_encrypt_preloaded_masked(const gift128b_masked_key_schedule_t *ks, mask_uint32_t output[4], const mask_uint32_t input[4])
Encrypts a block with masked GIFT-128 (bit-sliced and pre-loaded).
Definition: internal-gift128-m.c:1051
void gift128b_encrypt_masked(const gift128b_masked_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Encrypts a 128-bit block with masked GIFT-128 (bit-sliced).
Definition: internal-gift128-m.c:1024
void gift128n_init_masked(gift128n_masked_key_schedule_t *ks, const unsigned char *key)
Initializes the key schedule for masked GIFT-128 (nibble-based).
Definition: internal-gift128-m.c:576