Lightweight Cryptography Primitives
 All Data Structures Files Functions Variables Typedefs Macros Pages
internal-grain128.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_GRAIN128_H
24 #define LW_INTERNAL_GRAIN128_H
25 
26 #include "internal-util.h"
27 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
45 typedef struct
46 {
47  uint32_t lfsr[4];
48  uint32_t nfsr[4];
49  uint64_t accum;
50  uint64_t sr;
51  unsigned char ks[16];
52  unsigned posn;
55 
63 void grain128_core
64  (grain128_state_t *state, uint32_t x, uint32_t x2);
65 
73 uint32_t grain128_preoutput(const grain128_state_t *state);
74 
82 void grain128_setup
83  (grain128_state_t *state, const unsigned char *key,
84  const unsigned char *nonce);
85 
94  (grain128_state_t *state, const unsigned char *data,
95  size_t len);
96 
105 void grain128_encrypt
106  (grain128_state_t *state, unsigned char *c, const unsigned char *m,
107  size_t len);
108 
117 void grain128_decrypt
118  (grain128_state_t *state, unsigned char *m, const unsigned char *c,
119  size_t len);
120 
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif
uint64_t sr
Definition: internal-grain128.h:50
void grain128_compute_tag(grain128_state_t *state)
Computes the final authentiation tag.
Definition: internal-grain128.c:465
void grain128_decrypt(grain128_state_t *state, unsigned char *m, const unsigned char *c, size_t len)
Decrypts and authenticates data with Grain-128.
Definition: internal-grain128.c:420
uint32_t grain128_preoutput(const grain128_state_t *state)
Generates 32 bits of pre-output data.
Definition: internal-grain128.c:126
void grain128_encrypt(grain128_state_t *state, unsigned char *c, const unsigned char *m, size_t len)
Encrypts and authenticates data with Grain-128.
Definition: internal-grain128.c:377
unsigned posn
Definition: internal-grain128.h:52
Representation of the state of Grain-128.
Definition: internal-grain128.h:45
void grain128_setup(grain128_state_t *state, const unsigned char *key, const unsigned char *nonce)
Sets up the initial Grain-128 state with the key and nonce.
Definition: internal-grain128.c:207
void grain128_authenticate(grain128_state_t *state, const unsigned char *data, size_t len)
Authenticates data with Grain-128.
Definition: internal-grain128.c:336
uint64_t accum
Definition: internal-grain128.h:49
void grain128_core(grain128_state_t *state, uint32_t x, uint32_t x2)
Performs 32 rounds of Grain-128 in parallel.
Definition: internal-grain128.c:50