From 775e3dc3f082602269c3e347b8c763af42ca4185 Mon Sep 17 00:00:00 2001 From: laiwei360735 <1655919897@qq.com> Date: Mon, 20 Mar 2017 17:15:36 +0800 Subject: [PATCH] Create speck.h a not good speck.h --- demos/mycipher/speck.h | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 demos/mycipher/speck.h diff --git a/demos/mycipher/speck.h b/demos/mycipher/speck.h new file mode 100644 index 00000000..7307955c --- /dev/null +++ b/demos/mycipher/speck.h @@ -0,0 +1,48 @@ +#ifndef SPECK_H +#define SPECK_H + +/* +* 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_64_128 +#define SPECK_TYPE uint32_t +#define SPECK_ROUNDS 27 +#define SPECK_KEY_LEN 4 +#endif + +#ifdef SPECK_128_256 +#define SPECK_TYPE uint64_t +#define SPECK_ROUNDS 34 +#define SPECK_KEY_LEN 4 +#endif + +#define num_word sizeof(SPECK_TYPE) +#include +#include +#include +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct { + unsigned char rk[num_word]; + } mycipher_key_t; + + void mycipher_set_encrypt_key(mycipher_key_t *key, const unsigned char *user_key); + void speck_expand(SPECK_TYPE const K[SPECK_KEY_LEN], SPECK_TYPE S[SPECK_ROUNDS]); + void speck_encrypt(SPECK_TYPE const pt[2], SPECK_TYPE ct[2], SPECK_TYPE const K[SPECK_ROUNDS]); + void speck_decrypt(SPECK_TYPE const ct[2], SPECK_TYPE pt[2], SPECK_TYPE const K[SPECK_ROUNDS]); + +#ifdef __cplusplus +} +#endif +#endif