n2n/include/speck.h

81 lines
1.6 KiB
C
Raw Permalink Normal View History

2020-06-07 18:09:57 +05:30
// cipher SPECK -- 128 bit block size -- 256 bit key size
// taken from (and modified: removed pure crypto-stream generation and seperated key expansion)
// https://github.com/nsacyber/simon-speck-supercop/blob/master/crypto_stream/speck128256ctr/
2020-06-16 13:12:38 +05:30
#ifndef SPECK_H
#define SPECK_H
#include <stdint.h>
2020-06-07 19:21:58 +05:30
#define u32 uint32_t
2020-05-28 03:02:21 +05:30
#define u64 uint64_t
2020-06-05 01:28:57 +05:30
#if defined (__AVX2__)
2020-06-06 17:55:54 +05:30
#define SPECK_ALIGNED_CTX 32
#include <immintrin.h>
#define u256 __m256i
2020-06-05 01:28:57 +05:30
typedef struct {
2020-06-07 18:09:57 +05:30
u256 rk[34];
u64 key[34];
2020-06-05 01:28:57 +05:30
} speck_context_t;
2020-06-06 17:55:54 +05:30
2020-06-05 01:28:57 +05:30
#elif defined (__SSE4_2__)
2020-06-06 17:55:54 +05:30
#define SPECK_ALIGNED_CTX 16
#define SPECK_CTX_BYVAL 1
#include <immintrin.h>
#define u128 __m128i
2020-06-03 21:42:49 +05:30
typedef struct {
2020-06-07 18:09:57 +05:30
u128 rk[34];
u64 key[34];
2020-06-03 21:42:49 +05:30
} speck_context_t;
2020-06-06 17:55:54 +05:30
#elif defined (__ARM_NEON)
2020-06-06 17:55:54 +05:30
#include <arm_neon.h>
#define u128 uint64x2_t
typedef struct {
2020-06-07 18:09:57 +05:30
u128 rk[34];
u64 key[34];
} speck_context_t;
2020-06-06 17:55:54 +05:30
2020-06-03 21:42:49 +05:30
#else
2020-06-06 17:55:54 +05:30
2020-06-03 21:55:49 +05:30
typedef struct {
2020-06-07 18:09:57 +05:30
u64 key[34];
2020-06-03 21:55:49 +05:30
} speck_context_t;
2020-06-06 17:55:54 +05:30
2020-06-03 21:42:49 +05:30
#endif
2020-06-06 17:55:54 +05:30
int speck_ctr (unsigned char *out, const unsigned char *in, unsigned long long inlen,
2020-05-28 03:02:21 +05:30
const unsigned char *n,
2020-06-06 17:55:54 +05:30
#if defined (SPECK_CTX_BYVAL)
speck_context_t ctx);
#else
2020-06-07 18:09:57 +05:30
speck_context_t *ctx);
2020-06-06 17:55:54 +05:30
#endif
2020-05-28 03:02:21 +05:30
2020-06-03 22:52:40 +05:30
int speck_expand_key (const unsigned char *k, speck_context_t *ctx);
2020-06-15 12:38:37 +05:30
int speck_he (unsigned char *out, const unsigned char *in, unsigned long long inlen,
const unsigned char *n, speck_context_t *ctx);
int speck_expand_key_he (const unsigned char *k, speck_context_t *ctx);
2020-06-16 13:12:38 +05:30
int speck_he_iv_encrypt (unsigned char *inout, speck_context_t *ctx);
int speck_he_iv_decrypt (unsigned char *inout, speck_context_t *ctx);
int speck_expand_key_he_iv (const unsigned char *k, speck_context_t *ctx);
2020-06-16 13:12:38 +05:30
#endif