GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
Secret Sharing service

Verifiable additive secret sharing and cooperative decryption. More...

Data Structures

struct  GNUNET_SECRETSHARING_PublicKey
 Public key of a group sharing a secret. More...
 
struct  GNUNET_SECRETSHARING_Ciphertext
 Encrypted field element. More...
 
struct  GNUNET_SECRETSHARING_Plaintext
 Plain, unencrypted message that can be encrypted with a group public key. More...
 

Macros

#define GNUNET_SECRETSHARING_ELGAMAL_BITS   1024
 Number of bits for secretsharing elements. More...
 
#define GNUNET_SECRETSHARING_ELGAMAL_P_HEX
 The q-parameter for ElGamal encryption, a 1024-bit safe prime. More...
 
#define GNUNET_SECRETSHARING_ELGAMAL_Q_HEX
 The q-parameter for ElGamal encryption, a 1023-bit Sophie Germain prime, q = (p-1)/2. More...
 
#define GNUNET_SECRETSHARING_ELGAMAL_G_HEX
 The g-parameter for ElGamal encryption, a generator of the unique size q subgroup of Z_p^*. More...
 

Typedefs

typedef void(* GNUNET_SECRETSHARING_SecretReadyCallback) (void *cls, struct GNUNET_SECRETSHARING_Share *my_share, struct GNUNET_SECRETSHARING_PublicKey *public_key, unsigned int num_ready_peers, const struct GNUNET_PeerIdentity *ready_peers)
 Called once the secret has been established with all peers, or the deadline is due. More...
 
typedef void(* GNUNET_SECRETSHARING_DecryptCallback) (void *cls, const struct GNUNET_SECRETSHARING_Plaintext *plaintext)
 Called when a decryption has succeeded. More...
 

Functions

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...
 
void GNUNET_SECRETSHARING_session_destroy (struct GNUNET_SECRETSHARING_Session *s)
 Destroy a secret sharing session. More...
 
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...
 
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...
 
void GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *dh)
 Cancel a decryption. More...
 
struct GNUNET_SECRETSHARING_ShareGNUNET_SECRETSHARING_share_read (const void *data, size_t len, size_t *readlen)
 Read a share from its binary representation. More...
 
int GNUNET_SECRETSHARING_share_write (const struct GNUNET_SECRETSHARING_Share *share, void *buf, size_t buflen, size_t *writelen)
 Convert a share to its binary representation. More...
 
void GNUNET_SECRETSHARING_share_destroy (struct GNUNET_SECRETSHARING_Share *share)
 
int GNUNET_SECRETSHARING_plaintext_generate (struct GNUNET_SECRETSHARING_Plaintext *plaintext, gcry_mpi_t exponent)
 
int GNUNET_SECRETSHARING_plaintext_generate_i (struct GNUNET_SECRETSHARING_Plaintext *plaintext, int64_t exponent)
 

Detailed Description

Verifiable additive secret sharing and cooperative decryption.

Macro Definition Documentation

◆ GNUNET_SECRETSHARING_ELGAMAL_BITS

#define GNUNET_SECRETSHARING_ELGAMAL_BITS   1024

Number of bits for secretsharing elements.

Must be smaller than the Pallier key size used internally by the secretsharing service. When changing this value, other internal parameters must also be adjusted.

Definition at line 56 of file gnunet_secretsharing_service.h.

Referenced by decrypt_conclude(), decrypt_new_element(), encrypt_fair(), generate_presecret_polynomial(), get_fair_encryption_challenge(), GNUNET_SECRETSHARING_encrypt(), insert_decrypt_element(), insert_round1_element(), insert_round2_element(), keygen_reveal_get_exp_coeff(), keygen_reveal_get_exp_preshare(), keygen_round2_conclude(), keygen_round2_new_element(), and verify_fair().

◆ GNUNET_SECRETSHARING_ELGAMAL_P_HEX

