Skinny-C
 All Data Structures Files Functions Variables Groups Pages
mantis-cipher.h
1 /*
2  * Copyright (C) 2017 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 MANTIS_CIPHER_h
24 #define MANTIS_CIPHER_h
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
59 #define MANTIS_BLOCK_SIZE 8
60 
64 #define MANTIS_KEY_SIZE 16
65 
69 #define MANTIS_TWEAK_SIZE 8
70 
77 #define MANTIS_MIN_ROUNDS 5
78 
82 #define MANTIS_MAX_ROUNDS 8
83 
87 #define MANTIS_ENCRYPT 1
88 
92 #define MANTIS_DECRYPT 0
93 
97 typedef union
98 {
99  uint16_t row[4];
100  uint32_t lrow[2];
101  uint64_t llrow;
103 } MantisCells_t;
104 
108 typedef struct
109 {
112 
115 
118 
121 
123  unsigned rounds;
124 
125 } MantisKey_t;
126 
130 typedef struct
131 {
133  const void *vtable;
134 
136  void *ctx;
137 
138 } MantisCTR_t;
139 
164 int mantis_set_key
165  (MantisKey_t *ks, const void *key, unsigned size,
166  unsigned rounds, int mode);
167 
180 int mantis_set_tweak(MantisKey_t *ks, const void *tweak, unsigned size);
181 
188 
207 void mantis_ecb_crypt(void *output, const void *input, const MantisKey_t *ks);
208 
235  (void *output, const void *input, const void *tweak, const MantisKey_t *ks);
236 
249 int mantis_ctr_init(MantisCTR_t *ctr);
250 
257 
277  (MantisCTR_t *ctr, const void *key, unsigned size, unsigned rounds);
278 
299  (MantisCTR_t *ctr, const void *tweak, unsigned tweak_size);
300 
325  (MantisCTR_t *ctr, const void *counter, unsigned size);
326 
341  (void *output, const void *input, size_t size, MantisCTR_t *ctr);
342 
345 #ifdef __cplusplus
346 }
347 #endif
348 
349 #endif
void mantis_swap_modes(MantisKey_t *ks)
Swaps the encryption and decryption modes on a Mantis key schedule.
int mantis_ctr_encrypt(void *output, const void *input, size_t size, MantisCTR_t *ctr)
Encrypt a block of data using Mantis in CTR mode.
Definition: mantis-ctr.c:245
void mantis_ecb_crypt(void *output, const void *input, const MantisKey_t *ks)
Encrypts or decrypts a single block using the Mantis block cipher in ECB mode.
MantisCells_t tweak
int mantis_set_tweak(MantisKey_t *ks, const void *tweak, unsigned size)
Sets the tweak value for a previously-initialized key schedule.
MantisCells_t k1
unsigned rounds
void mantis_ctr_cleanup(MantisCTR_t *ctr)
Cleans up a CTR control block for Mantis.
Definition: mantis-ctr.c:205
int mantis_ctr_init(MantisCTR_t *ctr)
Initializes Mantis in CTR mode.
Definition: mantis-ctr.c:187
const void * vtable
int mantis_set_key(MantisKey_t *ks, const void *key, unsigned size, unsigned rounds, int mode)
Sets the key schedule for a Mantis block cipher.
uint64_t llrow
MantisCells_t k0prime
State information for Mantis in CTR mode.
int mantis_ctr_set_counter(MantisCTR_t *ctr, const void *counter, unsigned size)
Sets the counter value in a Mantis CTR control block.
Definition: mantis-ctr.c:235
int mantis_ctr_set_tweak(MantisCTR_t *ctr, const void *tweak, unsigned tweak_size)
Changes the tweak value for a previously-initialized key schedule.
Definition: mantis-ctr.c:225
Key schedule for Mantis block ciphers.
int mantis_ctr_set_key(MantisCTR_t *ctr, const void *key, unsigned size, unsigned rounds)
Sets the key schedule for a Mantis block cipher in CTR mode.
Definition: mantis-ctr.c:215
MantisCells_t k0
void mantis_ecb_crypt_tweaked(void *output, const void *input, const void *tweak, const MantisKey_t *ks)
Encrypts or decrypts a single block using the Mantis block cipher in ECB mode, with the tweak supplie...
Union that describes a 64-bit 4x4 array of cells.
Definition: mantis-cipher.h:97