Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
internal-subterranean.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_SUBTERRANEAN_H
24 #define LW_INTERNAL_SUBTERRANEAN_H
25 
26 #include "internal-util.h"
27 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
45 typedef struct
46 {
47  uint32_t x[9];
50 
57 
65 
71 #define subterranean_duplex_0(state) \
72  do { \
73  subterranean_round((state)); \
74  (state)->x[0] ^= 2; /* padding for an empty block */ \
75  } while (0)
76 
83 void subterranean_absorb_1(subterranean_state_t *state, unsigned char data);
84 
91 #define subterranean_duplex_1(state, data) \
92  do { \
93  subterranean_round((state)); \
94  subterranean_absorb_1((state), (data)); \
95  } while (0)
96 
103 void subterranean_absorb_word(subterranean_state_t *state, uint32_t x);
104 
112 #define subterranean_duplex_word(state, x) \
113  do { \
114  subterranean_round((state)); \
115  subterranean_absorb_word((state), (x)); \
116  } while (0)
117 
124 #define subterranean_duplex_4(state, data) \
125  do { \
126  subterranean_duplex_word((state), (data)); \
127  (state)->x[8] ^= 1; \
128  } while (0)
129 
139  (subterranean_state_t *state, const unsigned char *data, unsigned len);
140 
149 
158  (subterranean_state_t *state, const unsigned char *data,
159  unsigned long long len);
160 
169  (subterranean_state_t *state, unsigned char *data, unsigned len);
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif
Representation of the 257-bit state of Subterranean.
Definition: internal-subterranean.h:45
void subterranean_absorb(subterranean_state_t *state, const unsigned char *data, unsigned long long len)
Absorbs an arbitrary amount of data, four bytes at a time.
Definition: internal-subterranean.c:396
void subterranean_absorb_word(subterranean_state_t *state, uint32_t x)
Absorbs a 32-bit word into the Subterranean state.
Definition: internal-subterranean.c:187
void subterranean_squeeze(subterranean_state_t *state, unsigned char *data, unsigned len)
Squeezes an arbitrary amount of data out of a Subterranean state.
Definition: internal-subterranean.c:408
uint32_t subterranean_extract(subterranean_state_t *state)
Extracts 32 bits of output from the Subterranean state.
Definition: internal-subterranean.c:242
void subterranean_duplex_n(subterranean_state_t *state, const unsigned char *data, unsigned len)
Performs a single Subterranean round and absorbs between zero and four bytes.
Definition: internal-subterranean.c:362
void subterranean_blank(subterranean_state_t *state)
Performs 8 Subterranean rounds with no absorption or squeezing of data; i.e. data input and output is...
Definition: internal-subterranean.c:352
void subterranean_absorb_1(subterranean_state_t *state, unsigned char data)
Absorbs a single byte into the Subterranean state.
Definition: internal-subterranean.c:173
void subterranean_round(subterranean_state_t *state)
Performs a single Subterranean round.
Definition: internal-subterranean.c:28