#define GNUNET_SECRETSHARING_ELGAMAL_P_HEX
Value:
"0x08a347d3d69e8b2dd7d1b12a08dfbccbebf4ca" \
"6f4269a0814e158a34312964d946b3ef22882317" \
"2bcf30fc08f772774cb404f9bc002a6f66b09a79" \
"d810d67c4f8cb3bedc6060e3c8ef874b1b64df71" \
"6c7d2b002da880e269438d5a776e6b5f253c8df5" \
"6a16b1c7ce58def07c03db48238aadfc52a354a2" \
"7ed285b0c1675cad3f3"

The q-parameter for ElGamal encryption, a 1024-bit safe prime.

Definition at line 62 of file gnunet_secretsharing_service.h.

Referenced by ensure_elgamal_initialized(), and init_crypto_constants().

◆ GNUNET_SECRETSHARING_ELGAMAL_Q_HEX

#define GNUNET_SECRETSHARING_ELGAMAL_Q_HEX
Value:
"0x0451a3e9eb4f4596ebe8d895046fde65f5fa65" \
"37a134d040a70ac51a1894b26ca359f79144118b" \
"95e7987e047bb93ba65a027cde001537b3584d3c" \
"ec086b3e27c659df6e303071e477c3a58db26fb8" \
"b63e958016d4407134a1c6ad3bb735af929e46fa" \
"b50b58e3e72c6f783e01eda411c556fe2951aa51" \
"3f6942d860b3ae569f9"

The q-parameter for ElGamal encryption, a 1023-bit Sophie Germain prime, q = (p-1)/2.

Definition at line 75 of file gnunet_secretsharing_service.h.

Referenced by ensure_elgamal_initialized(), and init_crypto_constants().

◆ GNUNET_SECRETSHARING_ELGAMAL_G_HEX

#define GNUNET_SECRETSHARING_ELGAMAL_G_HEX
Value:
"0x05c00c36d2e822950087ef09d8252994adc4e4" \
"8fe3ec70269f035b46063aff0c99b633fd64df43" \
"02442e1914c829a41505a275438871f365e91c12" \
"3d5303ef9e90f4b8cb89bf86cc9b513e74a72634" \
"9cfd9f953674fab5d511e1c078fc72d72b34086f" \
"c82b4b951989eb85325cb203ff98df76bc366bba" \
"1d7024c3650f60d0da"

The g-parameter for ElGamal encryption, a generator of the unique size q subgroup of Z_p^*.

Definition at line 88 of file gnunet_secretsharing_service.h.

Referenced by ensure_elgamal_initialized(), and init_crypto_constants().

Typedef Documentation

◆ GNUNET_SECRETSHARING_SecretReadyCallback

typedef void(* GNUNET_SECRETSHARING_SecretReadyCallback) (void *cls, struct GNUNET_SECRETSHARING_Share *my_share, struct GNUNET_SECRETSHARING_PublicKey *public_key, unsigned int num_ready_peers, const struct GNUNET_PeerIdentity *ready_peers)

Called once the secret has been established with all peers, or the deadline is due.

Note that the number of peers can be smaller than 'k' (this threshold parameter), which makes the threshold crypto system useless. However, in this case one can still determine which peers were able to participate in the secret sharing successfully.

If the secret sharing failed, num_ready_peers is 0 and my_share and public_key is NULL.

After this callback has been called, the secretsharing session will be invalid.

Parameters
clsclosure
my_sharethe share of this peer
public_keypublic key of the session
num_ready_peersnumber of peers in ready_peers
ready_peerspeers that successfuly participated in establishing the shared secret

Definition at line 171 of file gnunet_secretsharing_service.h.

◆ GNUNET_SECRETSHARING_DecryptCallback

typedef void(* GNUNET_SECRETSHARING_DecryptCallback) (void *cls, const struct GNUNET_SECRETSHARING_Plaintext *plaintext)

Called when a decryption has succeeded.

Parameters
clsclosure
datadecrypted value
data_sizenumber of bytes in data

Definition at line 190 of file gnunet_secretsharing_service.h.

Function Documentation

◆ GNUNET_SECRETSHARING_create_session()

