35#define KEY_STR_LEN sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) * 8 / 5 + 1
93 if (NULL == (
f = fopen (fn,
"w+")))
95 fprintf (stderr,
_ (
"Failed to open `%s': %s\n"), fn, strerror (errno));
111 {mask = ~((
int) pow (2, 8 - rest) - 1);
120 target_byte = ((
unsigned char *) &target_pub)[n] & mask;
125 mask = target_byte = 0;
129 _ (
"Generating %u keys like %s, please wait"),
133 fprintf (stderr,
"\nattempt %s [%u, %X]\n", vanity, (
unsigned int) n, mask);
137 fprintf (stderr,
_ (
"Generating %u keys, please wait"),
make_keys);
139 n = rest = target_byte = mask = 0;
144 fprintf (stderr,
".");
152 if (0 != memcmp (&target_pub,
161 unsigned char new_byte;
163 new_byte = ((
unsigned char *) &newkey)[n] & mask;
164 if (target_byte != new_byte)
178 _ (
"\nFailed to write to `%s': %s\n"),
185 fprintf (stderr,
_ (
"\nFinished!\n"));
187 fprintf (stderr,
_ (
"\nError, %u keys not generated\n"),
make_keys);
195 printf (
"%s: ",
msg);
196 for (
size_t i = 0; i <
size; i++)
198 printf (
"%02hhx", ((
const uint8_t *) buf)[i]);
226 printf (
"ECDHE key 1:\n");
227 printf (
"private: %s\n",
230 &dh_priv1,
sizeof (dh_priv1));
236 printf (
"public: %s\n",
247 printf (
"ECDHE key 2:\n");
248 printf (
"private: %s\n", buf);
257 printf (
"public: %s\n", buf);
271 printf (
"ECDH shared secret: %s\n",
298 unsigned int total_hostkeys;
304 fprintf (stderr,
_ (
"Hostkeys file `%s' not found\n"),
filename);
318 _ (
"Hostkeys file `%s' is empty\n"),
filename);
324 _ (
"Incorrect hostkey file format: %s\n"),
338 if ((sret < 0) || (
fs != (
size_t) sret))
340 fprintf (stderr,
_ (
"Could not read hostkey file: %s\n"),
filename);
347 if (NULL == hostkeys_data)
357 if (NULL != hostkey_str)
359 fprintf (stderr,
"%4u: %s\n", c, hostkey_str);
363 fprintf (stderr,
"%4u: %s\n", c,
"invalid");
394 fprintf (stderr,
"%s",
_ (
"No hostkey file specified on command line\n"));
429 fprintf (stdout,
"%s\n", str);
435 fprintf (stdout,
"%s\n", str);
452main (
int argc,
char *
const *argv)
458 "list keys included in a file (for testing)"),
464 gettext_noop (
"number of keys to list included in a file (for testing)"),
470 gettext_noop (
"create COUNT public-private key pairs (for testing)"),
475 "print the public key in ASCII format"),
480 "print the private key in ASCII format"),
485 "print the public key in HEX format"),
491 "print examples of ECC operations (used for compatibility testing)"),
501 "gnunet-ecc [OPTIONS] keyfile [VANITY_PREFIX]",
503 "Manipulate GNUnet private ECC key files"),
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MessageHeader * msg
#define gettext_noop(String)
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static int prefix
If printing the value of PREFIX has been requested.
static void print_examples(void)
Print some random example operations to stdout.
static int list_keys
Flag for listing public key.
#define KEY_STR_LEN
Number of characters a Base32-encoded public key requires.
static int print_public_key_hex
Flag for printing public key in hex.
static void print_key(const char *filename)
static int print_private_key
Flag for printing private key.
static unsigned int make_keys
Option set to create a bunch of keys at once.
static void print_examples_ecdh(void)
static unsigned int list_keys_count
Flag for listing public key.
static int print_public_key
Flag for printing public key.
static void create_keys(const char *fn, const char *prefix)
Create a flat file with a large number of key pairs for testing.
static void print_hex(const char *msg, const void *buf, size_t size)
static int print_examples_flag
Flag for printing the output of random example operations.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
int main(int argc, char *const *argv)
Program to manipulate ECC key files.
static struct GNUNET_FS_Handle * fs
Handle to FS service.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_ecdh(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a public and a private ECC key.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
void GNUNET_CRYPTO_eddsa_key_create(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Create a new private key.
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
char * GNUNET_CRYPTO_eddsa_private_key_to_string(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Convert a private key to a string.
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
static unsigned int size
Size of the "table".
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.
Definition of a command line option.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key