Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
ascon-permutation.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 LWCRYPTO_ASCON_PERMUTATION_H
24 #define LWCRYPTO_ASCON_PERMUTATION_H
25 
26 #include <stdint.h>
27 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
63 #define ASCON_STATE_SIZE 40
64 
68 #define ASCON_MAX_ROUNDS 12
69 
76 typedef union
77 {
78  uint64_t S[ASCON_STATE_SIZE / 8];
79  uint32_t W[ASCON_STATE_SIZE / 4];
80  uint8_t B[ASCON_STATE_SIZE];
83 
92 
101 
110 
125 void ascon_add_byte
126  (ascon_permutation_state_t *state, unsigned char data, unsigned offset);
127 
147 void ascon_add_bytes
148  (ascon_permutation_state_t *state, const unsigned char *data,
149  unsigned offset, unsigned length);
150 
171  (ascon_permutation_state_t *state, const unsigned char *data,
172  unsigned offset, unsigned length);
173 
190  (ascon_permutation_state_t *state, unsigned count);
191 
206 void ascon_permute_n_rounds(ascon_permutation_state_t *state, unsigned rounds);
207 
218 
239  (const ascon_permutation_state_t *state, unsigned char *data,
240  unsigned offset, unsigned length);
241 
272  (const ascon_permutation_state_t *state, const unsigned char *input,
273  unsigned char *output, unsigned offset, unsigned length);
274 
308  (ascon_permutation_state_t *state, const unsigned char *input,
309  unsigned char *output, unsigned offset, unsigned length, int padded);
310 
344  (ascon_permutation_state_t *state, const unsigned char *input,
345  unsigned char *output, unsigned offset, unsigned length, int padded);
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 
351 #endif
void ascon_add_bytes(ascon_permutation_state_t *state, const unsigned char *data, unsigned offset, unsigned length)
Adds bytes to the state by XOR'ing them with the existing bytes.
Definition: ascon-permutation.c:76
#define ASCON_STATE_SIZE
Size of the ASCON permutation state in bytes.
Definition: ascon-permutation.h:63
void ascon_encrypt_bytes(ascon_permutation_state_t *state, const unsigned char *input, unsigned char *output, unsigned offset, unsigned length, int padded)
Encrypts bytes by XOR'ing them with the state and then adding the encrypted version back to the state...
Definition: ascon-permutation.c:295
Structure of the internal state of the ASCON permutation.
Definition: ascon-permutation.h:76
void ascon_extract_and_add_bytes(const ascon_permutation_state_t *state, const unsigned char *input, unsigned char *output, unsigned offset, unsigned length)
Extracts bytes from an ASCON state and XOR's them with input data.
Definition: ascon-permutation.c:251
void ascon_extract_bytes(const ascon_permutation_state_t *state, unsigned char *data, unsigned offset, unsigned length)
Extracts bytes from an ASCON state.
Definition: ascon-permutation.c:210
void ascon_permute_n_rounds(ascon_permutation_state_t *state, unsigned rounds)
Performs N rounds of the ASCON permutation.
Definition: ascon-permutation.c:186
void ascon_decrypt_bytes(ascon_permutation_state_t *state, const unsigned char *input, unsigned char *output, unsigned offset, unsigned length, int padded)
Decrypts bytes by XOR'ing them with the state and then overwriting the state with the original cipher...
Definition: ascon-permutation.c:363
void ascon_overwrite_bytes(ascon_permutation_state_t *state, const unsigned char *data, unsigned offset, unsigned length)
Writes bytes to the state, overwriting any existing bytes.
Definition: ascon-permutation.c:119
void ascon_to_operational(ascon_permutation_state_t *state)
Converts an ASCON state from traditional mode to operational mode.
Definition: ascon-permutation.c:44
void ascon_permute_all_rounds(ascon_permutation_state_t *state)
Performs all 12 rounds of the ASCON permutation.
Definition: ascon-permutation.c:200
void ascon_init(ascon_permutation_state_t *state)
Initializes an ASCON state to all-zeroes.
Definition: ascon-permutation.c:30
void ascon_from_operational(ascon_permutation_state_t *state)
Converts an ASCON state from operational mode to traditional mode.
Definition: ascon-permutation.c:35
void ascon_add_byte(ascon_permutation_state_t *state, unsigned char data, unsigned offset)
Adds a single byte to the state by XOR'ing it with the existing byte.
Definition: ascon-permutation.c:54
void ascon_overwrite_with_zeroes(ascon_permutation_state_t *state, unsigned count)
Overwrites the leading part of the state with zeroes.
Definition: ascon-permutation.c:162