Browse Source

bench shake; API_VIS on shake

master
Michael Hamburg 10 years ago
parent
commit
ade8246a3d
3 changed files with 23 additions and 11 deletions
  1. +4
    -3
      Makefile
  2. +11
    -8
      include/shake.h
  3. +8
    -0
      test/bench.c

+ 4
- 3
Makefile View File

@@ -66,12 +66,13 @@ HEADERS= Makefile $(shell find . -name "*.h") build/timestamp

LIBCOMPONENTS= build/goldilocks.o build/barrett_field.o build/crandom.o \
build/$(FIELD).o build/ec_point.o build/scalarmul.o build/sha512.o build/magic.o \
build/f_arithmetic.o build/arithmetic.o build/decaf.o
build/f_arithmetic.o build/arithmetic.o build/decaf.o build/shake.o

TESTCOMPONENTS=build/test.o build/test_scalarmul.o build/test_sha512.o \
build/test_pointops.o build/test_arithmetic.o build/test_goldilocks.o build/magic.o
build/test_pointops.o build/test_arithmetic.o build/test_goldilocks.o build/magic.o \
build/shake.o

BENCHCOMPONENTS=build/bench.o
BENCHCOMPONENTS=build/bench.o build/shake.o

BATBASE=ed448goldilocks-bats-$(TODAY)
BATNAME=build/$(BATBASE)


+ 11
- 8
include/shake.h View File

@@ -14,6 +14,8 @@

#include <stdint.h>

#define API_VIS __attribute__((visibility("default")))

#ifndef INTERNAL_SPONGE_STRUCT
typedef struct keccak_sponge_s {
uint64_t opaque[26];
@@ -29,7 +31,7 @@
void sponge_init (
keccak_sponge_t sponge,
const struct kparams_s *params
);
) API_VIS;

/**
* @brief Absorb data into a SHA3 or SHAKE hash context.
@@ -41,7 +43,7 @@ void sha3_update (
struct keccak_sponge_s * __restrict__ sponge,
const uint8_t *in,
size_t len
);
) API_VIS;

/**
* @brief Squeeze output data from a SHA3 or SHAKE hash context.
@@ -56,7 +58,7 @@ void sha3_output (
keccak_sponge_t sponge,
uint8_t * __restrict__ out,
size_t len
);
) API_VIS;

/**
* @brief Destroy a SHA3 or SHAKE sponge context by overwriting it with 0.
@@ -64,8 +66,7 @@ void sha3_output (
*/
void sponge_destroy (
keccak_sponge_t sponge
);

) API_VIS;

/**
* @brief Hash (in) to (out)
@@ -80,12 +81,12 @@ void sponge_hash (
uint8_t *out,
size_t outlen,
const struct kparams_s *params
);
) API_VIS;

/* TODO: expand/doxygenate individual SHAKE/SHA3 instances? */

#define DECSHAKE(n) \
extern const struct kparams_s *SHAKE##n##_params; \
extern const struct kparams_s *SHAKE##n##_params API_VIS; \
static inline void shake##n##_init(keccak_sponge_t sponge) { \
sponge_init(sponge, SHAKE##n##_params); \
} \
@@ -104,7 +105,7 @@ void sponge_hash (
}
#define DECSHA3(n) \
extern const struct kparams_s *SHA3_##n##_params; \
extern const struct kparams_s *SHA3_##n##_params API_VIS; \
static inline void sha3_##n##_init(keccak_sponge_t sponge) { \
sponge_init(sponge, SHA3_##n##_params); \
} \
@@ -129,4 +130,6 @@ DECSHA3(256)
DECSHA3(384)
DECSHA3(512)
#undef API_VIS
#endif /* __SHAKE_H__ */

+ 8
- 0
test/bench.c View File

@@ -17,6 +17,7 @@
#include "goldilocks.h"
#include "sha512.h"
#include "decaf.h"
#include "shake.h"

static __inline__ void
ignore_result ( int result ) {
@@ -164,6 +165,13 @@ int main(int argc, char **argv) {
when = now() - when;
printf("sha512 blk: %5.1fns (%0.2f MB/s)\n", when * 1e9 / i, 128*i/when/1e6);
when = now();
for (i=0; i<nbase; i++) {
shake256_hash(hashout,128,hashout,128);
}
when = now() - when;
printf("shake 1blk: %5.1fns\n", when * 1e9 / i);
when = now();
for (i=0; i<nbase; i++) {
field_isr(c, a);


Loading…
Cancel
Save