aboutsummaryrefslogtreecommitdiff
path: root/test_crypto.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-06-13 21:09:41 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-06-13 21:27:03 +0200
commit338c95de4190065149ddc995e5404d335c05f432 (patch)
tree2f7dbfb7b4fb274071fb5a2992de27703ac61960 /test_crypto.c
parent557fbe2cc32f3ff6d8c2c0c8aa272f7b55f45618 (diff)
downloadlibbrandt-338c95de4190065149ddc995e5404d335c05f432.tar.gz
libbrandt-338c95de4190065149ddc995e5404d335c05f432.zip
coding style
Diffstat (limited to 'test_crypto.c')
-rw-r--r--test_crypto.c97
1 files changed, 58 insertions, 39 deletions
diff --git a/test_crypto.c b/test_crypto.c
index 1bfc321..d692055 100644
--- a/test_crypto.c
+++ b/test_crypto.c
@@ -1,69 +1,88 @@
1 1/* This file is part of libbrandt.
2 * Copyright (C) 2016 GNUnet e.V.
3 *
4 * libbrandt is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation, either version 3 of the License, or (at your option) any later
7 * version.
8 *
9 * libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * libbrandt. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17/**
18 * @file test_crypto.c
19 * @brief testing crypto and smc functions.
20 */
2#include "brandt.h" 21#include "brandt.h"
3#include "crypto.h" 22#include "crypto.h"
4#include "smc.h" 23#include "smc.h"
5#include "test.h" 24#include "test.h"
6 25
7extern gcry_mpi_point_t ec_gen; 26extern gcry_mpi_point_t ec_gen;
8extern gcry_ctx_t ec_ctx; 27extern gcry_ctx_t ec_ctx;
9 28
10int 29int
11test_brandt_ec_keypair_create () 30test_brandt_ec_keypair_create ()
12{ 31{
13 gcry_mpi_t skey; 32 gcry_mpi_t skey;
14 gcry_mpi_point_t pkey1; 33 gcry_mpi_point_t pkey1;
15 gcry_mpi_point_t pkey2 = gcry_mpi_point_new(0); 34 gcry_mpi_point_t pkey2 = gcry_mpi_point_new (0);
16 35
17 brandt_ec_keypair_create (&pkey1, &skey); 36 brandt_ec_keypair_create (&pkey1, &skey);
18 check(skey, "no sec key created"); 37 check (skey, "no sec key created");
19 check(pkey1, "no pub key created"); 38 check (pkey1, "no pub key created");
20 check(pkey2, "could not init pkey2"); 39 check (pkey2, "could not init pkey2");
21 40
22 gcry_mpi_ec_mul(pkey2, skey, ec_gen, ec_ctx); 41 gcry_mpi_ec_mul (pkey2, skey, ec_gen, ec_ctx);
23 check(!brandt_ec_point_cmp(pkey1, pkey2), "pkeys do not match"); 42 check (!brandt_ec_point_cmp (pkey1, pkey2), "pkeys do not match");
24 43
25 gcry_mpi_release(skey); 44 gcry_mpi_release (skey);
26 gcry_mpi_point_release(pkey1); 45 gcry_mpi_point_release (pkey1);
27 gcry_mpi_point_release(pkey2); 46 gcry_mpi_point_release (pkey2);
28} 47}
29 48
30int 49int
31test_smc_zkp_dl () 50test_smc_zkp_dl ()
32{ 51{
33 static int first = 1; 52 static int first = 1;
34 gcry_mpi_t c; 53 gcry_mpi_t c;
35 gcry_mpi_t r; 54 gcry_mpi_t r;
36 gcry_mpi_t s; 55 gcry_mpi_t s;
37 gcry_mpi_t x; 56 gcry_mpi_t x;
38 gcry_mpi_point_t a; 57 gcry_mpi_point_t a;
39 gcry_mpi_point_t g; 58 gcry_mpi_point_t g;
40 gcry_mpi_point_t v = gcry_mpi_point_new(0); 59 gcry_mpi_point_t v = gcry_mpi_point_new (0);
41 60
42 check(v, "no pub key initialized"); 61 check (v, "no pub key initialized");
43 brandt_ec_keypair_create (&g, &s); 62 brandt_ec_keypair_create (&g, &s);
44 check(g, "no gen created"); 63 check (g, "no gen created");
45 64
46 if (first) 65 if (first)
47 { 66 {
48 gcry_mpi_ec_mul(g, GCRYMPI_CONST_ONE, ec_gen, ec_ctx); 67 gcry_mpi_ec_mul (g, GCRYMPI_CONST_ONE, ec_gen, ec_ctx);
49 first = 0; 68 first = 0;
50 } 69 }
51 70
52 brandt_ec_skey_create(&x); 71 brandt_ec_skey_create (&x);
53 check(x, "no sec key created"); 72 check (x, "no sec key created");
54 gcry_mpi_ec_mul(v, x, g, ec_ctx); 73 gcry_mpi_ec_mul (v, x, g, ec_ctx);
55 check(v, "no pub key created"); 74 check (v, "no pub key created");
56 75
57 smc_zkp_dl(v, g, x, &a, &c, &r); 76 smc_zkp_dl (v, g, x, &a, &c, &r);
58 check(!smc_zkp_dl_check(v, g, a, c, r), "zkp was false, should be true"); 77 check (!smc_zkp_dl_check (v, g, a, c, r), "zkp was false, should be true");
59 78
60 gcry_mpi_release(c); 79 gcry_mpi_release (c);
61 gcry_mpi_release(r); 80 gcry_mpi_release (r);
62 gcry_mpi_release(s); 81 gcry_mpi_release (s);
63 gcry_mpi_release(x); 82 gcry_mpi_release (x);
64 gcry_mpi_point_release(a); 83 gcry_mpi_point_release (a);
65 gcry_mpi_point_release(g); 84 gcry_mpi_point_release (g);
66 gcry_mpi_point_release(v); 85 gcry_mpi_point_release (v);
67} 86}
68 87
69int 88int
@@ -72,12 +91,12 @@ main (int argc, char *argv[])
72 int repeat = 50; 91 int repeat = 50;
73 int i; 92 int i;
74 93
75 BRANDT_init(); 94 BRANDT_init ();
76 95
77 for (i = 0; i < repeat; i++) 96 for (i = 0; i < repeat; i++)
78 { 97 {
79 run(test_brandt_ec_keypair_create); 98 run (test_brandt_ec_keypair_create);
80 run(test_smc_zkp_dl); 99 run (test_smc_zkp_dl);
81 } 100 }
82 101
83 return ret; 102 return ret;