struct GNUNET_SECRETSHARING_Session* GNUNET_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.

Parameters
cfgconfiguration to use
num_peersnumber of peers in peers
peersarray of peers that we will share secrets with, can optionally contain the local peer
session_idunique session id
startWhen should all peers be available for sharing the secret? Random number generation can take place before the start time.
deadlinepoint in time where the session must be established; taken as hint by underlying consensus sessions
thresholdminimum number of peers that must cooperate to decrypt a value
cbcalled when the secret has been established
clsclosure for cb

Definition at line 244 of file secretsharing_api.c.

References GNUNET_SECRETSHARING_CreateMessage::deadline, GNUNET_break, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_GENERATE, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, GNUNET_TIME_absolute_hton(), handle_session_client_error(), LOG, GNUNET_SECRETSHARING_Session::mq, msg, GNUNET_SECRETSHARING_CreateMessage::num_peers, GNUNET_SECRETSHARING_Session::secret_ready_cb, GNUNET_SECRETSHARING_Session::secret_ready_cls, GNUNET_SECRETSHARING_CreateMessage::session_id, session_id, GNUNET_SECRETSHARING_CreateMessage::start, and GNUNET_SECRETSHARING_CreateMessage::threshold.

Referenced by session_connect_adapter().

254 {
257  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
258  GNUNET_MQ_hd_var_size (secret_ready,
261  s),
263  };
264  struct GNUNET_MQ_Envelope *ev;
266 
267  s->mq = GNUNET_CLIENT_connect (cfg,
268  "secretsharing",
269  mq_handlers,
271  s);
272  if (NULL == s->mq)
273  {
274  /* secretsharing not configured correctly */
275  GNUNET_break (0);
276  GNUNET_free (s);
277  return NULL;
278  }
279  s->secret_ready_cb = cb;
280  s->secret_ready_cls = cls;
281  ev = GNUNET_MQ_msg_extra (msg,
282  num_peers * sizeof(struct GNUNET_PeerIdentity),
284 
285  msg->threshold = htons (threshold);
286  msg->num_peers = htons (num_peers);
287  msg->session_id = *session_id;
288  msg->start = GNUNET_TIME_absolute_hton (start);
289  msg->deadline = GNUNET_TIME_absolute_hton (deadline);
290  GNUNET_memcpy (&msg[1], peers, num_peers * sizeof(struct
292 
293  GNUNET_MQ_send (s->mq, ev);
294 
296  "Secretsharing session created with %u peers\n",
297  num_peers);
298  return s;
299 }
struct GNUNET_TIME_AbsoluteNBO start
Start time for communication with the other peers.
Definition: secretsharing.h:62
static unsigned int threshold
What should the threshold for then key be?
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
GNUNET_SECRETSHARING_SecretReadyCallback secret_ready_cb
Called when the secret sharing is done.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
static void handle_session_client_error(void *cls, enum GNUNET_MQ_Error error)
Callback invoked when there is an error communicating with the service.
struct GNUNET_MQ_Handle * mq
Message queue for client.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static struct GNUNET_HashCode session_id
void * secret_ready_cls
Closure for secret_ready_cb.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
struct GNUNET_TIME_AbsoluteNBO deadline
Deadline for the establishment of the crypto system.
Definition: secretsharing.h:67
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define LOG(kind,...)
Message handler for a specific message type.
uint16_t threshold
Mininum number of cooperating peers to decrypt a value.
Definition: secretsharing.h:73
Session that will eventually establish a shared secred between the involved peers and allow encryptio...
static unsigned int num_peers
The identity of the host (wraps the signing key of the peer).
uint16_t num_peers
Number of peers at the end of this message.
Definition: secretsharing.h:78
#define GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY
The cryptosystem has been established.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
#define GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_GENERATE
Establish a new session.
struct GNUNET_HashCode session_id
Session ID, will be used for consensus.
Definition: secretsharing.h:57
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Notify the client that then threshold secret has been established.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SECRETSHARING_session_destroy()

void GNUNET_SECRETSHARING_session_destroy ( struct GNUNET_SECRETSHARING_Session s)

Destroy a secret sharing session.

The secret ready callback will not be called.

Parameters
ssession to destroy

Definition at line 219 of file secretsharing_api.c.

References GNUNET_free, GNUNET_MQ_destroy(), and GNUNET_SECRETSHARING_Session::mq.

Referenced by handle_secret_ready(), handle_session_client_error(), and session_disconnect_adapter().

220 {
221  GNUNET_MQ_destroy (s->mq);
222  s->mq = NULL;
223  GNUNET_free (s);
224 }
struct GNUNET_MQ_Handle * mq
Message queue for client.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SECRETSHARING_encrypt()

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.

This operation is executed locally, no communication is necessary.

This is a helper function, encryption can be done soley with a session's public key and the crypto system parameters.

Parameters
public_keypublic key to use for decryption
messagemessage to encrypt
message_sizenumber of bytes in message
result_ciphertextpointer to store the resulting ciphertext
Returns
GNUNET_YES on succes, GNUNET_SYSERR if the message is invalid (invalid range)

Definition at line 448 of file secretsharing_api.c.

References GNUNET_SECRETSHARING_Ciphertext::c1_bits, GNUNET_SECRETSHARING_Ciphertext::c2_bits, elgamal_g, elgamal_p, elgamal_q, ensure_elgamal_initialized(), GNUNET_assert, GNUNET_CRYPTO_mpi_print_unsigned(), GNUNET_CRYPTO_mpi_scan_unsigned(), GNUNET_OK, GNUNET_SECRETSHARING_ELGAMAL_BITS, h, and m.

Referenced by session_disconnect_adapter().

454 {
455  /* pubkey */
456  gcry_mpi_t h;
457  /* nonce */
458  gcry_mpi_t y;
459  /* plaintext message */
460  gcry_mpi_t m;
461  /* temp value */
462  gcry_mpi_t tmp;
463 
465 
466  GNUNET_assert (NULL != (h = gcry_mpi_new (0)));
467  GNUNET_assert (NULL != (y = gcry_mpi_new (0)));
468  GNUNET_assert (NULL != (tmp = gcry_mpi_new (0)));
469 
470  GNUNET_CRYPTO_mpi_scan_unsigned (&h, public_key, sizeof *public_key);
471  GNUNET_CRYPTO_mpi_scan_unsigned (&m, plaintext, sizeof *plaintext);
472 
473  // Randomize y such that 0 < y < elgamal_q.
474  // The '- 1' is necessary as bitlength(q) = bitlength(p) - 1.
475  do
476  {
477  gcry_mpi_randomize (y, GNUNET_SECRETSHARING_ELGAMAL_BITS - 1,
478  GCRY_WEAK_RANDOM);
479  }
480  while ((gcry_mpi_cmp_ui (y, 0) == 0) || (gcry_mpi_cmp (y, elgamal_q) >= 0));
481 
482  // tmp <- g^y
483  gcry_mpi_powm (tmp, elgamal_g, y, elgamal_p);
484  // write tmp to c1
485  GNUNET_CRYPTO_mpi_print_unsigned (&result_ciphertext->c1_bits,
487 
488  // tmp <- h^y
489  gcry_mpi_powm (tmp, h, y, elgamal_p);
490  // tmp <- tmp * m
491  gcry_mpi_mulm (tmp, tmp, m, elgamal_p);
492  // write tmp to c2
493  GNUNET_CRYPTO_mpi_print_unsigned (&result_ciphertext->c2_bits,
495 
496  return GNUNET_OK;
497 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
Definition: crypto_mpi.c:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void ensure_elgamal_initialized(void)
Function to initialize elgamal_q, elgamal_p and elgamal_g.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
uint32_t c1_bits[1024/8/sizeof(uint32_t)]
void GNUNET_CRYPTO_mpi_scan_unsigned(gcry_mpi_t *result, const void *data, size_t size)
Convert data buffer into MPI value.
Definition: crypto_mpi.c:131
static gcry_mpi_t elgamal_p
Modulus of the prime field used for ElGamal.
uint32_t c2_bits[1024/8/sizeof(uint32_t)]
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.
#define GNUNET_SECRETSHARING_ELGAMAL_BITS
Number of bits for secretsharing elements.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SECRETSHARING_decrypt()

struct GNUNET_SECRETSHARING_DecryptionHandle* GNUNET_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.

Once a sufficient (>=k) number of peers has published the same value, it will be decrypted.

When the operation is canceled, the decrypt_cb is not called anymore, but the calling peer may already have irrevocably contributed its share for the decryption of the value.

Parameters
cfgconfiguration to use
shareour secret share to use for decryption
ciphertextciphertext to publish in order to decrypt it (if enough peers agree)
decrypt_cbcallback called once the decryption succeeded
startBy when should the cooperation for decryption start?
deadlineBy when should the decryption be finished?
decrypt_cb_clsclosure for decrypt_cb
Returns
handle to cancel the operation

Once a sufficient (>=k) number of peers has published the same value, it will be decrypted.

When the operation is canceled, the decrypt_cb is not called anymore, but the calling peer may already have irrevocably contributed its share for the decryption of the value.

Parameters
shareour secret share to use for decryption
ciphertextciphertext to publish in order to decrypt it (if enough peers agree)
decrypt_cbcallback called once the decryption succeeded
decrypt_cb_clsclosure for decrypt_cb
Returns
handle to cancel the operation

Definition at line 333 of file secretsharing_api.c.

References ciphertext, GNUNET_SECRETSHARING_DecryptRequestMessage::ciphertext, GNUNET_SECRETSHARING_DecryptRequestMessage::deadline, GNUNET_SECRETSHARING_DecryptionHandle::decrypt_cb, decrypt_cb(), GNUNET_SECRETSHARING_DecryptionHandle::decrypt_cls, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_DONE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, GNUNET_OK, GNUNET_SECRETSHARING_share_write(), GNUNET_TIME_absolute_hton(), handle_decrypt_client_error(), LOG, GNUNET_SECRETSHARING_DecryptionHandle::mq, msg, and GNUNET_SECRETSHARING_DecryptRequestMessage::start.

Referenced by decrypt_connect_adapter().

341 {
344  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
345  GNUNET_MQ_hd_fixed_size (decrypt_done,
348  s),
350  };
351  struct GNUNET_MQ_Envelope *ev;
353  size_t share_size;
354 
355  s->decrypt_cb = decrypt_cb;
356  s->decrypt_cls = decrypt_cb_cls;
357  s->mq = GNUNET_CLIENT_connect (cfg,
358  "secretsharing",
359  mq_handlers,
361  s);
362  if (NULL == s->mq)
363  {
364  GNUNET_free (s);
365  return NULL;
366  }
368  GNUNET_SECRETSHARING_share_write (share, NULL, 0,
369  &share_size));
370 
371  ev = GNUNET_MQ_msg_extra (msg,
372  share_size,
374 
377  &msg[1],
378  share_size,
379  NULL));
380 
381  msg->start = GNUNET_TIME_absolute_hton (start);
382  msg->deadline = GNUNET_TIME_absolute_hton (deadline);
383  msg->ciphertext = *ciphertext;
384 
385  GNUNET_MQ_send (s->mq, ev);
386 
388  "decrypt session created\n");
389  return s;
390 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT
Request the decryption of a ciphertext.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_SECRETSHARING_DecryptCallback decrypt_cb
Called when the secret sharing is done.
struct GNUNET_SECRETSHARING_Ciphertext ciphertext
Ciphertext we want to decrypt.
#define GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_DONE
The service succeeded in decrypting a ciphertext.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
int GNUNET_SECRETSHARING_share_write(const struct GNUNET_SECRETSHARING_Share *share, void *buf, size_t buflen, size_t *writelen)
Convert a share to its binary representation.
static struct GNUNET_SECRETSHARING_Ciphertext ciphertext
struct GNUNET_TIME_AbsoluteNBO deadline
Until when should the decryption be finished?
#define LOG(kind,...)
Message handler for a specific message type.
Handle to cancel a cooperative decryption operation.
struct GNUNET_TIME_AbsoluteNBO start
Until when should the decryption start?
static void handle_decrypt_client_error(void *cls, enum GNUNET_MQ_Error error)
Callback invoked when there is an error communicating with the service.
void * decrypt_cls
Closure for decrypt_cb.
static void decrypt_cb(void *cls, const struct GNUNET_SECRETSHARING_Plaintext *plaintext)
Called when a decryption has succeeded.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
struct GNUNET_MQ_Handle * mq
Message queue for client.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SECRETSHARING_decrypt_cancel()

void GNUNET_SECRETSHARING_decrypt_cancel ( struct GNUNET_SECRETSHARING_DecryptionHandle dh)

Cancel a decryption.

The decrypt_cb is not called anymore, but the calling peer may already have irrevocably contributed its share for the decryption of the value.

Parameters
dhto cancel

Definition at line 509 of file secretsharing_api.c.

References GNUNET_free, GNUNET_MQ_destroy(), and GNUNET_SECRETSHARING_DecryptionHandle::mq.

Referenced by decrypt_disconnect_adapter(), handle_decrypt_client_error(), and handle_decrypt_done().

511 {
512  GNUNET_MQ_destroy (dh->mq);
513  dh->mq = NULL;
514  GNUNET_free (dh);
515 }
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
struct GNUNET_MQ_Handle * mq
Message queue for client.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SECRETSHARING_share_read()

struct GNUNET_SECRETSHARING_Share* GNUNET_SECRETSHARING_share_read ( const void *  data,
size_t  len,
size_t *  readlen 
)

Read a share from its binary representation.

Parameters
dataBinary representation of the share.
lenLength of data.
[out]readlenNumber of bytes read, ignored if NULL.
Returns
The share, or NULL on error.

Definition at line 33 of file secretsharing_common.c.

References data, GNUNET_memcpy, GNUNET_new, GNUNET_new_array, GNUNET_SECRETSHARING_Share::my_peer, GNUNET_SECRETSHARING_Share::my_share, GNUNET_SECRETSHARING_ShareHeaderNBO::num_peers, GNUNET_SECRETSHARING_Share::num_peers, GNUNET_SECRETSHARING_Share::original_indices, p, GNUNET_SECRETSHARING_Share::peers, GNUNET_SECRETSHARING_Share::public_key, sh, GNUNET_SECRETSHARING_Share::sigmas, and GNUNET_SECRETSHARING_Share::threshold.

Referenced by handle_client_decrypt(), and handle_secret_ready().

36 {
37  struct GNUNET_SECRETSHARING_Share *share;
39  const char *p;
40  size_t n;
41  uint16_t payload_size;
42 
43  payload_size = ntohs (sh->num_peers)
44  * (sizeof(uint16_t) + sizeof(struct
46  + sizeof(struct GNUNET_PeerIdentity));
47 
48  if (NULL != readlen)
49  *readlen = payload_size + sizeof *sh;
50 
51  share = GNUNET_new (struct GNUNET_SECRETSHARING_Share);
52 
53  share->threshold = ntohs (sh->threshold);
54  share->num_peers = ntohs (sh->num_peers);
55  share->my_peer = ntohs (sh->my_peer);
56 
57  share->my_share = sh->my_share;
58  share->public_key = sh->public_key;
59 
60  p = (const char *) &sh[1];
61 
62  n = share->num_peers * sizeof(struct GNUNET_PeerIdentity);
63  share->peers = GNUNET_new_array (share->num_peers,
64  struct GNUNET_PeerIdentity);
65  GNUNET_memcpy (share->peers, p, n);
66  p += n;
67 
68  n = share->num_peers * sizeof(struct GNUNET_SECRETSHARING_FieldElement);
69  share->sigmas = GNUNET_new_array (share->num_peers,
71  GNUNET_memcpy (share->sigmas, p, n);
72  p += n;
73 
74  n = share->num_peers * sizeof(uint16_t);
76  uint16_t);
77  GNUNET_memcpy (share->original_indices, p, n);
78 
79  return share;
80 }
uint16_t threshold
Threshold for the key this share belongs to.
struct GNUNET_SECRETSHARING_FieldElement my_share
Share of &#39;my_peer&#39;.
struct GNUNET_PeerIdentity * peers
Peer identities (includes &#39;my_peer&#39;)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
A share, with all values in in host byte order.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static struct SolverHandle * sh
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_SECRETSHARING_FieldElement * sigmas
uint16_t my_peer
Index of our peer in the list.
uint16_t num_peers
Peers that have the share.
struct GNUNET_SECRETSHARING_PublicKey public_key
Public key.
uint32_t data
The data value.
uint16_t num_peers
Peers that have the share.
Definition: secretsharing.h:94
Here is the caller graph for this function:

◆ GNUNET_SECRETSHARING_share_write()

int GNUNET_SECRETSHARING_share_write ( const struct GNUNET_SECRETSHARING_Share share,
void *  buf,
size_t  buflen,
size_t *  writelen 
)

Convert a share to its binary representation.

Can be called with a NULL buf to get the size of the share.

Parameters
shareShare to write.
bufBuffer to write to.
buflenNumber of writable bytes in buf.
[out]writelenPointer to store number of bytes written, ignored if NULL.
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure.

Definition at line 95 of file secretsharing_common.c.

References buf, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_SECRETSHARING_ShareHeaderNBO::my_peer, GNUNET_SECRETSHARING_Share::my_peer, GNUNET_SECRETSHARING_ShareHeaderNBO::my_share, GNUNET_SECRETSHARING_Share::my_share, GNUNET_SECRETSHARING_ShareHeaderNBO::num_peers, GNUNET_SECRETSHARING_Share::num_peers, GNUNET_SECRETSHARING_Share::original_indices, p, GNUNET_SECRETSHARING_Share::peers, GNUNET_SECRETSHARING_ShareHeaderNBO::public_key, GNUNET_SECRETSHARING_Share::public_key, sh, GNUNET_SECRETSHARING_Share::sigmas, GNUNET_SECRETSHARING_ShareHeaderNBO::threshold, and GNUNET_SECRETSHARING_Share::threshold.

Referenced by GNUNET_SECRETSHARING_decrypt(), and keygen_round2_conclude().

98 {
99  uint16_t payload_size;
101  char *p;
102  int n;
103 
104  payload_size = share->num_peers
105  * (sizeof(uint16_t) + sizeof(struct
107  + sizeof(struct GNUNET_PeerIdentity));
108 
109  if (NULL != writelen)
110  *writelen = payload_size + sizeof(struct
112 
113  /* just a query for the writelen */
114  if (buf == NULL)
115  return GNUNET_OK;
116 
117  /* wrong buffer size */
118  if (buflen < payload_size + sizeof(struct
120  return GNUNET_SYSERR;
121 
122  sh = buf;
123 
124  sh->threshold = htons (share->threshold);
125  sh->num_peers = htons (share->num_peers);
126  sh->my_peer = htons (share->my_peer);
127 
128  sh->my_share = share->my_share;
129  sh->public_key = share->public_key;
130 
131  p = (void *) &sh[1];
132 
133  n = share->num_peers * sizeof(struct GNUNET_PeerIdentity);
134  GNUNET_memcpy (p, share->peers, n);
135  p += n;
136 
137  n = share->num_peers * sizeof(struct GNUNET_SECRETSHARING_FieldElement);
138  GNUNET_memcpy (p, share->sigmas, n);
139  p += n;
140 
141  n = share->num_peers * sizeof(uint16_t);
142  GNUNET_memcpy (p, share->original_indices, n);
143 
144  return GNUNET_OK;
145 }
uint16_t threshold
Threshold for the key this share belongs to.
struct GNUNET_SECRETSHARING_FieldElement my_share
Share of &#39;my_peer&#39;.
struct GNUNET_PeerIdentity * peers
Peer identities (includes &#39;my_peer&#39;)
struct GNUNET_SECRETSHARING_FieldElement my_share
Share of &#39;my_peer&#39;.
struct GNUNET_SECRETSHARING_PublicKey public_key
Public key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static struct SolverHandle * sh
static char buf[2048]
uint16_t threshold
Threshold for the key this share belongs to.
Definition: secretsharing.h:89
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
The identity of the host (wraps the signing key of the peer).
struct GNUNET_SECRETSHARING_FieldElement * sigmas
uint16_t my_peer
Index of our peer in the list.
uint16_t num_peers
Peers that have the share.
uint16_t my_peer
Index of our peer in the list.
Definition: secretsharing.h:99
struct GNUNET_SECRETSHARING_PublicKey public_key
Public key.
uint16_t num_peers
Peers that have the share.
Definition: secretsharing.h:94
Here is the caller graph for this function:

◆ GNUNET_SECRETSHARING_share_destroy()

void GNUNET_SECRETSHARING_share_destroy ( struct GNUNET_SECRETSHARING_Share share)

Definition at line 149 of file secretsharing_common.c.

References GNUNET_free, GNUNET_SECRETSHARING_Share::original_indices, GNUNET_SECRETSHARING_Share::peers, and GNUNET_SECRETSHARING_Share::sigmas.

Referenced by decrypt_session_destroy(), and keygen_round2_conclude().

150 {
151  GNUNET_free (share->original_indices);
152  share->original_indices = NULL;
153  GNUNET_free (share->sigmas);
154  share->sigmas = NULL;
155  GNUNET_free (share->peers);
156  share->peers = NULL;
157  GNUNET_free (share);
158 }
struct GNUNET_PeerIdentity * peers
Peer identities (includes &#39;my_peer&#39;)
struct GNUNET_SECRETSHARING_FieldElement * sigmas
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_SECRETSHARING_plaintext_generate()

int GNUNET_SECRETSHARING_plaintext_generate ( struct GNUNET_SECRETSHARING_Plaintext plaintext,
gcry_mpi_t  exponent 
)

◆ GNUNET_SECRETSHARING_plaintext_generate_i()

int GNUNET_SECRETSHARING_plaintext_generate_i ( struct GNUNET_SECRETSHARING_Plaintext plaintext,
int64_t  exponent 
)

Definition at line 394 of file secretsharing_api.c.

References elgamal_g, elgamal_p, ensure_elgamal_initialized(), GNUNET_assert, GNUNET_CRYPTO_mpi_print_unsigned(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, and res.

Referenced by session_disconnect_adapter().

398 {
399  int negative;
400  gcry_mpi_t x;
401 
403 
404  GNUNET_assert (NULL != (x = gcry_mpi_new (0)));
405 
406  negative = GNUNET_NO;
407  if (exponent < 0)
408  {
409  negative = GNUNET_YES;
410  exponent = -exponent;
411  }
412 
413  gcry_mpi_set_ui (x, exponent);
414 
415  gcry_mpi_powm (x, elgamal_g, x, elgamal_p);
416 
417  if (GNUNET_YES == negative)
418  {
419  int res;
420  res = gcry_mpi_invm (x, x, elgamal_p);
421  if (0 == res)
422  return GNUNET_SYSERR;
423  }
424 
426  sizeof(struct
428  x);
429 
430  return GNUNET_OK;
431 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
Definition: crypto_mpi.c:78
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void ensure_elgamal_initialized(void)
Function to initialize elgamal_q, elgamal_p and elgamal_g.
static int res
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Plain, unencrypted message that can be encrypted with a group public key.
static gcry_mpi_t elgamal_p
Modulus of the prime field used for ElGamal.
#define GNUNET_YES
Definition: gnunet_common.h:77
static gcry_mpi_t elgamal_g
Generator for prime field of order &#39;elgamal_q&#39;.
Here is the call graph for this function:
Here is the caller graph for this function: