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

Subversion Repositories gost28147-89

[/] [gost28147-89/] [trunk/] [utils/] [benchmark.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 fanatid
#include <assert.h>
2
#include <stdio.h>
3
#include <string.h>
4
#include <stdint.h>
5
#include <math.h>
6
 
7
#include <sys/time.h>
8
 
9
#include <openssl/rand.h>
10
 
11
#include "gost89.h"
12
 
13
#define TEST_SIZE 80*1024*1024
14
 
15
 
16
gost_subst_block gost_sbox = {
17
  {0x4,0xA,0x9,0x2,0xD,0x8,0x0,0xE,0x6,0xB,0x1,0xC,0x7,0xF,0x5,0x3},
18
  {0xE,0xB,0x4,0xC,0x6,0xD,0xF,0xA,0x2,0x3,0x8,0x1,0x0,0x7,0x5,0x9},
19
  {0x5,0x8,0x1,0xD,0xA,0x3,0x4,0x2,0xE,0xF,0xC,0x7,0x6,0x0,0x9,0xB},
20
  {0x7,0xD,0xA,0x1,0x0,0x8,0x9,0xF,0xE,0x4,0x6,0xC,0xB,0x2,0x5,0x3},
21
  {0x6,0xC,0x7,0x1,0x5,0xF,0xD,0x8,0x4,0xA,0x9,0xE,0x0,0x3,0xB,0x2},
22
  {0x4,0xB,0xA,0x0,0x7,0x2,0x1,0xD,0x3,0x6,0x8,0x5,0x9,0xC,0xF,0xE},
23
  {0xD,0xB,0x4,0x1,0x3,0xF,0x5,0x9,0x0,0xA,0xE,0x7,0x6,0x8,0x2,0xC},
24
  {0x1,0xF,0xD,0x0,0x5,0x7,0xA,0x4,0x9,0x2,0x3,0xE,0x6,0xB,0x8,0xC}
25
};
26
 
27
uint8_t gost_key[] = {
28
  0x04, 0x75, 0xF6, 0xE0, 0x50, 0x38, 0xFB, 0xFA,
29
  0xD2, 0xC7, 0xC3, 0x90, 0xED, 0xB3, 0xCA, 0x3D,
30
  0x15, 0x47, 0x12, 0x42, 0x91, 0xAE, 0x1E, 0x8A,
31
  0x2F, 0x79, 0xCD, 0x9E, 0xD2, 0xBC, 0xEF, 0xBD
32
};
33
 
34
double delta(struct timeval* t1, struct timeval* t2) {
35
  return (t2->tv_sec - t1->tv_sec) + (double) (t2->tv_usec - t1->tv_usec)/1000000;
36
}
37
 
38
int main(int argc, char **argv) {
39
  uint8_t gamma[8];
40
  uint8_t *in, *out;
41
  struct timeval t1, t2;
42
 
43
  gost_ctx ctx;
44
  gost_init(&ctx, &gost_sbox);
45
  gost_set_key(&ctx, &gost_key[0]);
46
 
47
  RAND_bytes(gamma, sizeof(gamma));
48
 
49
  in  = (uint8_t*) malloc(TEST_SIZE);
50
  assert(in != NULL);
51
  out = (uint8_t*) malloc(TEST_SIZE);
52
  assert(in != NULL);
53
  printf("TEST_SIZE: %d bytes\n", TEST_SIZE);
54
 
55
  gettimeofday(&t1, NULL);
56
  RAND_bytes(in, TEST_SIZE);
57
  gettimeofday(&t2, NULL);
58
  printf("RAND_bytes: %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2));
59
 
60
  gettimeofday(&t1, NULL);
61
  gost_ecb_encrypt(&ctx, &in[0], &out[0], TEST_SIZE/8);
62
  gettimeofday(&t2, NULL);
63
  printf("ECB mode:   %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2));
64
 
65
  gettimeofday(&t1, NULL);
66
  gost_cfb_encrypt(&ctx, &gamma[0], &in[0], &out[0], TEST_SIZE/8);
67
  gettimeofday(&t2, NULL);
68
  printf("CFB mode:   %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2));
69
 
70
  gettimeofday(&t1, NULL);
71
  gost_mac(&ctx, &in[0], TEST_SIZE, &out[0], 20);
72
  gettimeofday(&t2, NULL);
73
  printf("MAC mode:   %.6lf seconds, %.6lf bytes/s\n", delta(&t1, &t2), TEST_SIZE/delta(&t1, &t2));
74
 
75
  return 0;
76
}

powered by: WebSVN 2.1.0

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