Macros | Functions | Variables
shared_random.c File Reference
#include "core/or/or.h"
#include "feature/dirauth/shared_random.h"
#include "app/config/config.h"
#include "app/config/confparse.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_util.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/relay/router.h"
#include "feature/relay/routerkeys.h"
#include "feature/nodelist/dirlist.h"
#include "feature/hs_common/shared_random_client.h"
#include "feature/dirauth/shared_random_state.h"
#include "feature/dircommon/voting_schedule.h"
#include "feature/dirauth/dirvote.h"
#include "feature/dirauth/authmode.h"
#include "feature/nodelist/authority_cert_st.h"
#include "feature/nodelist/networkstatus_st.h"

Go to the source code of this file.


STATIC sr_srv_tsrv_dup (const sr_srv_t *orig)
static sr_commit_tcommit_new (const char *rsa_identity)
static void commit_log (const sr_commit_t *commit)
STATIC int verify_commit_and_reveal (const sr_commit_t *commit)
STATIC int commit_has_reveal_value (const sr_commit_t *commit)
STATIC int commit_decode (const char *encoded, sr_commit_t *commit)
STATIC int reveal_decode (const char *encoded, sr_commit_t *commit)
STATIC int reveal_encode (const sr_commit_t *commit, char *dst, size_t len)
STATIC int commit_encode (const sr_commit_t *commit, char *dst, size_t len)
static void sr_cleanup (void)
static char * get_srv_element_from_commit (const sr_commit_t *commit)
static sr_srv_tgenerate_srv (const char *hashed_reveals, uint64_t reveal_num, const sr_srv_t *previous_srv)
static int compare_reveal_ (const void **_a, const void **_b)
static char * get_vote_line_from_commit (const sr_commit_t *commit, sr_phase_t phase)
static char * srv_to_ns_string (const sr_srv_t *srv, const char *key)
static char * get_ns_str_from_sr_values (const sr_srv_t *prev_srv, const sr_srv_t *cur_srv)
STATIC int commitments_are_the_same (const sr_commit_t *commit_one, const sr_commit_t *commit_two)
STATIC int commit_is_authoritative (const sr_commit_t *commit, const char *voter_key)
STATIC int should_keep_commit (const sr_commit_t *commit, const char *voter_key, sr_phase_t phase)
STATIC void save_commit_during_reveal_phase (const sr_commit_t *commit)
STATIC void save_commit_to_state (sr_commit_t *commit)
static int should_keep_srv (int n_agreements)
static int compare_srvs_ (const void **_a, const void **_b)
static sr_srv_tsmartlist_get_most_frequent_srv (const smartlist_t *sl, int *count_out)
static int compare_srv_ (const void **_a, const void **_b)
STATIC sr_srv_tget_majority_srv_from_votes (const smartlist_t *votes, int current)
void sr_commit_free_ (sr_commit_t *commit)
sr_commit_tsr_generate_our_commit (time_t timestamp, const authority_cert_t *my_rsa_cert)
void sr_compute_srv (void)
sr_commit_tsr_parse_commit (const smartlist_t *args)
void sr_handle_received_commits (smartlist_t *commits, crypto_pk_t *voter_key)
char * sr_get_string_for_vote (void)
char * sr_get_string_for_consensus (const smartlist_t *votes, int32_t num_srv_agreements)
void sr_act_post_consensus (const networkstatus_t *consensus)
int sr_init (int save_to_disk)
void sr_save_and_cleanup (void)


static const char previous_srv_str [] = "shared-rand-previous-value"
static const char current_srv_str [] = "shared-rand-current-value"
static const char commit_ns_str [] = "shared-rand-commit"
static const char sr_flag_ns_str [] = "shared-rand-participate"
static int32_t num_srv_agreements_from_vote

Detailed Description

Functions and data structure needed to accomplish the shared random protocol as defined in proposal #250.

This file implements the dirauth-only commit-and-reveal protocol specified by proposal #250. The protocol has two phases (sr_phase_t): the commitment phase and the reveal phase (see get_sr_protocol_phase()).

During the protocol, directory authorities keep state in memory (using sr_state_t) and in disk (using sr_disk_state_t). The synchronization between these two data structures happens in disk_state_update() and disk_state_parse().

Here is a rough protocol outline:

 1) In the beginning of the commitment phase, dirauths generate a
    commitment/reveal value for the current protocol run (see
    new_protocol_run() and sr_generate_our_commit()).

 2) During voting, dirauths publish their commits in their votes
    depending on the current phase.  Dirauths also include the two
    latest shared random values (SRV) in their votes.
    (see sr_get_string_for_vote())

 3) Upon receiving a commit from a vote, authorities parse it, verify
    it, and attempt to save any new commitment or reveal information in
    their state file (see extract_shared_random_commits() and
    sr_handle_received_commits()).  They also parse SRVs from votes to
    decide which SRV should be included in the final consensus (see

 3) After voting is done, we count the SRVs we extracted from the votes,
    to find the one voted by the majority of dirauths which should be
    included in the final consensus (see get_majority_srv_from_votes()).
    If an appropriate SRV is found, it is embedded in the consensus (see

 4) At the end of the reveal phase, dirauths compute a fresh SRV for the
    day using the active commits (see sr_compute_srv()).  This new SRV
    is embedded in the votes as described above.

Some more notes:


Definition in file shared_random.c.

Function Documentation

◆ compare_srv_()

static int compare_srv_ ( const void **  _a,
const void **  _b 

Compare two SRVs. Used in smartlist sorting.

Definition at line 802 of file shared_random.c.

References fast_memcmp.