Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
internal-gift64.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_GIFT64_H
24 #define LW_INTERNAL_GIFT64_H
25 
35 #include <stddef.h>
36 #include <stdint.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
56 #if !defined(GIFT64_LOW_MEMORY)
57 #if defined(__AVR__)
58 #define GIFT64_LOW_MEMORY 1
59 #else
60 #define GIFT64_LOW_MEMORY 0
61 #endif
62 #endif
63 
67 #define GIFT64_BLOCK_SIZE 8
68 
72 typedef struct
73 {
74  uint32_t k[4];
75 #if !GIFT64_LOW_MEMORY
76  uint32_t rk[8];
77 #endif
78 
80 
87 #if GIFT64_LOW_MEMORY
88 #define gift64n_update_round_keys(ks) do { ; } while (0) /* Not needed */
89 #else
91 #endif
92 
99 void gift64n_init(gift64n_key_schedule_t *ks, const unsigned char *key);
100 
111 void gift64n_encrypt
112  (const gift64n_key_schedule_t *ks, unsigned char *output,
113  const unsigned char *input);
114 
125 void gift64n_decrypt
126  (const gift64n_key_schedule_t *ks, unsigned char *output,
127  const unsigned char *input);
128 
129 /* 4-bit tweak values expanded to 16-bit for TweGIFT-64 */
130 #define GIFT64T_TWEAK_0 0x0000
131 #define GIFT64T_TWEAK_1 0xe1e1
132 #define GIFT64T_TWEAK_2 0xd2d2
133 #define GIFT64T_TWEAK_3 0x3333
134 #define GIFT64T_TWEAK_4 0xb4b4
135 #define GIFT64T_TWEAK_5 0x5555
136 #define GIFT64T_TWEAK_6 0x6666
137 #define GIFT64T_TWEAK_7 0x8787
138 #define GIFT64T_TWEAK_8 0x7878
139 #define GIFT64T_TWEAK_9 0x9999
140 #define GIFT64T_TWEAK_10 0xaaaa
141 #define GIFT64T_TWEAK_11 0x4b4b
142 #define GIFT64T_TWEAK_12 0xcccc
143 #define GIFT64T_TWEAK_13 0x2d2d
144 #define GIFT64T_TWEAK_14 0x1e1e
145 #define GIFT64T_TWEAK_15 0xffff
163 void gift64t_encrypt
164  (const gift64n_key_schedule_t *ks, unsigned char *output,
165  const unsigned char *input, uint16_t tweak);
166 
183 void gift64t_decrypt
184  (const gift64n_key_schedule_t *ks, unsigned char *output,
185  const unsigned char *input, uint16_t tweak);
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 
191 #endif
void gift64t_decrypt(const gift64n_key_schedule_t *ks, unsigned char *output, const unsigned char *input, uint16_t tweak)
Decrypts a 64-bit block with TweGIFT-64 (tweakable variant).
Definition: internal-gift64.c:628
Structure of the key schedule for GIFT-64.
Definition: internal-gift64.h:72
void gift64n_update_round_keys(gift64n_key_schedule_t *ks)
Updates the round keys after a change in the base key.
Definition: internal-gift64.c:241
void gift64n_decrypt(const gift64n_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Decrypts a 64-bit block with GIFT-64 (nibble-based).
Definition: internal-gift64.c:601
void gift64n_init(gift64n_key_schedule_t *ks, const unsigned char *key)
Initializes the key schedule for GIFT-64 (nibble-based).
Definition: internal-gift64.c:505
void gift64n_encrypt(const gift64n_key_schedule_t *ks, unsigned char *output, const unsigned char *input)
Encrypts a 64-bit block with GIFT-64 (nibble-based).
Definition: internal-gift64.c:591