+/* This function prettyprints the key generation process */
+
+void indicator(int a, int b, void *p)
+{
+ switch(a)
+ {
+ case 0:
+ fprintf(stderr, ".");
+ break;
+ case 1:
+ fprintf(stderr, "+");
+ break;
+ case 2:
+ fprintf(stderr, "-");
+ break;
+ case 3:
+ switch(b)
+ {
+ case 0:
+ fprintf(stderr, " p\n");
+ break;
+ case 1:
+ fprintf(stderr, " q\n");
+ break;
+ default:
+ fprintf(stderr, "?");
+ }
+ break;
+ default:
+ fprintf(stderr, "?");
+ }
+}
+
+/* Generate a public/private RSA keypair, and possibly store it into the configuration file. */
+
+int keygen(int bits)
+{
+ RSA *rsa_key;
+
+ fprintf(stderr, _("Generating %d bits keys:\n"), bits);
+ rsa_key = RSA_generate_key(bits, 0xFFFF, indicator, NULL);
+ if(!rsa_key)
+ {
+ fprintf(stderr, _("Error during key generation!"));
+ return -1;
+ }
+ else
+ fprintf(stderr, _("Done.\n"));
+
+ fprintf(stderr, _("Please copy the private key to tinc.conf and the\npublic key to your host configuration file:\n\n"));
+ printf("PublicKey = %s\n", BN_bn2hex(rsa_key->n));
+ printf("PrivateKey = %s\n", BN_bn2hex(rsa_key->d));
+
+ fflush(stdin);
+ return 0;
+}
+
+void memory_full(int size)