GNUnet 0.22.2
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 57 of file gnunet_secretsharing_service.h.

◆ 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 63 of file gnunet_secretsharing_service.h.

◆ 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 76 of file gnunet_secretsharing_service.h.

◆ 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 89 of file gnunet_secretsharing_service.h.

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 successfully 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.

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
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;
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;
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_MessageHeader * msg
Definition: 005.c:2
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:38
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
static unsigned int num_peers
Number of peers.
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:1060
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#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:61
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY
The cryptosystem has been established.
#define GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_GENERATE
Establish a new session.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
static void handle_session_client_error(void *cls, enum GNUNET_MQ_Error error)
Callback invoked when there is an error communicating with the service.
#define LOG(kind,...)
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TIME_AbsoluteNBO deadline
Deadline for the establishment of the crypto system.
Definition: secretsharing.h:67
struct GNUNET_HashCode session_id
Session ID, will be used for consensus.
Definition: secretsharing.h:57
uint16_t threshold
Minimum number of cooperating peers to decrypt a value.
Definition: secretsharing.h:73
Notify the client that then threshold secret has been established.
Session that will eventually establish a shared secred between the involved peers and allow encryptio...
void * secret_ready_cls
Closure for secret_ready_cb.
struct GNUNET_MQ_Handle * mq
Message queue for client.
GNUNET_SECRETSHARING_SecretReadyCallback secret_ready_cb
Called when the secret sharing is done.

References cfg, 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, num_peers, peers, GNUNET_SECRETSHARING_Session::secret_ready_cb, GNUNET_SECRETSHARING_Session::secret_ready_cls, GNUNET_SECRETSHARING_CreateMessage::session_id, start, and GNUNET_SECRETSHARING_CreateMessage::threshold.

Here is the call 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.

220{
222 s->mq = NULL;
223 GNUNET_free (s);
224}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700

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

Referenced by handle_secret_ready(), and handle_session_client_error().

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 solely 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 success, GNUNET_SYSERR if the message is invalid (invalid range)

Definition at line 422 of file secretsharing_api.c.

