Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
internal-tinyjambu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 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_TINYJAMBU_H
24 #define LW_INTERNAL_TINYJAMBU_H
25 
26 #include "internal-util.h"
27 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
38 #if defined(LW_UTIL_CPU_IS_64BIT)
39 #define TINY_JAMBU_64BIT 1
40 #else
41 #define TINY_JAMBU_64BIT 0
42 #endif
43 
48 typedef struct
49 {
50 #if TINY_JAMBU_64BIT
51  uint64_t t[2];
52 #else
53  uint32_t s[4];
54 #endif
56 
61 #if TINY_JAMBU_64BIT
62 typedef uint64_t tiny_jambu_key_word_t;
63 #else
64 typedef uint32_t tiny_jambu_key_word_t;
65 #endif
66 
81 #if TINY_JAMBU_64BIT
82 #define tiny_jambu_key_load_even(ptr) \
83  ((tiny_jambu_key_word_t)(~(le_load_word32((ptr)))))
84 #define tiny_jambu_key_load_odd(ptr) \
85  (((tiny_jambu_key_word_t)(~(le_load_word32((ptr))))) << 32)
86 #else
87 #define tiny_jambu_key_load_even(ptr) \
88  ((tiny_jambu_key_word_t)(~(le_load_word32((ptr)))))
89 #define tiny_jambu_key_load_odd(ptr) \
90  ((tiny_jambu_key_word_t)(~(le_load_word32((ptr)))))
91 #endif
92 
120 #if TINY_JAMBU_64BIT
121 #define tiny_jambu_init_state(state) \
122  ((state)->t[0] = (state)->t[1] = 0)
123 #define tiny_jambu_add_domain(state, domain) \
124  ((state)->t[0] ^= ((uint64_t)(domain)) << 32)
125 #define tiny_jambu_absorb(state, word) \
126  ((state)->t[1] ^= ((uint64_t)(word)) << 32)
127 #define tiny_jambu_squeeze(state) ((uint32_t)((state)->t[1]))
128 #else
129 #define tiny_jambu_init_state(state) \
130  ((state)->s[0] = (state)->s[1] = (state)->s[2] = (state)->s[3] = 0)
131 #define tiny_jambu_add_domain(state, domain) \
132  ((state)->s[1] ^= (domain))
133 #define tiny_jambu_absorb(state, word) \
134  ((state)->s[3] ^= (word))
135 #define tiny_jambu_squeeze(state) ((state)->s[2])
136 #endif
137 
146 #define TINYJAMBU_ROUNDS(steps) ((steps) / 128)
147 
160  (tiny_jambu_state_t *state, const tiny_jambu_key_word_t *key,
161  unsigned rounds);
162 
175  (tiny_jambu_state_t *state, const tiny_jambu_key_word_t *key,
176  unsigned rounds);
177 
190  (tiny_jambu_state_t *state, const tiny_jambu_key_word_t *key,
191  unsigned rounds);
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 #endif
TinyJAMBU permutation state.
Definition: internal-tinyjambu.h:48
void tiny_jambu_permutation_128(tiny_jambu_state_t *state, const tiny_jambu_key_word_t *key, unsigned rounds)
Perform the TinyJAMBU-128 permutation.
Definition: internal-tinyjambu.c:52
uint32_t tiny_jambu_key_word_t
Size of a word in the key schedule (32 or 64 bits).
Definition: internal-tinyjambu.h:64
void tiny_jambu_permutation_256(tiny_jambu_state_t *state, const tiny_jambu_key_word_t *key, unsigned rounds)
Perform the TinyJAMBU-256 permutation.
Definition: internal-tinyjambu.c:138
void tiny_jambu_permutation_192(tiny_jambu_state_t *state, const tiny_jambu_key_word_t *key, unsigned rounds)
Perform the TinyJAMBU-192 permutation.
Definition: internal-tinyjambu.c:90