GNUnet  0.17.6
Macros | Functions
crypto_mpi.c File Reference

Helper functions for libgcrypt MPIs. More...

#include "platform.h"
#include <gcrypt.h>
#include "gnunet_crypto_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 32 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:32
#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 39 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 54 of file crypto_mpi.c.

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

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

162 {
163  int rc;
164 
165  if (0 != (rc = gcry_mpi_scan (result,
166  GCRYMPI_FMT_USG,
167  data, size, &size)))
168  {
170  "gcry_mpi_scan",
171  rc);
172  GNUNET_assert (0);
173  }
174 }
#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:39
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.