diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-19 22:37:31 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-19 22:41:03 +0200 |
commit | 0d2f95ffba76a338b5820f862d826a7ac1812ec3 (patch) | |
tree | 8eaf9b97f41999920043d46911270295f053aec0 /test_crypto.c | |
parent | 3f81885ee3e44486505935760da7c812efc4c76f (diff) | |
download | libbrandt-0d2f95ffba76a338b5820f862d826a7ac1812ec3.tar.gz libbrandt-0d2f95ffba76a338b5820f862d826a7ac1812ec3.zip |
merge smc into crypto module. add 2dim array helpers
Diffstat (limited to 'test_crypto.c')
-rw-r--r-- | test_crypto.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/test_crypto.c b/test_crypto.c index 5cc2ed1..a42a643 100644 --- a/test_crypto.c +++ b/test_crypto.c | |||
@@ -18,15 +18,33 @@ | |||
18 | * @file test_crypto.c | 18 | * @file test_crypto.c |
19 | * @brief testing crypto and smc functions. | 19 | * @brief testing crypto and smc functions. |
20 | */ | 20 | */ |
21 | |||
22 | /* For testing static functions and variables we include the whole source */ | ||
23 | #include "crypto.c" | ||
24 | |||
21 | #include "brandt.h" | 25 | #include "brandt.h" |
22 | #include "crypto.h" | 26 | #include "crypto.h" |
23 | #include "smc.h" | ||
24 | #include "test.h" | 27 | #include "test.h" |
25 | 28 | ||
26 | extern gcry_ctx_t ec_ctx; | 29 | |
27 | extern gcry_mpi_point_t ec_gen; | 30 | int |
28 | extern gcry_mpi_point_t ec_zero; | 31 | test_smc_2d_array () |
29 | extern gcry_mpi_t ec_n; | 32 | { |
33 | gcry_mpi_point_t **array; | ||
34 | uint16_t size1 = 3; | ||
35 | uint16_t size2 = 7; | ||
36 | uint16_t i, j; | ||
37 | |||
38 | array = smc_init2 (size1, size2); | ||
39 | check (array, "memory allocation failed"); | ||
40 | |||
41 | for (i = 0; i < size1; i++) | ||
42 | for (j = 0; j < size2; j++) | ||
43 | check (array[i][j], "point has not been initialized"); | ||
44 | |||
45 | smc_free2 (array, size1, size2); | ||
46 | } | ||
47 | |||
30 | 48 | ||
31 | int | 49 | int |
32 | test_smc_zkp_dl () | 50 | test_smc_zkp_dl () |
@@ -38,7 +56,7 @@ test_smc_zkp_dl () | |||
38 | gcry_mpi_point_t g = gcry_mpi_point_new (0); | 56 | gcry_mpi_point_t g = gcry_mpi_point_new (0); |
39 | gcry_mpi_point_t v = gcry_mpi_point_new (0); | 57 | gcry_mpi_point_t v = gcry_mpi_point_new (0); |
40 | 58 | ||
41 | brandt_ec_keypair_create (g, c); | 59 | ec_keypair_create (g, c); |
42 | 60 | ||
43 | if (0 == tests_run) | 61 | if (0 == tests_run) |
44 | { | 62 | { |
@@ -46,7 +64,7 @@ test_smc_zkp_dl () | |||
46 | gcry_mpi_ec_mul (g, GCRYMPI_CONST_ONE, ec_gen, ec_ctx); | 64 | gcry_mpi_ec_mul (g, GCRYMPI_CONST_ONE, ec_gen, ec_ctx); |
47 | } | 65 | } |
48 | 66 | ||
49 | brandt_ec_keypair_create_base (v, x, g); | 67 | ec_keypair_create_base (v, x, g); |
50 | 68 | ||
51 | smc_zkp_dl (v, g, x, a, c, r); | 69 | smc_zkp_dl (v, g, x, a, c, r); |
52 | check (!smc_zkp_dl_check (v, g, a, c, r), "zkp dl wrong"); | 70 | check (!smc_zkp_dl_check (v, g, a, c, r), "zkp dl wrong"); |
@@ -77,8 +95,8 @@ test_smc_zkp_2dle () | |||
77 | gcry_mpi_point_t v = gcry_mpi_point_new (0); | 95 | gcry_mpi_point_t v = gcry_mpi_point_new (0); |
78 | gcry_mpi_point_t w = gcry_mpi_point_new (0); | 96 | gcry_mpi_point_t w = gcry_mpi_point_new (0); |
79 | 97 | ||
80 | brandt_ec_keypair_create (g1, c); | 98 | ec_keypair_create (g1, c); |
81 | brandt_ec_keypair_create (g2, c); | 99 | ec_keypair_create (g2, c); |
82 | 100 | ||
83 | if (0 == tests_run) | 101 | if (0 == tests_run) |
84 | { | 102 | { |
@@ -87,7 +105,7 @@ test_smc_zkp_2dle () | |||
87 | gcry_mpi_ec_mul (g2, GCRYMPI_CONST_ONE, ec_gen, ec_ctx); | 105 | gcry_mpi_ec_mul (g2, GCRYMPI_CONST_ONE, ec_gen, ec_ctx); |
88 | } | 106 | } |
89 | 107 | ||
90 | brandt_ec_keypair_create_base (v, x, g1); | 108 | ec_keypair_create_base (v, x, g1); |
91 | gcry_mpi_ec_mul (w, x, g2, ec_ctx); | 109 | gcry_mpi_ec_mul (w, x, g2, ec_ctx); |
92 | 110 | ||
93 | smc_zkp_2dle (v, w, g1, g2, x, a, b, c, r); | 111 | smc_zkp_2dle (v, w, g1, g2, x, a, b, c, r); |
@@ -128,7 +146,7 @@ test_smc_zkp_0og () | |||
128 | gcry_mpi_point_t b1 = gcry_mpi_point_new (0); | 146 | gcry_mpi_point_t b1 = gcry_mpi_point_new (0); |
129 | gcry_mpi_point_t b2 = gcry_mpi_point_new (0); | 147 | gcry_mpi_point_t b2 = gcry_mpi_point_new (0); |
130 | 148 | ||
131 | brandt_ec_keypair_create (y, c); | 149 | ec_keypair_create (y, c); |
132 | 150 | ||
133 | smc_zkp_0og (alpha, (tests_run % 2 ? ec_zero : ec_gen), y, beta, a1, a2, b1, | 151 | smc_zkp_0og (alpha, (tests_run % 2 ? ec_zero : ec_gen), y, beta, a1, a2, b1, |
134 | b2, c, d1, d2, r1, r2); | 152 | b2, c, d1, d2, r1, r2); |
@@ -161,10 +179,13 @@ test_smc_zkp_0og () | |||
161 | int | 179 | int |
162 | main (int argc, char *argv[]) | 180 | main (int argc, char *argv[]) |
163 | { | 181 | { |
164 | int repeat = 32; | 182 | int repeat = 8; |
165 | 183 | ||
166 | BRANDT_init (); | 184 | BRANDT_init (); |
167 | 185 | ||
186 | /* tests that need to run only once */ | ||
187 | run (test_smc_2d_array); | ||
188 | |||
168 | for (tests_run = 0; tests_run < repeat; tests_run++) | 189 | for (tests_run = 0; tests_run < repeat; tests_run++) |
169 | { | 190 | { |
170 | run (test_smc_zkp_dl); | 191 | run (test_smc_zkp_dl); |