diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-09 15:51:57 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-09 15:51:57 +0000 |
commit | efd634ccf636b870b2dbd79f8969f8999c5573fa (patch) | |
tree | 4492353a28bf7add22f9ea7a42233a6bd679ca44 /src/util/test_crypto_rsa.c | |
parent | 8215376b2d1b4a3d95a0cf1ba474cf4be437c1b0 (diff) | |
download | gnunet-efd634ccf636b870b2dbd79f8969f8999c5573fa.tar.gz gnunet-efd634ccf636b870b2dbd79f8969f8999c5573fa.zip |
adding support for blind signatures (modernized version of Taler logic, with variable key length)
Diffstat (limited to 'src/util/test_crypto_rsa.c')
-rw-r--r-- | src/util/test_crypto_rsa.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c new file mode 100644 index 000000000..a0a6b4722 --- /dev/null +++ b/src/util/test_crypto_rsa.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify it under the | ||
6 | terms of the GNU General Public License as published by the Free Software | ||
7 | Foundation; either version 3, or (at your option) any later version. | ||
8 | |||
9 | GNUnet 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 | TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file util/test_crypto_rsa.c | ||
19 | * @brief testcase for utility functions for RSA cryptography | ||
20 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
21 | */ | ||
22 | #include "platform.h" | ||
23 | #include <gnunet/gnunet_util_lib.h> | ||
24 | |||
25 | #define KEY_SIZE 1024 | ||
26 | |||
27 | |||
28 | int | ||
29 | main (int argc, | ||
30 | char *argv[]) | ||
31 | { | ||
32 | #define RND_BLK_SIZE 4096 | ||
33 | unsigned char rnd_blk[RND_BLK_SIZE]; | ||
34 | struct GNUNET_CRYPTO_rsa_PrivateKey *priv; | ||
35 | struct GNUNET_CRYPTO_rsa_PublicKey *pub; | ||
36 | struct GNUNET_CRYPTO_rsa_BlindingKey *bkey; | ||
37 | struct GNUNET_CRYPTO_rsa_Signature *sig; | ||
38 | struct GNUNET_CRYPTO_rsa_Signature *bsig; | ||
39 | struct GNUNET_HashCode hash; | ||
40 | char *blind_buf; | ||
41 | size_t bsize; | ||
42 | |||
43 | GNUNET_log_setup ("test-rsa", "WARNING", NULL); | ||
44 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | ||
45 | rnd_blk, | ||
46 | RND_BLK_SIZE); | ||
47 | GNUNET_CRYPTO_hash (rnd_blk, | ||
48 | RND_BLK_SIZE, | ||
49 | &hash); | ||
50 | priv = GNUNET_CRYPTO_rsa_private_key_create (KEY_SIZE); | ||
51 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); | ||
52 | /* try ordinary sig first */ | ||
53 | sig = GNUNET_CRYPTO_rsa_sign (priv, | ||
54 | &hash, | ||
55 | sizeof (hash)); | ||
56 | GNUNET_assert (GNUNET_OK == | ||
57 | GNUNET_CRYPTO_rsa_verify (&hash, sig, pub)); | ||
58 | GNUNET_CRYPTO_rsa_signature_free (sig); | ||
59 | |||
60 | /* test blind signing */ | ||
61 | bkey = GNUNET_CRYPTO_rsa_blinding_key_create (KEY_SIZE); | ||
62 | bsize = GNUNET_CRYPTO_rsa_blind (&hash, | ||
63 | bkey, | ||
64 | pub, | ||
65 | &blind_buf); | ||
66 | GNUNET_assert (0 != bsize); | ||
67 | bsig = GNUNET_CRYPTO_rsa_sign (priv, | ||
68 | blind_buf, | ||
69 | bsize); | ||
70 | GNUNET_free (blind_buf); | ||
71 | sig = GNUNET_CRYPTO_rsa_unblind (bsig, | ||
72 | bkey, | ||
73 | pub); | ||
74 | GNUNET_CRYPTO_rsa_signature_free (bsig); | ||
75 | GNUNET_assert (GNUNET_OK == | ||
76 | GNUNET_CRYPTO_rsa_verify (&hash, sig, pub)); | ||
77 | GNUNET_CRYPTO_rsa_signature_free (sig); | ||
78 | GNUNET_CRYPTO_rsa_private_key_free (priv); | ||
79 | GNUNET_CRYPTO_rsa_public_key_free (pub); | ||
80 | GNUNET_CRYPTO_rsa_blinding_key_free (bkey); | ||
81 | return 0; | ||
82 | } | ||