Skip to content

Commit

Permalink
adds hashing benchmarks. Closes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
mkannwischer committed Mar 21, 2019
1 parent 42ad78d commit d067bca
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ all: $(DEST)/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_testvectors.bin \
$(DEST)/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_test.bin \
$(DEST)/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_speed.bin \
$(DEST)/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_stack.bin \
$(DEST)/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_hashing.bin \
$(DEST_HOST)/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_testvectors

$(DEST_HOST)/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_testvectors: $(COMMONSOURCES_HOST) crypto_$(TYPE)/$(SCHEME)/$(IMPLEMENTATION)/*.c
Expand All @@ -86,6 +87,12 @@ elf/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_testvectors.elf: $(COMMONSOURCES_
crypto_$(TYPE)/testvectors.c $(COMMONSOURCES_M4) crypto_$(TYPE)/$(SCHEME)/$(IMPLEMENTATION)/*.c common/hal-stm32f4.c \
-Icrypto_$(TYPE)/$(SCHEME)/$(IMPLEMENTATION) $(COMMONINCLUDES_M4) $(LDFLAGS)

elf/crypto_$(TYPE)_$(SCHEME)_$(IMPLEMENTATION)_hashing.elf: $(COMMONSOURCES_M4) crypto_$(TYPE)/$(SCHEME)/$(IMPLEMENTATION)/*.c $(OPENCM3FILE) common/hal-stm32f4.c
mkdir -p elf
$(CC) -o $@ $(CFLAGS) -DPROFILE_HASHING \
crypto_$(TYPE)/hashing.c $(COMMONSOURCES_M4) $(RANDOMBYTES_M4) crypto_$(TYPE)/$(SCHEME)/$(IMPLEMENTATION)/*.c common/hal-stm32f4.c \
-Icrypto_$(TYPE)/$(SCHEME)/$(IMPLEMENTATION) $(COMMONINCLUDES_M4) $(LDFLAGS)

$(OPENCM3FILE):
@if [ ! "`ls -A $(OPENCM3_DIR)`" ] ; then \
printf "######## ERROR ########\n"; \
Expand Down
54 changes: 54 additions & 0 deletions crypto_kem/hashing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "api.h"
#include "hal.h"

#include <stdio.h>
#include <stdint.h>
#include <string.h>

static void printcycles(const char *s, unsigned long long c)
{
char outs[32];
hal_send_str(s);
snprintf(outs,sizeof(outs),"%llu\n",c);
hal_send_str(outs);
}

unsigned long long hash_cycles;

int main(void)
{
unsigned char key_a[CRYPTO_BYTES], key_b[CRYPTO_BYTES];
unsigned char sk[CRYPTO_SECRETKEYBYTES];
unsigned char pk[CRYPTO_PUBLICKEYBYTES];
unsigned char ct[CRYPTO_CIPHERTEXTBYTES];

hal_setup(CLOCK_BENCHMARK);

hal_send_str("==========================");

// Key-pair generation
hash_cycles = 0;
crypto_kem_keypair(pk, sk);
printcycles("keypair hash cycles:", hash_cycles);

// Encapsulation
hash_cycles = 0;
crypto_kem_enc(ct, key_a, pk);
printcycles("sign hash cycles: ", hash_cycles);

// Decapsulation
hash_cycles = 0;
crypto_kem_dec(key_b, ct, sk);
printcycles("verify hash cycles: ", hash_cycles);

if (memcmp(key_a, key_b, CRYPTO_BYTES)) {
hal_send_str("ERROR KEYS\n");
}
else {
hal_send_str("OK KEYS\n");
}

hal_send_str("#");
while(1);
return 0;
}
49 changes: 49 additions & 0 deletions crypto_sign/hashing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "api.h"
#include "hal.h"

#include <stdio.h>
#include <stdint.h>
#include <string.h>

#define MLEN 59

static void printcycles(const char *s, unsigned long long c)
{
char outs[32];
hal_send_str(s);
snprintf(outs,sizeof(outs),"%llu\n",c);
hal_send_str(outs);
}

unsigned long long hash_cycles;

int main(void)
{
unsigned char sk[CRYPTO_SECRETKEYBYTES];
unsigned char pk[CRYPTO_PUBLICKEYBYTES];
unsigned char sm[MLEN+CRYPTO_BYTES];
unsigned long long smlen;

hal_setup(CLOCK_BENCHMARK);

hal_send_str("==========================");

// Key-pair generation
hash_cycles = 0;
crypto_sign_keypair(pk, sk);
printcycles("keypair hash cycles:", hash_cycles);

// Signing
hash_cycles = 0;
crypto_sign(sm, &smlen, sm, MLEN, sk);
printcycles("sign hash cycles: ", hash_cycles);

// Verification
hash_cycles = 0;
crypto_sign_open(sm, &smlen, sm, smlen, pk);
printcycles("verify hash cycles: ", hash_cycles);

hal_send_str("#");
while(1);
return 0;
}

0 comments on commit d067bca

Please sign in to comment.