GNUnet  0.19.2
crypto_mpi.c File Reference

Helper functions for libgcrypt MPIs. More...

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

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-crypto-mpi", __VA_ARGS__)
 
#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 void adjust (void *buf, size_t size, size_t target)
 If target != size, move target bytes to the end of the size-sized buffer and zero out the first target - size bytes. More...
 
void GNUNET_CRYPTO_mpi_print_unsigned (void *buf, size_t size, gcry_mpi_t val)
 Output the given MPI value to the given buffer in network byte order. More...
 
void GNUNET_CRYPTO_mpi_scan_unsigned (gcry_mpi_t *result, const void *data, size_t size)
 Convert data buffer into MPI value. More...
 
void GNUNET_CRYPTO_mpi_scan_unsigned_le (gcry_mpi_t *result, const void *data, size_t size)
 Convert little endian data buffer into MPI value. More...
 

Detailed Description

Helper functions for libgcrypt MPIs.

Author
Christian Grothoff
Florian Dold

Definition in file crypto_mpi.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 33 of file crypto_mpi.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 LOG(kind,...)
Definition: crypto_mpi.c:33
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

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 40 of file crypto_mpi.c.

Function Documentation

◆ adjust()

static void adjust ( void *  buf,
size_t  size,
size_t  target 
)
static

If target != size, move target bytes to the end of the size-sized buffer and zero out the first target - size bytes.

Parameters
buforiginal buffer
sizenumber of bytes in buf
targettarget size of the buffer

Definition at line 55 of file crypto_mpi.c.

58 {
59  char *p = buf;
60 
61  if (size < target)
62  {
63  memmove (&p[target - size], buf, size);
64  memset (buf, 0, target - size);
65  }
66 }
static char buf[2048]
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
static unsigned int size
Size of the "table".
Definition: peer.c:68

References buf, p, and size.

Referenced by GNUNET_CRYPTO_mpi_print_unsigned().

Here is the caller graph for this function:

◆ GNUNET_CRYPTO_mpi_scan_unsigned_le()

void GNUNET_CRYPTO_mpi_scan_unsigned_le ( gcry_mpi_t *  result,
const void *  data,
size_t  size 
)

Convert little endian data buffer into MPI value.

The buffer is interpreted as network byte order, unsigned integer.

Parameters
resultwhere to store MPI value (allocated)
dataraw data (GCRYMPI_FMT_USG)
sizenumber of bytes in data

Definition at line 160 of file crypto_mpi.c.

163 {
164  int rc;
165 
166  if (0 != (rc = gcry_mpi_scan (result,
167  GCRYMPI_FMT_USG,
168  data, size, &size)))
169  {
171  "gcry_mpi_scan",
172  rc);
173  GNUNET_assert (0);
174  }
175 }
#define LOG_GCRY(level, cmd, rc)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
Definition: crypto_mpi.c:40
uint32_t data
The data value.
static int result
Global testing status.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR

References data, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, LOG_GCRY, result, and size.