OpenCores
URL https://opencores.org/ocsvn/gost28147-89/gost28147-89/trunk

Subversion Repositories gost28147-89

[/] [gost28147-89/] [trunk/] [utils/] [benchmark.c] - Rev 5

Compare with Previous | Blame | View Log

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
 
#include <sys/time.h>
 
#include <openssl/rand.h>
 
#include "gost89.h"
 
#define TEST_SIZE 80*1024*1024
 
 
gost_subst_block gost_sbox = {
  {0x4,0xA,0x9,0x2,0xD,0x8,0x0,0xE,0x6,0xB,0x1,0xC,0x7,0xF,0x5,0x3},
  {0xE,0xB,0x4,0xC,0x6,0xD,0xF,0xA,0x2,0x3,0x8,0x1,0x0,0x7,0x5,0x9},
  {0x5,0x8,0x1,0xD,0xA,0x3,0x4,0x2,0xE,0xF,0xC,0x7,0x6,0x0,0x9,0xB},
  {0x7,0xD,0xA,0x1,0x0,0x8,0x9,0xF,0xE,0x4,0x6,0xC,0xB,0x2,0x5,0x3},
  {0x6,0xC,0x7,0x1,0x5,0xF,0xD,0x8,0x4,0xA,0x9,0xE,0x0,0x3,0xB,0x2},
  {0x4,0xB,0xA,0x0,0x7,0x2,0x1,0xD,0x3,0x6,0x8,0x5,0x9,0xC,0xF,0xE},
  {0xD,0xB,0x4,0x1,0x3,0xF,0x5,0x9,0x0,0xA,0xE,0x7,0x6,0x8,0x2,0xC},
  {0x1,0xF,0xD,0x0,0x5,0x7,0xA,0x4,0x9,0x2,0x3,0xE,0x6,0xB,0x8,0xC}
};
 
uint8_t gost_key[] = {
  0x04, 0x75, 0xF6, 0xE0, 0x50, 0x38, 0xFB, 0xFA,
  0xD2, 0xC7, 0xC3, 0x90, 0xED, 0xB3, 0xCA, 0x3D,
  0x15, 0x47, 0x12, 0x42, 0x91, 0xAE, 0x1E, 0x8A,
  0x2F, 0x79, 0xCD, 0x9E, 0xD2, 0xBC, 0xEF, 0xBD
};
 
double delta(struct timeval* t1, struct timeval* t2) {
  return (t2->tv_sec - t1->tv_sec) + (double) (t2->tv_usec - t1->tv_usec)/1000000;
}
 
int main(int argc, char **argv) {
  uint8_t gamma[8];
  uint8_t *in, *out;
  struct timeval t1, t2;
 
  gost_ctx ctx;
  gost_init(&ctx, &gost_sbox);
  gost_set_key(&ctx, &gost_key[0]);
 
  RAND_bytes(gamma, sizeof(gamma));
 
  in  = (uint8_t*) malloc(TEST_SIZE);
  assert(in != NULL);
  out = (uint8_t*) malloc(TEST_SIZE);
  assert(in != NULL);
  printf("TEST_SIZE: %d bytes\n", TEST_SIZE);
 
  gettimeofday(&t1, NULL);
  RAND_bytes(in, TEST_SIZE);
  gettimeofday(&t2, NULL);
  printf("RAND_bytes: %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2));
 
  gettimeofday(&t1, NULL);
  gost_ecb_encrypt(&ctx, &in[0], &out[0], TEST_SIZE/8);
  gettimeofday(&t2, NULL);
  printf("ECB mode:   %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2));
 
  gettimeofday(&t1, NULL);
  gost_cfb_encrypt(&ctx, &gamma[0], &in[0], &out[0], TEST_SIZE/8);
  gettimeofday(&t2, NULL);
  printf("CFB mode:   %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2));
 
  gettimeofday(&t1, NULL);
  gost_mac(&ctx, &in[0], TEST_SIZE, &out[0], 20);
  gettimeofday(&t2, NULL);
  printf("MAC mode:   %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2));
 
  return 0;
}
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.