428{
429 /* pubkey */
430 gcry_mpi_t h;
431 /* nonce */
432 gcry_mpi_t y;
433 /* plaintext message */
434 gcry_mpi_t m;
435 /* temp value */
436 gcry_mpi_t tmp;
437
439
440 GNUNET_assert (NULL != (h = gcry_mpi_new (0)));
441 GNUNET_assert (NULL != (y = gcry_mpi_new (0)));
442 GNUNET_assert (NULL != (tmp = gcry_mpi_new (0)));
443
444 GNUNET_CRYPTO_mpi_scan_unsigned (&h, public_key, sizeof *public_key);
445 GNUNET_CRYPTO_mpi_scan_unsigned (&m, plaintext, sizeof *plaintext);
446
447 // Randomize y such that 0 < y < elgamal_q.
448 // The '- 1' is necessary as bitlength(q) = bitlength(p) - 1.
449 do
450 {
451 gcry_mpi_randomize (y, GNUNET_SECRETSHARING_ELGAMAL_BITS - 1,
452 GCRY_WEAK_RANDOM);
453 }
454 while ((gcry_mpi_cmp_ui (y, 0) == 0) || (gcry_mpi_cmp (y, elgamal_q) >= 0));
455
456 // tmp <- g^y
457 gcry_mpi_powm (tmp, elgamal_g, y, elgamal_p);
458 // write tmp to c1
459 GNUNET_CRYPTO_mpi_print_unsigned (&result_ciphertext->c1_bits,
461
462 // tmp <- h^y
463 gcry_mpi_powm (tmp, h, y, elgamal_p);
464 // tmp <- tmp * m
465 gcry_mpi_mulm (tmp, tmp, m, elgamal_p);
466 // write tmp to c2
467 GNUNET_CRYPTO_mpi_print_unsigned (&result_ciphertext->c2_bits,
469
470 return GNUNET_OK;
471}
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
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:132
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:79
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_SECRETSHARING_ELGAMAL_BITS
Number of bits for secretsharing elements.
static gcry_mpi_t elgamal_q
The ElGamal prime field order as libgcrypt mpi.
static gcry_mpi_t elgamal_g
Generator for prime field of order 'elgamal_q'.
static gcry_mpi_t elgamal_p
Modulus of the prime field used for ElGamal.
static void ensure_elgamal_initialized(void)
Function to initialize elgamal_q, elgamal_p and elgamal_g.
uint32_t c2_bits[1024/8/sizeof(uint32_t)]
uint32_t c1_bits[1024/8/sizeof(uint32_t)]

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.

Here is the call 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

Definition at line 320 of file secretsharing_api.c.

328{
331 struct GNUNET_MQ_MessageHandler mq_handlers[] = {
332 GNUNET_MQ_hd_fixed_size (decrypt_done,
335 s),
337 };
338 struct GNUNET_MQ_Envelope *ev;
340 size_t share_size;
341
342 s->decrypt_cb = decrypt_cb;
343 s->decrypt_cls = decrypt_cb_cls;
345 "secretsharing",
346 mq_handlers,
348 s);
349 if (NULL == s->mq)
350 {
351 GNUNET_free (s);
352 return NULL;
353 }
355 GNUNET_SECRETSHARING_share_write (share, NULL, 0,
356 &share_size));
357
359 share_size,
361
364 &msg[1],
365 share_size,
366 NULL));
367
370 msg->ciphertext = *ciphertext;
371
372 GNUNET_MQ_send (s->mq, ev);
373
375 "decrypt session created\n");
376 return s;
377}
#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_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_DONE
The service succeeded in decrypting a ciphertext.
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 void handle_decrypt_client_error(void *cls, enum GNUNET_MQ_Error error)
Callback invoked when there is an error communicating with the service.
struct GNUNET_TIME_AbsoluteNBO deadline
Until when should the decryption be finished?
struct GNUNET_SECRETSHARING_Ciphertext ciphertext
Ciphertext we want to decrypt.
Handle to cancel a cooperative decryption operation.
struct GNUNET_MQ_Handle * mq
Message queue for client.
GNUNET_SECRETSHARING_DecryptCallback decrypt_cb
Called when the secret sharing is done.
void * decrypt_cls
Closure for decrypt_cb.

References cfg, GNUNET_SECRETSHARING_DecryptRequestMessage::ciphertext, GNUNET_SECRETSHARING_DecryptRequestMessage::deadline, GNUNET_SECRETSHARING_DecryptionHandle::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 start.

Here is the call 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 483 of file secretsharing_api.c.

485{
486 GNUNET_MQ_destroy (dh->mq);
487 dh->mq = NULL;
488 GNUNET_free (dh);
489}

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

Referenced by handle_decrypt_client_error(), and handle_decrypt_done().

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 34 of file secretsharing_common.c.

