BitPunch McEliece  v0.0.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-speed.c
Go to the documentation of this file.
1 /*
2  This file is part of BitPunch
3  Copyright (C) 2014-2015 Frantisek Uhrecky <frantisek.uhrecky[what here]gmail.com>
4  Copyright (C) 2014 Andrej Gulyas <andrej.guly[what here]gmail.com>
5  Copyright (C) 2014 Marek Klein <kleinmrk[what here]gmail.com>
6  Copyright (C) 2014 Filip Machovec <filipmachovec[what here]yahoo.com>
7  Copyright (C) 2014 Jozef Kudlac <jozef[what here]kudlac.sk>
8 
9  This program is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include <bitpunch/bitpunch.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <time.h>
26 #include <sys/time.h>
27 
28 #define BPU_TEST_ROUNDS 300
29 
30 int main(int argc, char **argv) {
31  // MUST BE INITIALIZED TO NULL
32  BPU_T_Mecs_Ctx *ctx = NULL;
33  BPU_T_UN_Mecs_Params params;
34  BPU_T_GF2_Vector *ct, *pt;
35  int i;
36  struct timeval tv, tv_end;
37  double res = 0;
38  double res_2 = 0;
39  double res_3 = 0;
40  fprintf(stderr, "====== SPEED TEST ======\n");
41  srand(time(NULL));
42 
43  for (i = 0; i < BPU_TEST_ROUNDS; i++){
44  BPU_mecsInitParamsGoppa(&params, 11, 50, 0);
46  gettimeofday(&tv, NULL);
47 
48  BPU_mecsGenKeyPair(ctx);
49  gettimeofday(&tv_end, NULL);
50  res += (tv_end.tv_sec - tv.tv_sec + ((tv_end.tv_usec - tv.tv_usec) / (double)1000000));
51 
52  BPU_gf2VecMalloc(&ct, ctx->ct_len);
53  BPU_gf2VecMalloc(&pt, ctx->pt_len);
54  BPU_gf2VecRand(pt, 0);
55 
56  gettimeofday(&tv, NULL);
57  BPU_mecsEncrypt(ct, pt, ctx);
58  gettimeofday(&tv_end, NULL);
59  res_2 += (tv_end.tv_sec - tv.tv_sec + ((tv_end.tv_usec - tv.tv_usec) / (double)1000000));
60 
61  gettimeofday(&tv, NULL);
62  BPU_mecsDecrypt(pt, ct, ctx);
63  gettimeofday(&tv_end, NULL);
64  res_3 += (tv_end.tv_sec - tv.tv_sec + ((tv_end.tv_usec - tv.tv_usec) / (double)1000000));
65 
66  BPU_gf2VecFree(&pt);
67  BPU_gf2VecFree(&ct);
68  BPU_mecsFreeCtx(&ctx);
69  BPU_mecsFreeParamsGoppa(&params);
70  }
71  fprintf(stderr, "%0.6lf\n", res / BPU_TEST_ROUNDS);
72  fprintf(stderr, "%0.6lf\n", res_2 / BPU_TEST_ROUNDS);
73  fprintf(stderr, "%0.6lf\n", res_3 / BPU_TEST_ROUNDS);
74 
75  return 0;
76 }
77 
int BPU_gf2VecMalloc(BPU_T_GF2_Vector **v, int len)
Definition: gf2types.c:97
void BPU_gf2VecFree(BPU_T_GF2_Vector **v)
Free dynamically or statically allocated vector.
Definition: gf2types.c:45
uint16_t pt_len
PT len in bits.
Definition: mecsctx.h:45
int BPU_gf2VecRand(BPU_T_GF2_Vector *out, int w)
Definition: gf2.c:240
int BPU_mecsInitParamsGoppa(BPU_T_UN_Mecs_Params *params, const uint16_t m, const uint16_t t, const BPU_T_GF2_16x mod)
Definition: mecsctx.c:192
int BPU_mecsDecrypt(BPU_T_GF2_Vector *pt, BPU_T_GF2_Vector *ct, const BPU_T_Mecs_Ctx *ctx)
Decrypt cipher text (ct) and save it to plain text.
Definition: mecs.c:45
int BPU_mecsInitCtx(BPU_T_Mecs_Ctx **ctx, const BPU_T_UN_Mecs_Params *params, const BPU_T_EN_Mecs_Types type)
Initialize (register) mecs functions for encryption, decryption and key gen based on type...
Definition: mecsctx.c:37
basic mecs, without any conversion
Definition: mecsctx.h:28
int main(int argc, char **argv)
Definition: test-speed.c:30
int BPU_mecsFreeCtx(BPU_T_Mecs_Ctx **ctx)
Definition: mecsctx.c:158
uint16_t ct_len
CT len in bits.
Definition: mecsctx.h:46
void BPU_mecsFreeParamsGoppa(BPU_T_UN_Mecs_Params *params)
Definition: mecsctx.c:196
#define BPU_TEST_ROUNDS
Definition: test-speed.c:28
int BPU_mecsGenKeyPair(BPU_T_Mecs_Ctx *ctx)
Key generation, first must be initialized context using BPU_mecsInitCtx().
Definition: mecs.c:55
int BPU_mecsEncrypt(BPU_T_GF2_Vector *ct, const BPU_T_GF2_Vector *pt, const BPU_T_Mecs_Ctx *ctx)
Encrypt plaintext (pt) and save it to cipher text.
Definition: mecs.c:33