GNUnet  0.10.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 169 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 184 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 238 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().

247 {
250  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
251  GNUNET_MQ_hd_var_size(secret_ready,
254  s),
256  };
257  struct GNUNET_MQ_Envelope *ev;
259 
260  s->mq = GNUNET_CLIENT_connect(cfg,
261  "secretsharing",
262  mq_handlers,
264  s);
265  if (NULL == s->mq)
266  {
267  /* secretsharing not configured correctly */
268  GNUNET_break(0);
269  GNUNET_free(s);
270  return NULL;
271  }
272  s->secret_ready_cb = cb;
273  s->secret_ready_cls = cls;
274  ev = GNUNET_MQ_msg_extra(msg,
275  num_peers * sizeof(struct GNUNET_PeerIdentity),
277 
278  msg->threshold = htons(threshold);
279  msg->num_peers = htons(num_peers);
280  msg->session_id = *session_id;
281  msg->start = GNUNET_TIME_absolute_hton(start);
282  msg->deadline = GNUNET_TIME_absolute_hton(deadline);
283  GNUNET_memcpy(&msg[1], peers, num_peers * sizeof(struct GNUNET_PeerIdentity));
284 
285  GNUNET_MQ_send(s->mq, ev);
286 
288  "Secretsharing session created with %u peers\n",
289  num_peers);
290  return s;
291 }
struct GNUNET_TIME_AbsoluteNBO start
Start time for communication with the other peers.
Definition: secretsharing.h:60
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:900
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:65
#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:71
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:76
#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:351
#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:55
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:655
#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 213 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().

214 {
215  GNUNET_MQ_destroy(s->mq);
216  s->mq = NULL;
217  GNUNET_free(s);
218 }
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:821
#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 435 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().

438 {
439  /* pubkey */
440  gcry_mpi_t h;
441  /* nonce */
442  gcry_mpi_t y;
443  /* plaintext message */
444  gcry_mpi_t m;
445  /* temp value */
446  gcry_mpi_t tmp;
447 
449 
450  GNUNET_assert(NULL != (h = gcry_mpi_new(0)));
451  GNUNET_assert(NULL != (y = gcry_mpi_new(0)));
452  GNUNET_assert(NULL != (tmp = gcry_mpi_new(0)));
453 
454  GNUNET_CRYPTO_mpi_scan_unsigned(&h, public_key, sizeof *public_key);
455  GNUNET_CRYPTO_mpi_scan_unsigned(&m, plaintext, sizeof *plaintext);
456 
457  // Randomize y such that 0 < y < elgamal_q.
458  // The '- 1' is necessary as bitlength(q) = bitlength(p) - 1.
459  do
460  {
461  gcry_mpi_randomize(y, GNUNET_SECRETSHARING_ELGAMAL_BITS - 1, GCRY_WEAK_RANDOM);
462  }
463  while ((gcry_mpi_cmp_ui(y, 0) == 0) || (gcry_mpi_cmp(y, elgamal_q) >= 0));
464 
465  // tmp <- g^y
466  gcry_mpi_powm(tmp, elgamal_g, y, elgamal_p);
467  // write tmp to c1
468  GNUNET_CRYPTO_mpi_print_unsigned(&result_ciphertext->c1_bits,
470 
471  // tmp <- h^y
472  gcry_mpi_powm(tmp, h, y, elgamal_p);
473  // tmp <- tmp * m
474  gcry_mpi_mulm(tmp, tmp, m, elgamal_p);
475  // write tmp to c2
476  GNUNET_CRYPTO_mpi_print_unsigned(&result_ciphertext->c2_bits,
478 
479  return GNUNET_OK;
480 }
#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:75
#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:94
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
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:128
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 324 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().

331 {
334  struct GNUNET_MQ_MessageHandler mq_handlers[] = {
335  GNUNET_MQ_hd_fixed_size(decrypt_done,
338  s),
340  };
341  struct GNUNET_MQ_Envelope *ev;
343  size_t share_size;
344 
345  s->decrypt_cb = decrypt_cb;
346  s->decrypt_cls = decrypt_cb_cls;
347  s->mq = GNUNET_CLIENT_connect(cfg,
348  "secretsharing",
349  mq_handlers,
351  s);
352  if (NULL == s->mq)
353  {
354  GNUNET_free(s);
355  return NULL;
356  }
358  GNUNET_SECRETSHARING_share_write(share, NULL, 0,
359  &share_size));
360 
361  ev = GNUNET_MQ_msg_extra(msg,
362  share_size,
364 
367  &msg[1],
368  share_size,
369  NULL));
370 
371  msg->start = GNUNET_TIME_absolute_hton(start);
372  msg->deadline = GNUNET_TIME_absolute_hton(deadline);
373  msg->ciphertext = *ciphertext;
374 
375  GNUNET_MQ_send(s->mq, ev);
376 
378  "decrypt session created\n");
379  return s;
380 }
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:900
#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:351
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:655
#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 492 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().

