diff options
-rw-r--r-- | doc/man/gnunet-rsa.1 | 3 | ||||
-rw-r--r-- | src/util/gnunet-rsa.c | 65 |
2 files changed, 68 insertions, 0 deletions
diff --git a/doc/man/gnunet-rsa.1 b/doc/man/gnunet-rsa.1 index 46f24de1c..c61bc1fd3 100644 --- a/doc/man/gnunet-rsa.1 +++ b/doc/man/gnunet-rsa.1 | |||
@@ -13,6 +13,9 @@ gnunet\-rsa \- manipulate GNUnet RSA key files | |||
13 | 13 | ||
14 | .SH OPTIONS | 14 | .SH OPTIONS |
15 | .B | 15 | .B |
16 | .IP "\-g COUNT, \-\-generate-keys=COUNT" | ||
17 | Create COUNT public-private key pairs and write them to FILENAME. Used for creating a file for testing. | ||
18 | .B | ||
16 | .IP "\-p, \-\-print-public-key" | 19 | .IP "\-p, \-\-print-public-key" |
17 | Print the corresponding public key to stdout. | 20 | Print the corresponding public key to stdout. |
18 | .B | 21 | .B |
diff --git a/src/util/gnunet-rsa.c b/src/util/gnunet-rsa.c index e9fbf15df..69b500100 100644 --- a/src/util/gnunet-rsa.c +++ b/src/util/gnunet-rsa.c | |||
@@ -48,6 +48,10 @@ static int print_short_identity; | |||
48 | */ | 48 | */ |
49 | static int weak_random; | 49 | static int weak_random; |
50 | 50 | ||
51 | /** | ||
52 | * Option set to create a bunch of keys at once. | ||
53 | */ | ||
54 | static unsigned int make_keys; | ||
51 | 55 | ||
52 | /** | 56 | /** |
53 | * The private information of an RSA key pair. | 57 | * The private information of an RSA key pair. |
@@ -89,6 +93,59 @@ GNUNET_CRYPTO_rsa_key_create () | |||
89 | 93 | ||
90 | 94 | ||
91 | /** | 95 | /** |
96 | * Create a flat file with a large number of key pairs for testing. | ||
97 | */ | ||
98 | static void | ||
99 | create_keys (const char *fn) | ||
100 | { | ||
101 | time_t start; | ||
102 | struct GNUNET_HashCode hc; | ||
103 | struct GNUNET_HashCode h2; | ||
104 | struct GNUNET_HashCode h3; | ||
105 | FILE *f; | ||
106 | struct GNUNET_CRYPTO_RsaPrivateKey *pk; | ||
107 | struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *enc; | ||
108 | |||
109 | start = time (NULL); | ||
110 | GNUNET_CRYPTO_hash (&start, sizeof (start), &hc); | ||
111 | if (NULL == (f = fopen (fn, "w+"))) | ||
112 | { | ||
113 | fprintf (stderr, | ||
114 | _("Failed to open `%s': %s\n"), | ||
115 | fn, | ||
116 | STRERROR (errno)); | ||
117 | return; | ||
118 | } | ||
119 | fprintf (stderr, | ||
120 | _("Generating %u keys, please wait"), | ||
121 | make_keys); | ||
122 | while (0 < make_keys--) | ||
123 | { | ||
124 | fprintf (stderr, | ||
125 | "."); | ||
126 | GNUNET_CRYPTO_hash (&make_keys, sizeof (make_keys), &h2); | ||
127 | GNUNET_CRYPTO_hash (&hc, sizeof (hc), &h3); | ||
128 | GNUNET_CRYPTO_hash_xor (&h2, &h3, &hc); | ||
129 | pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc); | ||
130 | enc = GNUNET_CRYPTO_rsa_encode_key (pk); | ||
131 | if (htons (enc->len) != fwrite (enc, 1, htons (enc->len), f)) | ||
132 | { | ||
133 | fprintf (stderr, | ||
134 | _("\nFailed to write to `%s': %s\n"), | ||
135 | fn, | ||
136 | STRERROR (errno)); | ||
137 | break; | ||
138 | } | ||
139 | GNUNET_CRYPTO_rsa_key_free (pk); | ||
140 | } | ||
141 | if (0 == make_keys) | ||
142 | fprintf (stderr, | ||
143 | _("Finished!\n")); | ||
144 | fclose (f); | ||
145 | } | ||
146 | |||
147 | |||
148 | /** | ||
92 | * Main function that will be run by the scheduler. | 149 | * Main function that will be run by the scheduler. |
93 | * | 150 | * |
94 | * @param cls closure | 151 | * @param cls closure |
@@ -111,6 +168,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
111 | } | 168 | } |
112 | if (0 != weak_random) | 169 | if (0 != weak_random) |
113 | GNUNET_CRYPTO_random_disable_entropy_gathering (); | 170 | GNUNET_CRYPTO_random_disable_entropy_gathering (); |
171 | if (make_keys > 0) | ||
172 | { | ||
173 | create_keys (args[0]); | ||
174 | return; | ||
175 | } | ||
114 | pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]); | 176 | pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]); |
115 | if (NULL == pk) | 177 | if (NULL == pk) |
116 | return; | 178 | return; |
@@ -157,6 +219,9 @@ int | |||
157 | main (int argc, char *const *argv) | 219 | main (int argc, char *const *argv) |
158 | { | 220 | { |
159 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 221 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
222 | { 'g', "generate-keys", "COUNT", | ||
223 | gettext_noop ("create COUNT public-private key pairs (for testing)"), | ||
224 | 1, &GNUNET_GETOPT_set_uint, &make_keys }, | ||
160 | { 'p', "print-public-key", NULL, | 225 | { 'p', "print-public-key", NULL, |
161 | gettext_noop ("print the public key in ASCII format"), | 226 | gettext_noop ("print the public key in ASCII format"), |
162 | 0, &GNUNET_GETOPT_set_one, &print_public_key }, | 227 | 0, &GNUNET_GETOPT_set_one, &print_public_key }, |