aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-rsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-rsa.c')
-rw-r--r--src/util/gnunet-rsa.c110
1 files changed, 0 insertions, 110 deletions
diff --git a/src/util/gnunet-rsa.c b/src/util/gnunet-rsa.c
index 917ee50f4..1e7132d3f 100644
--- a/src/util/gnunet-rsa.c
+++ b/src/util/gnunet-rsa.c
@@ -25,7 +25,6 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_lib.h"
29#include <gcrypt.h> 28#include <gcrypt.h>
30 29
31 30
@@ -49,107 +48,6 @@ static int print_short_identity;
49 */ 48 */
50static int weak_random; 49static int weak_random;
51 50
52/**
53 * Option set to create a bunch of keys at once.
54 */
55static unsigned int make_keys;
56
57/**
58 * The private information of an RSA key pair.
59 * NOTE: this must match the definition in crypto_ksk.c and crypto_rsa.c!
60 */
61struct GNUNET_CRYPTO_RsaPrivateKey
62{
63 gcry_sexp_t sexp;
64};
65
66
67/**
68 * Create a new private key. Caller must free return value.
69 *
70 * @return fresh private key
71 */
72static struct GNUNET_CRYPTO_RsaPrivateKey *
73rsa_key_create ()
74{
75 struct GNUNET_CRYPTO_RsaPrivateKey *ret;
76 gcry_sexp_t s_key;
77 gcry_sexp_t s_keyparam;
78
79 GNUNET_assert (0 ==
80 gcry_sexp_build (&s_keyparam, NULL,
81 "(genkey(rsa(nbits %d)(rsa-use-e 3:257)))",
82 2048));
83 GNUNET_assert (0 == gcry_pk_genkey (&s_key, s_keyparam));
84 gcry_sexp_release (s_keyparam);
85#if EXTRA_CHECKS
86 GNUNET_assert (0 == gcry_pk_testkey (s_key));
87#endif
88 ret = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPrivateKey));
89 ret->sexp = s_key;
90 return ret;
91}
92
93
94/**
95 * Create a flat file with a large number of key pairs for testing.
96 */
97static void
98create_keys (const char *fn)
99{
100 FILE *f;
101 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
102 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *enc;
103
104 if (NULL == (f = fopen (fn, "w+")))
105 {
106 fprintf (stderr,
107 _("Failed to open `%s': %s\n"),
108 fn,
109 STRERROR (errno));
110 return;
111 }
112 fprintf (stderr,
113 _("Generating %u keys, please wait"),
114 make_keys);
115 while (0 < make_keys--)
116 {
117 fprintf (stderr,
118 ".");
119 if (NULL == (pk = rsa_key_create ()))
120 {
121 GNUNET_break (0);
122 break;
123 }
124 enc = GNUNET_CRYPTO_rsa_encode_key (pk);
125 if (GNUNET_TESTING_HOSTKEYFILESIZE != htons (enc->len))
126 {
127 /* sometimes we get a different key length because 'd' or 'u' start
128 with leading bits; skip those... */
129 GNUNET_CRYPTO_rsa_key_free (pk);
130 GNUNET_free (enc);
131 make_keys++;
132 continue;
133 }
134 if (htons (enc->len) != fwrite (enc, 1, htons (enc->len), f))
135 {
136 fprintf (stderr,
137 _("\nFailed to write to `%s': %s\n"),
138 fn,
139 STRERROR (errno));
140 GNUNET_CRYPTO_rsa_key_free (pk);
141 GNUNET_free (enc);
142 break;
143 }
144 GNUNET_CRYPTO_rsa_key_free (pk);
145 GNUNET_free (enc);
146 }
147 if (0 == make_keys)
148 fprintf (stderr,
149 _("Finished!\n"));
150 fclose (f);
151}
152
153 51
154/** 52/**
155 * Main function that will be run by the scheduler. 53 * Main function that will be run by the scheduler.
@@ -174,11 +72,6 @@ run (void *cls, char *const *args, const char *cfgfile,
174 } 72 }
175 if (0 != weak_random) 73 if (0 != weak_random)
176 GNUNET_CRYPTO_random_disable_entropy_gathering (); 74 GNUNET_CRYPTO_random_disable_entropy_gathering ();
177 if (make_keys > 0)
178 {
179 create_keys (args[0]);
180 return;
181 }
182 pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]); 75 pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]);
183 if (NULL == pk) 76 if (NULL == pk)
184 return; 77 return;
@@ -225,9 +118,6 @@ int
225main (int argc, char *const*argv) 118main (int argc, char *const*argv)
226{ 119{
227 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 120 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
228 { 'g', "generate-keys", "COUNT",
229 gettext_noop ("create COUNT public-private key pairs (for testing)"),
230 1, &GNUNET_GETOPT_set_uint, &make_keys },
231 { 'p', "print-public-key", NULL, 121 { 'p', "print-public-key", NULL,
232 gettext_noop ("print the public key in ASCII format"), 122 gettext_noop ("print the public key in ASCII format"),
233 0, &GNUNET_GETOPT_set_one, &print_public_key }, 123 0, &GNUNET_GETOPT_set_one, &print_public_key },