493 {
494  GNUNET_MQ_destroy(dh->mq);
495  dh->mq = NULL;
496  GNUNET_free(dh);
497 }
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
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 GNUNET_SECRETSHARING_FieldElement) +
45  sizeof(struct GNUNET_PeerIdentity));
46 
47  if (NULL != readlen)
48  *readlen = payload_size + sizeof *sh;
49 
50  share = GNUNET_new(struct GNUNET_SECRETSHARING_Share);
51 
52  share->threshold = ntohs(sh->threshold);
53  share->num_peers = ntohs(sh->num_peers);
54  share->my_peer = ntohs(sh->my_peer);
55 
56  share->my_share = sh->my_share;
57  share->public_key = sh->public_key;
58 
59  p = (const char *)&sh[1];
60 
61  n = share->num_peers * sizeof(struct GNUNET_PeerIdentity);
62  share->peers = GNUNET_new_array(share->num_peers,
63  struct GNUNET_PeerIdentity);
64  GNUNET_memcpy(share->peers, p, n);
65  p += n;
66 
67  n = share->num_peers * sizeof(struct GNUNET_SECRETSHARING_FieldElement);
68  share->sigmas = GNUNET_new_array(share->num_peers,
70  GNUNET_memcpy(share->sigmas, p, n);
71  p += n;
72 
73  n = share->num_peers * sizeof(uint16_t);
75  uint16_t);
76  GNUNET_memcpy(share->original_indices, p, n);
77 
78  return share;
79 }
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:92
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 94 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().

96 {
97  uint16_t payload_size;
99  char *p;
100  int n;
101 
102  payload_size = share->num_peers *
103  (sizeof(uint16_t) + sizeof(struct GNUNET_SECRETSHARING_FieldElement) +
104  sizeof(struct GNUNET_PeerIdentity));
105 
106  if (NULL != writelen)
107  *writelen = payload_size + sizeof(struct GNUNET_SECRETSHARING_ShareHeaderNBO);
108 
109  /* just a query for the writelen */
110  if (buf == NULL)
111  return GNUNET_OK;
112 
113  /* wrong buffer size */
114  if (buflen < payload_size + sizeof(struct GNUNET_SECRETSHARING_ShareHeaderNBO))
115  return GNUNET_SYSERR;
116 
117  sh = buf;
118 
119  sh->threshold = htons(share->threshold);
120  sh->num_peers = htons(share->num_peers);
121  sh->my_peer = htons(share->my_peer);
122 
123  sh->my_share = share->my_share;
124  sh->public_key = share->public_key;
125 
126  p = (void *)&sh[1];
127 
128  n = share->num_peers * sizeof(struct GNUNET_PeerIdentity);
129  GNUNET_memcpy(p, share->peers, n);
130  p += n;
131 
132  n = share->num_peers * sizeof(struct GNUNET_SECRETSHARING_FieldElement);
133  GNUNET_memcpy(p, share->sigmas, n);
134  p += n;
135 
136  n = share->num_peers * sizeof(uint16_t);
137  GNUNET_memcpy(p, share->original_indices, n);
138 
139  return GNUNET_OK;
140 }
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:87
#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:97
struct GNUNET_SECRETSHARING_PublicKey public_key
Public key.
uint16_t num_peers
Peers that have the share.
Definition: secretsharing.h:92
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 144 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().

145 {
147  share->original_indices = NULL;
148  GNUNET_free(share->sigmas);
149  share->sigmas = NULL;
150  GNUNET_free(share->peers);
151  share->peers = NULL;
152  GNUNET_free(share);
153 }
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 384 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().

386 {
387  int negative;
388  gcry_mpi_t x;
389 
391 
392  GNUNET_assert(NULL != (x = gcry_mpi_new(0)));
393 
394  negative = GNUNET_NO;
395  if (exponent < 0)
396  {
397  negative = GNUNET_YES;
398  exponent = -exponent;
399  }
400 
401  gcry_mpi_set_ui(x, exponent);
402 
403  gcry_mpi_powm(x, elgamal_g, x, elgamal_p);
404 
405  if (GNUNET_YES == negative)
406  {
407  int res;
408  res = gcry_mpi_invm(x, x, elgamal_p);
409  if (0 == res)
410  return GNUNET_SYSERR;
411  }
412 
414  sizeof(struct GNUNET_SECRETSHARING_Plaintext),
415  x);
416 
417  return GNUNET_OK;
418 }
#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:75
#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: