Create speck.h

a not good speck.h
This commit is contained in:
laiwei360735
2017-03-20 17:15:36 +08:00
committed by GitHub
parent d2254170b8
commit 8f7bdcd4b0

48
demos/mycipher/speck.h Normal file
View File

@@ -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 <sys/types.h>
#include <stdint.h>
#include <string.h>
#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