readability code clean-up (#532)

This commit is contained in:
Logan oos Even 2020-12-19 17:11:32 +05:45 committed by GitHub
parent d063cf3088
commit 1c29fbee8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 512 additions and 467 deletions

View File

@ -17,7 +17,7 @@
*/
// cipher SPECK -- 128 bit block size -- 256 bit key size
// cipher SPECK -- 128 bit block size -- 256 bit key size -- CTR mode
// 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/
@ -25,10 +25,13 @@
#ifndef SPECK_H
#define SPECK_H
#include <stdint.h>
#include <stdlib.h>
#include "portable_endian.h"
#define u32 uint32_t
#define u64 uint64_t
@ -36,45 +39,60 @@
#define SPECK_KEY_BYTES (256/8)
#if defined (__AVX2__)
#if defined (__AVX2__) // AVX support -----------------------------------------------------------------------------
#include <immintrin.h>
#define SPECK_ALIGNED_CTX 32
#define u256 __m256i
#define SPECK_ALIGNED_CTX 32
typedef struct {
u256 rk[34];
u64 key[34];
u256 rk[34];
u64 key[34];
} speck_context_t;
#elif defined (__SSE2__)
#elif defined (__SSE2__) // SSE support ---------------------------------------------------------------------------
#include <immintrin.h>
#define u128 __m128i
#define SPECK_ALIGNED_CTX 16
#define SPECK_CTX_BYVAL 1
#define u128 __m128i
typedef struct {
u128 rk[34];
u64 key[34];
u128 rk[34];
u64 key[34];
} speck_context_t;
#elif defined (__ARM_NEON)
#elif defined (__ARM_NEON) // NEON support ------------------------------------------------------------------------
#include <arm_neon.h>
#define u128 uint64x2_t
typedef struct {
u128 rk[34];
u64 key[34];
} speck_context_t;
#else
typedef struct {
u64 key[34];
u128 rk[34];
u64 key[34];
} speck_context_t;
#endif
// -----
#else // plain C --------------------------------------------------------------------------------------------------
typedef struct {
u64 key[34];
} speck_context_t;
#endif // ---------------------------------------------------------------------------------------------------------
int speck_ctr (unsigned char *out, const unsigned char *in, unsigned long long inlen,
const unsigned char *n,
@ -84,14 +102,29 @@ int speck_init (const unsigned char *k, speck_context_t **ctx);
int speck_deinit (speck_context_t *ctx);
// -----
// ----------------------------------------------------------------------------------------------------------------
// cipher SPECK -- 128 bit block size -- 128 bit key size -- CTR mode
// used for header encryption, thus the postfix '_he'
// for now: just plain C -- AVX, SSE, NEON do not make sense for short header
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);
// -----
// ----------------------------------------------------------------------------------------------------------------
// cipher SPECK -- 96 bit block size -- 96 bit key size -- ECB mode
// follows endianess rules as used in official implementation guide and NOT as in original 2013 cipher presentation
// used for IV in header encryption, thus the in/postfix 'he_iv'
// for now: just plain C -- probably no need for AVX, SSE, NEON
int speck_he_iv_encrypt (unsigned char *inout, speck_context_t *ctx);

File diff suppressed because it is too large Load Diff