GNUnet 0.22.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...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_by_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
 Sign a given block with a specific purpose using the host's peer identity. More...
 
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity (uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_PeerIdentity *identity)
 Verify a given signature with a peer's identity. 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 66 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",
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
#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

References filename, GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror_file, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_CRYPTO_ecdsa_key_from_file(), and GNUNET_CRYPTO_eddsa_key_from_file().

Here is the caller graph for this function: