GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
secretsharing_api.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_secretsharing_service.h"
#include "secretsharing.h"
#include <gcrypt.h>
Include dependency graph for secretsharing_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_SECRETSHARING_Session
 Session that will eventually establish a shared secred between the involved peers and allow encryption and cooperative decryption. More...
 
struct  GNUNET_SECRETSHARING_DecryptionHandle
 Handle to cancel a cooperative decryption operation. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "secretsharing-api", __VA_ARGS__)
 

Functions

static void ensure_elgamal_initialized (void)
 Function to initialize elgamal_q, elgamal_p and elgamal_g. More...
 
static void handle_session_client_error (void *cls, enum GNUNET_MQ_Error error)
 Callback invoked when there is an error communicating with the service. More...
 
static void handle_decrypt_client_error (void *cls, enum GNUNET_MQ_Error error)
 Callback invoked when there is an error communicating with the service. More...
 
static int check_secret_ready (void *cls, const struct GNUNET_SECRETSHARING_SecretReadyMessage *m)
 Handler invoked with the final result message from secret sharing. More...
 
static void handle_secret_ready (void *cls, const struct GNUNET_SECRETSHARING_SecretReadyMessage *m)
 Handler invoked with the final result message from secret sharing. More...
 
void GNUNET_SECRETSHARING_session_destroy (struct GNUNET_SECRETSHARING_Session *s)
 Destroy a secret sharing session. More...
 
struct GNUNET_SECRETSHARING_SessionGNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int num_peers, const struct GNUNET_PeerIdentity *peers, const struct GNUNET_HashCode *session_id, struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute deadline, unsigned int threshold, GNUNET_SECRETSHARING_SecretReadyCallback cb, void *cls)
 Create a session that will eventually establish a shared secret with the other peers. More...
 
static void handle_decrypt_done (void *cls, const struct GNUNET_SECRETSHARING_DecryptResponseMessage *m)
 
struct GNUNET_SECRETSHARING_DecryptionHandleGNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SECRETSHARING_Share *share, const struct GNUNET_SECRETSHARING_Ciphertext *ciphertext, struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute deadline, GNUNET_SECRETSHARING_DecryptCallback decrypt_cb, void *decrypt_cb_cls)
 Publish the given ciphertext for decryption. More...
 
int GNUNET_SECRETSHARING_plaintext_generate_i (struct GNUNET_SECRETSHARING_Plaintext *plaintext, int64_t exponent)
 
int GNUNET_SECRETSHARING_encrypt (const struct GNUNET_SECRETSHARING_PublicKey *public_key, const struct GNUNET_SECRETSHARING_Plaintext *plaintext, struct GNUNET_SECRETSHARING_Ciphertext *result_ciphertext)
 Encrypt a value. More...
 
void GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *dh)
 Cancel a decryption. More...
 

Variables

static gcry_mpi_t elgamal_q
 The ElGamal prime field order as libgcrypt mpi. More...
 
static gcry_mpi_t elgamal_p
 Modulus of the prime field used for ElGamal. More...
 
static gcry_mpi_t elgamal_g
 Generator for prime field of order 'elgamal_q'. More...
 

Detailed Description

Author
Florian Dold

Definition in file secretsharing_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "secretsharing-api", __VA_ARGS__)

Function Documentation

◆ ensure_elgamal_initialized()

static void ensure_elgamal_initialized ( void  )
static

Function to initialize elgamal_q, elgamal_p and elgamal_g.

Definition at line 103 of file secretsharing_api.c.

References elgamal_g, elgamal_p, elgamal_q, GNUNET_assert, GNUNET_SECRETSHARING_ELGAMAL_G_HEX, GNUNET_SECRETSHARING_ELGAMAL_P_HEX, and GNUNET_SECRETSHARING_ELGAMAL_Q_HEX.

Referenced by GNUNET_SECRETSHARING_encrypt(), and GNUNET_SECRETSHARING_plaintext_generate_i().

104 {
105  if (NULL != elgamal_q)
106  return; /* looks like crypto is already initialized */
107 
108  GNUNET_assert (0 == gcry_mpi_scan (&elgamal_q, GCRYMPI_FMT_HEX,
110  NULL));
111  GNUNET_assert (0 == gcry_mpi_scan (&elgamal_p, GCRYMPI_FMT_HEX,
113  NULL));
114  GNUNET_assert (0 == gcry_mpi_scan (&elgamal_g, GCRYMPI_FMT_HEX,
116  NULL));
117 }
#define GNUNET_SECRETSHARING_ELGAMAL_G_HEX
The g-parameter for ElGamal encryption, a generator of the unique size q subgroup of Z_p^*...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_SECRETSHARING_ELGAMAL_Q_HEX
The q-parameter for ElGamal encryption, a 1023-bit Sophie Germain prime, q = (p-1)/2.
#define GNUNET_SECRETSHARING_ELGAMAL_P_HEX
The q-parameter for ElGamal encryption, a 1024-bit safe prime.
static gcry_mpi_t elgamal_p
Modulus of the prime field used for ElGamal.
static gcry_mpi_t elgamal_g
Generator for prime field of order &#39;elgamal_q&#39;.
static gcry_mpi_t elgamal_q
The ElGamal prime field order as libgcrypt mpi.
Here is the caller graph for this function:

◆ handle_session_client_error()

static void handle_session_client_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Callback invoked when there is an error communicating with the service.

Notifies the application about the error.

Parameters
clsthe struct GNUNET_SECRETSHARING_Session
errorerror code

Definition at line 128 of file secretsharing_api.c.

References GNUNET_SECRETSHARING_session_destroy(), GNUNET_SECRETSHARING_Session::secret_ready_cb, and GNUNET_SECRETSHARING_Session::secret_ready_cls.

Referenced by GNUNET_SECRETSHARING_create_session().

130 {
131  struct GNUNET_SECRETSHARING_Session *s = cls;
132 
133  s->secret_ready_cb (s->secret_ready_cls, NULL, NULL, 0, NULL);
135 }
GNUNET_SECRETSHARING_SecretReadyCallback secret_ready_cb
Called when the secret sharing is done.
void * secret_ready_cls
Closure for secret_ready_cb.
void GNUNET_SECRETSHARING_session_destroy(struct GNUNET_SECRETSHARING_Session *s)
Destroy a secret sharing session.
Session that will eventually establish a shared secred between the involved peers and allow encryptio...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_decrypt_client_error()

static void handle_decrypt_client_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Callback invoked when there is an error communicating with the service.

Notifies the application about the error.

Parameters
clsthe struct GNUNET_SECRETSHARING_DecryptionHandle
errorerror code

Definition at line 146 of file secretsharing_api.c.

References GNUNET_SECRETSHARING_DecryptionHandle::decrypt_cb, GNUNET_SECRETSHARING_DecryptionHandle::decrypt_cls, and GNUNET_SECRETSHARING_decrypt_cancel().

Referenced by GNUNET_SECRETSHARING_decrypt().

148 {
149  struct GNUNET_SECRETSHARING_DecryptionHandle *dh = cls;
150 
151  dh->decrypt_cb (dh->decrypt_cls, NULL);
153 }
GNUNET_SECRETSHARING_DecryptCallback decrypt_cb
Called when the secret sharing is done.
void GNUNET_SECRETSHARING_decrypt_cancel(struct GNUNET_SECRETSHARING_DecryptionHandle *dh)
Cancel a decryption.
Handle to cancel a cooperative decryption operation.
void * decrypt_cls
Closure for decrypt_cb.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_secret_ready()

static int check_secret_ready ( void *  cls,
const struct GNUNET_SECRETSHARING_SecretReadyMessage m 
)
static

Handler invoked with the final result message from secret sharing.

Decodes the message and passes the result to the application.

Parameters
clsthe struct GNUNET_SECRETSHARING_Session
mmessage with the result

Definition at line 165 of file secretsharing_api.c.

References GNUNET_OK.

