diff options
Diffstat (limited to 'src/util/test_rsa.c')
-rw-r--r-- | src/util/test_rsa.c | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/src/util/test_rsa.c b/src/util/test_rsa.c deleted file mode 100644 index fdacf5212..000000000 --- a/src/util/test_rsa.c +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | /* NOTE: this is obsolete logic, we should migrate to the | ||
2 | GNUNET_CRYPTO_rsa-API as soon as possible */ | ||
3 | |||
4 | |||
5 | /* | ||
6 | This file is part of TALER | ||
7 | (C) 2014 Christian Grothoff (and other contributing authors) | ||
8 | |||
9 | TALER is free software; you can redistribute it and/or modify it under the | ||
10 | terms of the GNU General Public License as published by the Free Software | ||
11 | Foundation; either version 3, or (at your option) any later version. | ||
12 | |||
13 | TALER is distributed in the hope that it will be useful, but WITHOUT ANY | ||
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
15 | A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License along with | ||
18 | TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/test_rsa.c | ||
23 | * @brief testcase for utility functions for RSA cryptography | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "taler_rsa.h" | ||
28 | #include <gnunet/gnunet_util_lib.h> | ||
29 | |||
30 | #define TEST_PURPOSE UINT32_MAX | ||
31 | |||
32 | |||
33 | #define EXITIF(cond) \ | ||
34 | do { \ | ||
35 | if (cond) { GNUNET_break (0); goto EXITIF_exit; } \ | ||
36 | } while (0) | ||
37 | |||
38 | int | ||
39 | main (int argc, char *argv[]) | ||
40 | { | ||
41 | #define RND_BLK_SIZE 16524 | ||
42 | unsigned char rnd_blk[RND_BLK_SIZE]; | ||
43 | struct TALER_RSA_PrivateKey *priv; | ||
44 | struct TALER_RSA_PrivateKeyBinaryEncoded *priv_enc; | ||
45 | struct TALER_RSA_PublicKeyBinaryEncoded pubkey; | ||
46 | struct TALER_RSA_BlindingKey *bkey; | ||
47 | struct TALER_RSA_BlindedSignaturePurpose *bsp; | ||
48 | struct TALER_RSA_Signature sig; | ||
49 | struct GNUNET_HashCode hash; | ||
50 | int ret; | ||
51 | |||
52 | priv = NULL; | ||
53 | bsp = NULL; | ||
54 | bkey = NULL; | ||
55 | ret = 1; | ||
56 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, rnd_blk, | ||
57 | RND_BLK_SIZE); | ||
58 | GNUNET_CRYPTO_hash (rnd_blk, RND_BLK_SIZE, &hash); | ||
59 | priv = TALER_RSA_key_create (); | ||
60 | GNUNET_assert (NULL != priv); | ||
61 | EXITIF (GNUNET_OK != TALER_RSA_sign (priv, | ||
62 | &hash, sizeof (hash), | ||
63 | &sig)); | ||
64 | TALER_RSA_key_get_public (priv, &pubkey); | ||
65 | EXITIF (NULL == (priv_enc = TALER_RSA_encode_key (priv))); | ||
66 | TALER_RSA_key_free (priv); | ||
67 | priv = NULL; | ||
68 | EXITIF (NULL == (priv = TALER_RSA_decode_key ((const char *) priv_enc, | ||
69 | ntohs (priv_enc->len)))); | ||
70 | GNUNET_free (priv_enc); | ||
71 | priv_enc = NULL; | ||
72 | EXITIF (GNUNET_OK != TALER_RSA_verify (&hash, sizeof (hash), | ||
73 | &sig, | ||
74 | &pubkey)); | ||
75 | /* corrupt our hash and see if the signature is still valid */ | ||
76 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &hash, | ||
77 | sizeof (struct GNUNET_HashCode)); | ||
78 | EXITIF (GNUNET_OK == TALER_RSA_verify (&hash, sizeof (hash), | ||
79 | &sig, | ||
80 | &pubkey)); | ||
81 | |||
82 | /* test blind signing */ | ||
83 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, rnd_blk, | ||
84 | RND_BLK_SIZE); | ||
85 | GNUNET_CRYPTO_hash (rnd_blk, RND_BLK_SIZE, &hash); | ||
86 | (void) memset (&sig, 0, sizeof (struct TALER_RSA_Signature)); | ||
87 | EXITIF (NULL == (bkey = TALER_RSA_blinding_key_create ())); | ||
88 | EXITIF (NULL == (bsp = | ||
89 | TALER_RSA_message_blind (&hash, sizeof (hash), | ||
90 | bkey, &pubkey))); | ||
91 | EXITIF (GNUNET_OK != TALER_RSA_sign (priv, | ||
92 | bsp, | ||
93 | sizeof (struct TALER_RSA_BlindedSignaturePurpose), | ||
94 | &sig)); | ||
95 | EXITIF (GNUNET_OK != TALER_RSA_unblind (&sig, | ||
96 | bkey, | ||
97 | &pubkey)); | ||
98 | EXITIF (GNUNET_OK != TALER_RSA_verify (&hash, sizeof (hash), | ||
99 | &sig, | ||
100 | &pubkey)); | ||
101 | /* corrupt our hash and see if the signature is still valid */ | ||
102 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &hash, | ||
103 | sizeof (struct GNUNET_HashCode)); | ||
104 | EXITIF (GNUNET_OK == TALER_RSA_verify (&hash, sizeof (hash), | ||
105 | &sig, | ||
106 | &pubkey)); | ||
107 | ret = 0; /* all OK */ | ||
108 | |||
109 | EXITIF_exit: | ||
110 | if (NULL != priv) | ||
111 | { | ||
112 | TALER_RSA_key_free (priv); | ||
113 | priv = NULL; | ||
114 | } | ||
115 | if (NULL != priv_enc) | ||
116 | { | ||
117 | GNUNET_free (priv_enc); | ||
118 | priv_enc = NULL; | ||
119 | } | ||
120 | if (NULL != bkey) | ||
121 | TALER_RSA_blinding_key_destroy (bkey); | ||
122 | GNUNET_free_non_null (bsp); | ||
123 | return ret; | ||
124 | } | ||