Browse Source

code size related improvements

master
Michael Hamburg 9 years ago
parent
commit
c8bf0382c5
3 changed files with 16 additions and 18 deletions
  1. +8
    -8
      include/shake.h
  2. +1
    -1
      src/decaf_fast.c
  3. +7
    -9
      src/shake.c

+ 8
- 8
include/shake.h View File

@@ -91,38 +91,38 @@ void sponge_hash (
/* TODO: expand/doxygenate individual SHAKE/SHA3 instances? */

#define DECSHAKE(n) \
extern const struct kparams_s *SHAKE##n##_params API_VIS; \
extern const struct kparams_s SHAKE##n##_params_s API_VIS; \
static inline void shake##n##_init(keccak_sponge_t sponge) { \
sponge_init(sponge, SHAKE##n##_params); \
sponge_init(sponge, &SHAKE##n##_params_s); \
} \
static inline void shake##n##_update(keccak_sponge_t sponge, const uint8_t *in, size_t inlen ) { \
sha3_update(sponge, in, inlen); \
} \
static inline void shake##n##_final(keccak_sponge_t sponge, uint8_t *out, size_t outlen ) { \
sha3_output(sponge, out, outlen); \
sponge_init(sponge, SHAKE##n##_params); \
sponge_init(sponge, &SHAKE##n##_params_s); \
} \
static inline void shake##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \
sponge_hash(in,inlen,out,outlen,SHAKE##n##_params); \
sponge_hash(in,inlen,out,outlen,&SHAKE##n##_params_s); \
} \
static inline void shake##n##_destroy( keccak_sponge_t sponge ) { \
sponge_destroy(sponge); \
}
#define DECSHA3(n) \
extern const struct kparams_s *SHA3_##n##_params API_VIS; \
extern const struct kparams_s SHA3_##n##_params_s API_VIS; \
static inline void sha3_##n##_init(keccak_sponge_t sponge) { \
sponge_init(sponge, SHA3_##n##_params); \
sponge_init(sponge, &SHA3_##n##_params_s); \
} \
static inline void sha3_##n##_update(keccak_sponge_t sponge, const uint8_t *in, size_t inlen ) { \
sha3_update(sponge, in, inlen); \
} \
static inline void sha3_##n##_final(keccak_sponge_t sponge, uint8_t *out, size_t outlen ) { \
sha3_output(sponge, out, outlen); \
sponge_init(sponge, SHA3_##n##_params); \
sponge_init(sponge, &SHA3_##n##_params_s); \
} \
static inline void sha3_##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \
sponge_hash(in,inlen,out,outlen,SHA3_##n##_params); \
sponge_hash(in,inlen,out,outlen,&SHA3_##n##_params_s); \
} \
static inline void sha3_##n##_destroy( keccak_sponge_t sponge ) { \
sponge_destroy(sponge); \


+ 1
- 1
src/decaf_fast.c View File

@@ -35,7 +35,7 @@ typedef int64_t decaf_sdword_t;
#error "Only supporting 32- and 64-bit platforms right now"
#endif

static const int QUADRATIC_NONRESIDUE = -1;
//static const int QUADRATIC_NONRESIDUE = -1;

#define sv static void
#define snv static void __attribute__((noinline))


+ 7
- 9
src/shake.c View File

@@ -100,13 +100,13 @@ static inline uint64_t rol(uint64_t x, int s) {
/* Helper macros to unroll the permutation. TODO: opt tradeoffs. */
#define REPEAT5(e) e e e e e
#define FOR51(v, e) v = 0; REPEAT5(e; v += 1;)
#if (defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__))
//#if (defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__))
# define FOR55(v, e) v = 0; REPEAT5(e; v += 5;)
# define REPEAT24(e) e e e e e e e e e e e e e e e e e e e e e e e e
#else
# define FOR55(v, e) for (v=0; v<25; v+= 5) { e; }
# define REPEAT24(e) {int _j=0; for (_j=0; _j<24; _j++) { e }}
#endif
// #else
// # define FOR55(v, e) for (v=0; v<25; v+= 5) { e; }
// # define REPEAT24(e) {int _j=0; for (_j=0; _j<24; _j++) { e }}
// #endif

/*** The Keccak-f[1600] permutation ***/
static void
@@ -251,13 +251,11 @@ void sponge_hash (

#define DEFSHAKE(n) \
const struct kparams_s SHAKE##n##_params_s = \
{ 0, FLAG_ABSORBING, 200-n/4, 0, 0x1f, 0x80, 0xFF, 0 }, \
*SHAKE##n##_params = &SHAKE##n##_params_s;
{ 0, FLAG_ABSORBING, 200-n/4, 0, 0x1f, 0x80, 0xFF, 0 };
#define DEFSHA3(n) \
const struct kparams_s SHA3_##n##_params_s = \
{ 0, FLAG_ABSORBING, 200-n/4, 0, 0x06, 0x80, n/8, 0 }, \
*SHA3_##n##_params = &SHA3_##n##_params_s;
{ 0, FLAG_ABSORBING, 200-n/4, 0, 0x06, 0x80, n/8, 0 };

DEFSHAKE(128)
DEFSHAKE(256)


Loading…
Cancel
Save