GNUnet  0.20.0
crypto_ecc_setup.c File Reference

helper function for easy EdDSA key setup More...

#include "platform.h"
#include <gcrypt.h>
#include "gnunet_util_lib.h"
Include dependency graph for crypto_ecc_setup.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
 
#define LOG_STRERROR(kind, syscall)    GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
 
#define LOG_STRERROR_FILE(kind, syscall, filename)    GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)
 
#define LOG_GCRY(level, cmd, rc)
 Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by gcry_strerror(rc). More...
 

Functions

static enum GNUNET_GenericReturnValue read_from_file (const char *filename, void *buf, size_t buf_size)
 Read file to buf. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, int do_create, struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
 Create a new private key by reading it from a file. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, int do_create, struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey)
 Create a new private key by reading it from a file. More...
 
struct GNUNET_CRYPTO_EddsaPrivateKeyGNUNET_CRYPTO_eddsa_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Create a new private key by reading our peer's key from the file specified in the configuration. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
 Retrieve the identity of the host's peer. More...
 
void GNUNET_CRYPTO_eddsa_setup_key (const char *cfg_name)
 Setup a key file for a peer given the name of the configuration file (!). More...
 

Detailed Description

helper function for easy EdDSA key setup

Author
Christian Grothoff

Definition in file crypto_ecc_setup.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)

Definition at line 31 of file crypto_ecc_setup.c.

◆ LOG_STRERROR

#define LOG_STRERROR (   kind,
  syscall 
)     GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)

Definition at line 33 of file crypto_ecc_setup.c.

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  syscall,
  filename 
)     GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)

Definition at line 36 of file crypto_ecc_setup.c.

◆ LOG_GCRY

#define LOG_GCRY (   level,
  cmd,
  rc 
)
Value:
do \
{ \
LOG (level, \
_ ("`%s' failed at %s:%d with error: %s\n"), \
cmd, \
__FILE__, \
__LINE__, \
gcry_strerror (rc)); \
} while (0)
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the message given by gcry_strerror(rc).

Definition at line 44 of file crypto_ecc_setup.c.

Function Documentation

◆ read_from_file()

static enum GNUNET_GenericReturnValue read_from_file ( const char *  filename,
void *  buf,
size_t  buf_size 
)
static

Read file to buf.

Fails if the file does not exist or does not have precisely buf_size bytes.

Parameters
filenamefile to read
[out]bufwhere to write the file contents
buf_sizenumber of bytes in buf
Returns
GNUNET_OK on success

Definition at line 1 of file crypto_ecc_setup.c.

69 {
70  int fd;
71  struct stat sb;
72 
73  fd = open (filename,
74  O_RDONLY);
75  if (-1 == fd)
76  {
77  memset (buf,
78  0,
79  buf_size);
80  return GNUNET_SYSERR;
81  }
82  if (0 != fstat (fd,
83  &sb))
84  {
86  "stat",
87  filename);
88  GNUNET_assert (0 == close (fd));
89  memset (buf,
90  0,
91  buf_size);
92  return GNUNET_SYSERR;
93  }
94  if (sb.st_size != buf_size)
95  {
97  "File `%s' has wrong size (%llu), expected %llu bytes\n",
98  filename,
99  (unsigned long long) sb.st_size,
100  (unsigned long long) buf_size);
101  GNUNET_assert (0 == close (fd));
102  memset (buf,
103  0,
104  buf_size);
105  return GNUNET_SYSERR;
106  }
107  if (buf_size !=
108  read (fd,
109  buf,
110  buf_size))
111  {
113  "read",
114  filename);
115  GNUNET_assert (0 == close (fd));
116  memset (buf,
117  0,
118  buf_size);
119  return GNUNET_SYSERR;
120  }
121  GNUNET_assert (0 == close (fd));
122  return GNUNET_OK;
123 }
static char * filename
static char buf[2048]
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
#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_WARNING

◆ GNUNET_CRYPTO_eddsa_setup_key()

void GNUNET_CRYPTO_eddsa_setup_key ( const char *  cfg_name)

Setup a key file for a peer given the name of the configuration file (!).

This function is used so that at a later point code can be certain that reading a key is fast (for example in time-dependent testcases).

Parameters
cfg_namename of the configuration file to use

Definition at line 301 of file crypto_ecc_setup.c.

302 {
304  struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
305 
307  (void) GNUNET_CONFIGURATION_load (cfg, cfg_name);
309  if (NULL != priv)
310  GNUNET_free (priv);
312 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
#define GNUNET_free(ptr)
Wrapper around free.
Private ECC key encoded for transmission.

References cfg, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), and GNUNET_free.

Here is the call graph for this function: