diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-15 00:52:18 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-15 00:52:18 +0200 |
commit | 8035afa583d323060c6f05804024bbe4069a1f60 (patch) | |
tree | 06e22415b1a7a260ff2091438f87053006b78abb /test_crypto.c | |
parent | 338c95de4190065149ddc995e5404d335c05f432 (diff) | |
download | libbrandt-8035afa583d323060c6f05804024bbe4069a1f60.tar.gz libbrandt-8035afa583d323060c6f05804024bbe4069a1f60.zip |
add second ZKP (equality of two EC DLs) with test case
Diffstat (limited to 'test_crypto.c')
-rw-r--r-- | test_crypto.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test_crypto.c b/test_crypto.c index d692055..5103e0e 100644 --- a/test_crypto.c +++ b/test_crypto.c | |||
@@ -86,6 +86,58 @@ test_smc_zkp_dl () | |||
86 | } | 86 | } |
87 | 87 | ||
88 | int | 88 | int |
89 | test_smc_zkp_2dle () | ||
90 | { | ||
91 | static int first = 1; | ||
92 | gcry_mpi_t c; | ||
93 | gcry_mpi_t r; | ||
94 | gcry_mpi_t s; | ||
95 | gcry_mpi_t x; | ||
96 | gcry_mpi_point_t a; | ||
97 | gcry_mpi_point_t b; | ||
98 | gcry_mpi_point_t g1; | ||
99 | gcry_mpi_point_t g2; | ||
100 | gcry_mpi_point_t v = gcry_mpi_point_new (0); | ||
101 | gcry_mpi_point_t w = gcry_mpi_point_new (0); | ||
102 | |||
103 | check (v, "no pub1 key initialized"); | ||
104 | check (w, "no pub2 key initialized"); | ||
105 | brandt_ec_keypair_create (&g1, &s); | ||
106 | gcry_mpi_release (s); | ||
107 | brandt_ec_keypair_create (&g2, &s); | ||
108 | check (g1, "no gen1 created"); | ||
109 | check (g2, "no gen2 created"); | ||
110 | |||
111 | if (first) | ||
112 | { | ||
113 | gcry_mpi_ec_mul (g1, GCRYMPI_CONST_ONE, ec_gen, ec_ctx); | ||
114 | gcry_mpi_ec_mul (g2, GCRYMPI_CONST_ONE, ec_gen, ec_ctx); | ||
115 | first = 0; | ||
116 | } | ||
117 | |||
118 | brandt_ec_skey_create (&x); | ||
119 | check (x, "no sec key created"); | ||
120 | gcry_mpi_ec_mul (v, x, g1, ec_ctx); | ||
121 | check (v, "no pub1 key created"); | ||
122 | gcry_mpi_ec_mul (w, x, g2, ec_ctx); | ||
123 | check (w, "no pub2 key created"); | ||
124 | |||
125 | smc_zkp_2dle (v, w, g1, g2, x, &a, &b, &c, &r); | ||
126 | check (!smc_zkp_2dle_check (v, w, g1, g2, a, b, c, r), "zkp was false, should be true"); | ||
127 | |||
128 | gcry_mpi_release (c); | ||
129 | gcry_mpi_release (r); | ||
130 | gcry_mpi_release (s); | ||
131 | gcry_mpi_release (x); | ||
132 | gcry_mpi_point_release (a); | ||
133 | gcry_mpi_point_release (b); | ||
134 | gcry_mpi_point_release (g1); | ||
135 | gcry_mpi_point_release (g2); | ||
136 | gcry_mpi_point_release (v); | ||
137 | gcry_mpi_point_release (w); | ||
138 | } | ||
139 | |||
140 | int | ||
89 | main (int argc, char *argv[]) | 141 | main (int argc, char *argv[]) |
90 | { | 142 | { |
91 | int repeat = 50; | 143 | int repeat = 50; |