mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
prop250: Change reveal_num to uint64_t and version to uint32_t
Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
899d2b890b
commit
e62f3133bb
@ -403,10 +403,10 @@ get_srv_element_from_commit(const sr_commit_t *commit)
|
|||||||
|
|
||||||
/* Return a srv object that is built with the construction:
|
/* Return a srv object that is built with the construction:
|
||||||
* SRV = SHA3-256("shared-random" | INT_8(reveal_num) |
|
* SRV = SHA3-256("shared-random" | INT_8(reveal_num) |
|
||||||
* INT_8(version) | HASHED_REVEALS | previous_SRV)
|
* INT_4(version) | HASHED_REVEALS | previous_SRV)
|
||||||
* This function cannot fail. */
|
* This function cannot fail. */
|
||||||
static sr_srv_t *
|
static sr_srv_t *
|
||||||
generate_srv(const char *hashed_reveals, uint8_t reveal_num,
|
generate_srv(const char *hashed_reveals, uint64_t reveal_num,
|
||||||
const sr_srv_t *previous_srv)
|
const sr_srv_t *previous_srv)
|
||||||
{
|
{
|
||||||
char msg[DIGEST256_LEN + SR_SRV_MSG_LEN] = {0};
|
char msg[DIGEST256_LEN + SR_SRV_MSG_LEN] = {0};
|
||||||
@ -418,10 +418,10 @@ generate_srv(const char *hashed_reveals, uint8_t reveal_num,
|
|||||||
/* Add the invariant token. */
|
/* Add the invariant token. */
|
||||||
memcpy(msg, SR_SRV_TOKEN, SR_SRV_TOKEN_LEN);
|
memcpy(msg, SR_SRV_TOKEN, SR_SRV_TOKEN_LEN);
|
||||||
offset += SR_SRV_TOKEN_LEN;
|
offset += SR_SRV_TOKEN_LEN;
|
||||||
set_uint8(msg + offset, reveal_num);
|
set_uint64(msg + offset, tor_htonll(reveal_num));
|
||||||
offset += 1;
|
offset += sizeof(uint64_t);
|
||||||
set_uint8(msg + offset, SR_PROTO_VERSION);
|
set_uint32(msg + offset, htonl(SR_PROTO_VERSION));
|
||||||
offset += 1;
|
offset += sizeof(uint32_t);
|
||||||
memcpy(msg + offset, hashed_reveals, DIGEST256_LEN);
|
memcpy(msg + offset, hashed_reveals, DIGEST256_LEN);
|
||||||
offset += DIGEST256_LEN;
|
offset += DIGEST256_LEN;
|
||||||
if (previous_srv != NULL) {
|
if (previous_srv != NULL) {
|
||||||
@ -505,7 +505,7 @@ srv_to_ns_string(const sr_srv_t *srv, const char *key)
|
|||||||
tor_assert(key);
|
tor_assert(key);
|
||||||
|
|
||||||
sr_srv_encode(srv_hash_encoded, sizeof(srv_hash_encoded), srv);
|
sr_srv_encode(srv_hash_encoded, sizeof(srv_hash_encoded), srv);
|
||||||
tor_asprintf(&srv_str, "%s %d %s\n", key,
|
tor_asprintf(&srv_str, "%s %" PRIu64 " %s\n", key,
|
||||||
srv->num_reveals, srv_hash_encoded);
|
srv->num_reveals, srv_hash_encoded);
|
||||||
log_debug(LD_DIR, "SR: Consensus SRV line: %s", srv_str);
|
log_debug(LD_DIR, "SR: Consensus SRV line: %s", srv_str);
|
||||||
return srv_str;
|
return srv_str;
|
||||||
@ -962,7 +962,7 @@ sr_generate_our_commit(time_t timestamp, const authority_cert_t *my_rsa_cert)
|
|||||||
void
|
void
|
||||||
sr_compute_srv(void)
|
sr_compute_srv(void)
|
||||||
{
|
{
|
||||||
size_t reveal_num = 0;
|
uint64_t reveal_num = 0;
|
||||||
char *reveals = NULL;
|
char *reveals = NULL;
|
||||||
smartlist_t *chunks, *commits;
|
smartlist_t *chunks, *commits;
|
||||||
digestmap_t *state_commits;
|
digestmap_t *state_commits;
|
||||||
@ -1019,8 +1019,7 @@ sr_compute_srv(void)
|
|||||||
SR_DIGEST_ALG)) {
|
SR_DIGEST_ALG)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
tor_assert(reveal_num < UINT8_MAX);
|
current_srv = generate_srv(hashed_reveals, reveal_num,
|
||||||
current_srv = generate_srv(hashed_reveals, (uint8_t) reveal_num,
|
|
||||||
sr_state_get_previous_srv());
|
sr_state_get_previous_srv());
|
||||||
sr_state_set_current_srv(current_srv);
|
sr_state_set_current_srv(current_srv);
|
||||||
/* We have a fresh SRV, flag our state. */
|
/* We have a fresh SRV, flag our state. */
|
||||||
@ -1042,7 +1041,8 @@ sr_srv_t *
|
|||||||
sr_parse_srv(const smartlist_t *args)
|
sr_parse_srv(const smartlist_t *args)
|
||||||
{
|
{
|
||||||
char *value;
|
char *value;
|
||||||
int num_reveals, ok, ret;
|
int ok, ret;
|
||||||
|
uint64_t num_reveals;
|
||||||
sr_srv_t *srv = NULL;
|
sr_srv_t *srv = NULL;
|
||||||
|
|
||||||
tor_assert(args);
|
tor_assert(args);
|
||||||
@ -1052,8 +1052,8 @@ sr_parse_srv(const smartlist_t *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* First argument is the number of reveal values */
|
/* First argument is the number of reveal values */
|
||||||
num_reveals = (int)tor_parse_long(smartlist_get(args, 0),
|
num_reveals = tor_parse_uint64(smartlist_get(args, 0),
|
||||||
10, 0, INT32_MAX, &ok, NULL);
|
10, 0, UINT64_MAX, &ok, NULL);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,9 @@
|
|||||||
* timestamp and the hashed random number. This adds up to 40 bytes. */
|
* timestamp and the hashed random number. This adds up to 40 bytes. */
|
||||||
#define SR_REVEAL_LEN (sizeof(uint64_t) + DIGEST256_LEN)
|
#define SR_REVEAL_LEN (sizeof(uint64_t) + DIGEST256_LEN)
|
||||||
/* Size of SRV message length. The construction is has follow:
|
/* Size of SRV message length. The construction is has follow:
|
||||||
* "shared-random" | INT_8(reveal_num) | INT_8(version) | PREV_SRV */
|
* "shared-random" | INT_8(reveal_num) | INT_4(version) | PREV_SRV */
|
||||||
#define SR_SRV_MSG_LEN \
|
#define SR_SRV_MSG_LEN \
|
||||||
(SR_SRV_TOKEN_LEN + 1 + 1 + DIGEST256_LEN)
|
(SR_SRV_TOKEN_LEN + sizeof(uint64_t) + sizeof(uint32_t) + DIGEST256_LEN)
|
||||||
|
|
||||||
/* Length of base64 encoded commit NOT including the NULL terminated byte.
|
/* Length of base64 encoded commit NOT including the NULL terminated byte.
|
||||||
* Formula is taken from base64_encode_size. */
|
* Formula is taken from base64_encode_size. */
|
||||||
@ -62,7 +62,7 @@ typedef enum {
|
|||||||
/* A shared random value (SRV). */
|
/* A shared random value (SRV). */
|
||||||
typedef struct sr_srv_t {
|
typedef struct sr_srv_t {
|
||||||
/* The number of reveal values used to derive this SRV. */
|
/* The number of reveal values used to derive this SRV. */
|
||||||
int num_reveals;
|
uint64_t num_reveals;
|
||||||
/* The actual value. This is the stored result of SHA3-256. */
|
/* The actual value. This is the stored result of SHA3-256. */
|
||||||
uint8_t value[DIGEST256_LEN];
|
uint8_t value[DIGEST256_LEN];
|
||||||
} sr_srv_t;
|
} sr_srv_t;
|
||||||
|
@ -60,7 +60,7 @@ disk_state_validate_cb(void *old_state, void *state, void *default_state,
|
|||||||
|
|
||||||
/* Array of variables that are saved to disk as a persistent state. */
|
/* Array of variables that are saved to disk as a persistent state. */
|
||||||
static config_var_t state_vars[] = {
|
static config_var_t state_vars[] = {
|
||||||
V(Version, INT, "0"),
|
V(Version, UINT, "0"),
|
||||||
V(TorVersion, STRING, NULL),
|
V(TorVersion, STRING, NULL),
|
||||||
V(ValidAfter, ISOTIME, NULL),
|
V(ValidAfter, ISOTIME, NULL),
|
||||||
V(ValidUntil, ISOTIME, NULL),
|
V(ValidUntil, ISOTIME, NULL),
|
||||||
@ -590,7 +590,7 @@ disk_state_put_srv_line(const sr_srv_t *srv, config_line_t *line)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sr_srv_encode(encoded, sizeof(encoded), srv);
|
sr_srv_encode(encoded, sizeof(encoded), srv);
|
||||||
tor_asprintf(&line->value, "%d %s", srv->num_reveals, encoded);
|
tor_asprintf(&line->value, "%" PRIu64 " %s", srv->num_reveals, encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset disk state that is free allocated memory and zeroed the object. */
|
/* Reset disk state that is free allocated memory and zeroed the object. */
|
||||||
|
@ -36,7 +36,7 @@ typedef struct sr_state_t {
|
|||||||
/* Filename of the state file on disk. */
|
/* Filename of the state file on disk. */
|
||||||
char *fname;
|
char *fname;
|
||||||
/* Version of the protocol. */
|
/* Version of the protocol. */
|
||||||
uint8_t version;
|
uint32_t version;
|
||||||
/* The valid-after of the voting period we have prepared the state for. */
|
/* The valid-after of the voting period we have prepared the state for. */
|
||||||
time_t valid_after;
|
time_t valid_after;
|
||||||
/* Until when is this state valid? */
|
/* Until when is this state valid? */
|
||||||
@ -76,7 +76,7 @@ typedef struct sr_state_t {
|
|||||||
typedef struct sr_disk_state_t {
|
typedef struct sr_disk_state_t {
|
||||||
uint32_t magic_;
|
uint32_t magic_;
|
||||||
/* Version of the protocol. */
|
/* Version of the protocol. */
|
||||||
int Version;
|
uint32_t Version;
|
||||||
/* Version of our running tor. */
|
/* Version of our running tor. */
|
||||||
char *TorVersion;
|
char *TorVersion;
|
||||||
/* Creation time of this state */
|
/* Creation time of this state */
|
||||||
|
@ -785,9 +785,6 @@ test_sr_compute_srv(void *arg)
|
|||||||
#define SRV_TEST_VECTOR \
|
#define SRV_TEST_VECTOR \
|
||||||
"2A9B1D6237DAB312A40F575DA85C147663E7ED3F80E9555395F15B515C74253D"
|
"2A9B1D6237DAB312A40F575DA85C147663E7ED3F80E9555395F15B515C74253D"
|
||||||
|
|
||||||
MOCK(trusteddirserver_get_by_v3_auth_digest,
|
|
||||||
trusteddirserver_get_by_v3_auth_digest_m);
|
|
||||||
|
|
||||||
MOCK(trusteddirserver_get_by_v3_auth_digest,
|
MOCK(trusteddirserver_get_by_v3_auth_digest,
|
||||||
trusteddirserver_get_by_v3_auth_digest_m);
|
trusteddirserver_get_by_v3_auth_digest_m);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user