167 {
168  /* FIXME: actually check m is well-formed here! */
169  return GNUNET_OK;
170 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_secret_ready()

static void handle_secret_ready ( void *  cls,
const struct GNUNET_SECRETSHARING_SecretReadyMessage m 
)
static

Handler invoked with the final result message from secret sharing.

Decodes the message and passes the result to the application.

Parameters
clsthe struct GNUNET_SECRETSHARING_Session
mmessage with the result

Definition at line 182 of file secretsharing_api.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SECRETSHARING_session_destroy(), GNUNET_SECRETSHARING_share_read(), GNUNET_SECRETSHARING_SecretReadyMessage::header, LOG, GNUNET_SECRETSHARING_Share::num_peers, GNUNET_SECRETSHARING_Share::public_key, GNUNET_SECRETSHARING_Session::secret_ready_cb, GNUNET_SECRETSHARING_Session::secret_ready_cls, and GNUNET_MessageHeader::size.

184 {
185  struct GNUNET_SECRETSHARING_Session *s = cls;
186  struct GNUNET_SECRETSHARING_Share *share;
187  size_t share_size;
188 
190  "Got secret ready message of size %u\n",
191  ntohs (m->header.size));
192  share_size = ntohs (m->header.size) - sizeof(struct
194 
195  share = GNUNET_SECRETSHARING_share_read (&m[1],
196  share_size,
197  NULL);
198  GNUNET_assert (NULL != share); // FIXME: this can fail!
199  // should have been checked in #check_secret_ready!
200  // FIXME: below we never check &m[1] is valid!
201  // FIXME: do we leak 'share' here?
203  share, /* FIXME */
204  &share->public_key,
205  share->num_peers,
206  (const struct GNUNET_PeerIdentity *) &m[1]);
207 
209 }
struct GNUNET_SECRETSHARING_Share * GNUNET_SECRETSHARING_share_read(const void *data, size_t len, size_t *readlen)
Read a share from its binary representation.
GNUNET_SECRETSHARING_SecretReadyCallback secret_ready_cb
Called when the secret sharing is done.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A share, with all values in in host byte order.
void * secret_ready_cls
Closure for secret_ready_cb.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_SECRETSHARING_session_destroy(struct GNUNET_SECRETSHARING_Session *s)
Destroy a secret sharing session.
#define LOG(kind,...)
Session that will eventually establish a shared secred between the involved peers and allow encryptio...
The identity of the host (wraps the signing key of the peer).
uint16_t num_peers
Peers that have the share.
struct GNUNET_SECRETSHARING_PublicKey public_key
Public key.
Notify the client that then threshold secret has been established.
Here is the call graph for this function:

◆ handle_decrypt_done()

static void handle_decrypt_done ( void *  cls,
const struct GNUNET_SECRETSHARING_DecryptResponseMessage m 
)
static

Definition at line 303 of file secretsharing_api.c.

References GNUNET_SECRETSHARING_DecryptionHandle::decrypt_cb, GNUNET_SECRETSHARING_DecryptionHandle::decrypt_cls, GNUNET_SECRETSHARING_decrypt_cancel(), GNUNET_SECRETSHARING_DecryptResponseMessage::plaintext, and GNUNET_SECRETSHARING_DecryptResponseMessage::success.

306 {
307  struct GNUNET_SECRETSHARING_DecryptionHandle *dh = cls;
308  const struct GNUNET_SECRETSHARING_Plaintext *plaintext;
309 
310  if (m->success == 0)
311  plaintext = NULL;
312  else
313  plaintext = (void *) &m->plaintext;
314  dh->decrypt_cb (dh->decrypt_cls, plaintext);
316 }
struct GNUNET_SECRETSHARING_FieldElement plaintext
Decrypted plaintext.
GNUNET_SECRETSHARING_DecryptCallback decrypt_cb
Called when the secret sharing is done.
void GNUNET_SECRETSHARING_decrypt_cancel(struct GNUNET_SECRETSHARING_DecryptionHandle *dh)
Cancel a decryption.
Handle to cancel a cooperative decryption operation.
uint32_t success
Zero if decryption failed, non-zero if decryption succeeded.
Plain, unencrypted message that can be encrypted with a group public key.
void * decrypt_cls
Closure for decrypt_cb.
Here is the call graph for this function:

Variable Documentation

◆ elgamal_q

gcry_mpi_t elgamal_q
static

The ElGamal prime field order as libgcrypt mpi.

Initialized in init_crypto_constants.

Definition at line 84 of file secretsharing_api.c.

Referenced by ensure_elgamal_initialized(), and GNUNET_SECRETSHARING_encrypt().

◆ elgamal_p

gcry_mpi_t elgamal_p
static

Modulus of the prime field used for ElGamal.

Initialized in init_crypto_constants.

Definition at line 90 of file secretsharing_api.c.

Referenced by ensure_elgamal_initialized(), GNUNET_SECRETSHARING_encrypt(), and GNUNET_SECRETSHARING_plaintext_generate_i().

◆ elgamal_g

gcry_mpi_t elgamal_g
static

Generator for prime field of order 'elgamal_q'.

Initialized in init_crypto_constants.

Definition at line 96 of file secretsharing_api.c.

Referenced by ensure_elgamal_initialized(), GNUNET_SECRETSHARING_encrypt(), and GNUNET_SECRETSHARING_plaintext_generate_i().