speck/speck.h

91 lines
2.4 KiB
C
Raw Normal View History

2016-01-27 22:26:26 +00:00
/*
Copyright (c) 2016, Moritz Bitsch
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef SPECK_H
#define SPECK_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define MASK24 0xFFFFFF
#define MASK48 0xFFFFFFFFFFFF
2016-01-27 22:26:26 +00:00
/*
* define speck type to use (one of SPECK_32_64, SPECK_64_128, SPECK_128_256)
*/
#define SPECK_32_64
#ifdef SPECK_32_64
#define SPECK_TYPE uint16_t
#define SPECK_ROUNDS 22
#define SPECK_KEY_LEN 4
#endif
#ifdef SPECK_48_72
#define SPECK_TYPE uint32_t
#define SPECK_ROUNDS 22
#define SPECK_KEY_LEN 3
#define WORDSIZE 24
#endif
#ifdef SPECK_48_96
#define SPECK_TYPE uint32_t
#define SPECK_ROUNDS 23
#define SPECK_KEY_LEN 4
#define WORDSIZE 24
#endif
2016-01-27 22:26:26 +00:00
#ifdef SPECK_64_128
#define SPECK_TYPE uint32_t
#define SPECK_ROUNDS 27
#define SPECK_KEY_LEN 4
#endif
#ifdef SPECK_96_96
#define SPECK_TYPE uint64_t
#define SPECK_ROUNDS 28
#define SPECK_KEY_LEN 2
#define WORDSIZE 48
#endif
#ifdef SPECK_96_144
#define SPECK_TYPE uint64_t
#define SPECK_ROUNDS 29
#define SPECK_KEY_LEN 3
#define WORDSIZE 48
#endif
2016-01-27 22:26:26 +00:00
#ifdef SPECK_128_256
#define SPECK_TYPE uint64_t
#define SPECK_ROUNDS 34
#define SPECK_KEY_LEN 4
#endif
void speck_expand(SPECK_TYPE const K[static SPECK_KEY_LEN], SPECK_TYPE S[static SPECK_ROUNDS]);
2016-01-27 22:26:26 +00:00
void speck_encrypt(SPECK_TYPE const pt[static 2], SPECK_TYPE ct[static 2], SPECK_TYPE const K[static SPECK_ROUNDS]);
void speck_decrypt(SPECK_TYPE const ct[static 2], SPECK_TYPE pt[static 2], SPECK_TYPE const K[static SPECK_ROUNDS]);
void speck_encrypt_combined(SPECK_TYPE const pt[static 2], SPECK_TYPE ct[static 2], SPECK_TYPE const K[static SPECK_KEY_LEN]);
void speck_decrypt_combined(SPECK_TYPE const ct[static 2], SPECK_TYPE pt[static 2], SPECK_TYPE const K[static SPECK_KEY_LEN]);
2016-01-27 22:26:26 +00:00
#ifdef __cplusplus
}
#endif
#endif