diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-12 20:52:22 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-12 20:52:22 +0200 |
commit | 62b87e57a7f7042d27fe0a80b9194aeae0c14a50 (patch) | |
tree | 961a43363dbca413e4b1e65b367c0ffd553cfaf0 /test_crypto.c | |
parent | 5957a777076d014b17aada25afe0991397edbacc (diff) | |
download | libbrandt-62b87e57a7f7042d27fe0a80b9194aeae0c14a50.tar.gz libbrandt-62b87e57a7f7042d27fe0a80b9194aeae0c14a50.zip |
add tests for key generation
Diffstat (limited to 'test_crypto.c')
-rw-r--r-- | test_crypto.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test_crypto.c b/test_crypto.c new file mode 100644 index 0000000..67894eb --- /dev/null +++ b/test_crypto.c | |||
@@ -0,0 +1,59 @@ | |||
1 | |||
2 | #include "brandt.h" | ||
3 | #include "crypto.h" | ||
4 | #include "test.h" | ||
5 | |||
6 | int | ||
7 | test_brandt_ec_keypair_create () | ||
8 | { | ||
9 | gcry_mpi_t skey; | ||
10 | gcry_mpi_t x1 = gcry_mpi_new(0); | ||
11 | gcry_mpi_t x2 = gcry_mpi_new(0); | ||
12 | gcry_mpi_t y1 = gcry_mpi_new(0); | ||
13 | gcry_mpi_t y2 = gcry_mpi_new(0); | ||
14 | gcry_mpi_point_t pkey1; | ||
15 | gcry_mpi_point_t pkey2 = gcry_mpi_point_new(0); | ||
16 | |||
17 | brandt_ec_keypair_create (&pkey1, &skey); | ||
18 | check(skey, "no sec key created"); | ||
19 | check(pkey1, "no pub key created"); | ||
20 | check(pkey2, "could not init pkey2"); | ||
21 | check(x1, "could not init x1"); | ||
22 | check(x2, "could not init x2"); | ||
23 | check(y1, "could not init y1"); | ||
24 | check(y2, "could not init y2"); | ||
25 | |||
26 | gcry_mpi_ec_mul(pkey2, skey, ec_gen, ec_ctx); | ||
27 | check(!gcry_mpi_ec_get_affine(x1, y1, pkey1, ec_ctx), "could not get affine coords for pkey1"); | ||
28 | check(!gcry_mpi_ec_get_affine(x2, y2, pkey2, ec_ctx), "could not get affine coords for pkey1"); | ||
29 | check(!gcry_mpi_cmp(x1, x2), "x component does not match"); | ||
30 | check(!gcry_mpi_cmp(y1, y2), "y component does not match"); | ||
31 | |||
32 | gcry_mpi_release(skey); | ||
33 | gcry_mpi_release(x1); | ||
34 | gcry_mpi_release(x2); | ||
35 | gcry_mpi_release(y1); | ||
36 | gcry_mpi_release(y2); | ||
37 | gcry_mpi_point_release(pkey1); | ||
38 | gcry_mpi_point_release(pkey2); | ||
39 | } | ||
40 | |||
41 | int | ||
42 | main (int argc, char *argv[]) | ||
43 | { | ||
44 | int repeat = 100; | ||
45 | int i; | ||
46 | |||
47 | BRANDT_init(); | ||
48 | |||
49 | for (i = 0; i < repeat; i++) | ||
50 | { | ||
51 | run(test_brandt_ec_keypair_create); | ||
52 | } | ||
53 | |||
54 | if (!ret) | ||
55 | { | ||
56 | fputs("All tests passed", stderr); | ||
57 | } | ||
58 | return ret; | ||
59 | } | ||