37{
38 struct GNUNET_SECRETSHARING_Share *share;
40 const char *p;
41 size_t n;
42 uint16_t payload_size;
43
44 payload_size = ntohs (sh->num_peers)
45 * (sizeof(uint16_t) + sizeof(struct
47 + sizeof(struct GNUNET_PeerIdentity));
48
49 if (NULL != readlen)
50 *readlen = payload_size + sizeof *sh;
51
53
54 share->threshold = ntohs (sh->threshold);
55 share->num_peers = ntohs (sh->num_peers);
56 share->my_peer = ntohs (sh->my_peer);
57
58 share->my_share = sh->my_share;
59 share->public_key = sh->public_key;
60
61 p = (const char *) &sh[1];
62
63 n = share->num_peers * sizeof(struct GNUNET_PeerIdentity);
64 share->peers = GNUNET_new_array (share->num_peers,
65 struct GNUNET_PeerIdentity);
66 GNUNET_memcpy (share->peers, p, n);
67 p += n;
68
69 n = share->num_peers * sizeof(struct GNUNET_SECRETSHARING_FieldElement);
70 share->sigmas = GNUNET_new_array (share->num_peers,
72 GNUNET_memcpy (share->sigmas, p, n);
73 p += n;
74
75 n = share->num_peers * sizeof(uint16_t);
77 uint16_t);
78 GNUNET_memcpy (share->original_indices, p, n);
79
80 return share;
81}
static char * data
The data to insert into the dht.
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
A share, with all values in in host byte order.
uint16_t num_peers
Peers that have the share.
uint16_t threshold
Threshold for the key this share belongs to.
struct GNUNET_SECRETSHARING_FieldElement my_share
Share of 'my_peer'.
struct GNUNET_SECRETSHARING_PublicKey public_key
Public key.
struct GNUNET_PeerIdentity * peers
Peer identities (includes 'my_peer')
uint16_t my_peer
Index of our peer in the list.
struct GNUNET_SECRETSHARING_FieldElement * sigmas

References data, GNUNET_memcpy, GNUNET_new, GNUNET_new_array, GNUNET_SECRETSHARING_Share::my_peer, GNUNET_SECRETSHARING_Share::my_share, 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().

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 96 of file secretsharing_common.c.

99{
100 uint16_t payload_size;
102 char *p;
103 int n;
104
105 payload_size = share->num_peers
106 * (sizeof(uint16_t) + sizeof(struct
108 + sizeof(struct GNUNET_PeerIdentity));
109
110 if (NULL != writelen)
111 *writelen = payload_size + sizeof(struct
113
114 /* just a query for the writelen */
115 if (buf == NULL)
116 return GNUNET_OK;
117
118 /* wrong buffer size */
119 if (buflen < payload_size + sizeof(struct
121 return GNUNET_SYSERR;
122
123 sh = buf;
124
125 sh->threshold = htons (share->threshold);
126 sh->num_peers = htons (share->num_peers);
127 sh->my_peer = htons (share->my_peer);
128
129 sh->my_share = share->my_share;
130 sh->public_key = share->public_key;
131
132 p = (void *) &sh[1];
133
134 n = share->num_peers * sizeof(struct GNUNET_PeerIdentity);
135 GNUNET_memcpy (p, share->peers, n);
136 p += n;
137
138 n = share->num_peers * sizeof(struct GNUNET_SECRETSHARING_FieldElement);
139 GNUNET_memcpy (p, share->sigmas, n);
140 p += n;
141
142 n = share->num_peers * sizeof(uint16_t);
143 GNUNET_memcpy (p, share->original_indices, n);
144
145 return GNUNET_OK;
146}
@ GNUNET_SYSERR

References GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_SECRETSHARING_Share::my_peer, GNUNET_SECRETSHARING_Share::my_share, 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 GNUNET_SECRETSHARING_decrypt(), and keygen_round2_conclude().

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 150 of file secretsharing_common.c.

151{
153 share->original_indices = NULL;
154 GNUNET_free (share->sigmas);
155 share->sigmas = NULL;
156 GNUNET_free (share->peers);
157 share->peers = NULL;
158 GNUNET_free (share);
159}

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().

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 381 of file secretsharing_api.c.

385{
386 int negative;
387 gcry_mpi_t x;
388
390
391 GNUNET_assert (NULL != (x = gcry_mpi_new (0)));
392
393 negative = GNUNET_NO;
394 if (exponent < 0)
395 {
396 negative = GNUNET_YES;
397 exponent = -exponent;
398 }
399
400 gcry_mpi_set_ui (x, exponent);
401
402 gcry_mpi_powm (x, elgamal_g, x, elgamal_p);
403
404 if (GNUNET_YES == negative)
405 {
406 int res;
407 res = gcry_mpi_invm (x, x, elgamal_p);
408 if (0 == res)
409 return GNUNET_SYSERR;
410 }
411
413 sizeof(struct
415 x);
416
417 return GNUNET_OK;
418}
static char * res
Currently read line or NULL on EOF.
@ GNUNET_YES
@ GNUNET_NO
Plain, unencrypted message that can be encrypted with a group public key.

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.

Here is the call graph for this function: