/* Return a srv object that is built with the construction:
* 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. */
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)
{
char msg[DIGEST256_LEN + SR_SRV_MSG_LEN] = {0};
/* Add the invariant token. */
memcpy(msg, SR_SRV_TOKEN, SR_SRV_TOKEN_LEN);
offset += SR_SRV_TOKEN_LEN;
- set_uint8(msg + offset, reveal_num);
- offset += 1;
- set_uint8(msg + offset, SR_PROTO_VERSION);
- offset += 1;
+ set_uint64(msg + offset, tor_htonll(reveal_num));
+ offset += sizeof(uint64_t);
+ set_uint32(msg + offset, htonl(SR_PROTO_VERSION));
+ offset += sizeof(uint32_t);
memcpy(msg + offset, hashed_reveals, DIGEST256_LEN);
offset += DIGEST256_LEN;
if (previous_srv != NULL) {
tor_assert(key);
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);
log_debug(LD_DIR, "SR: Consensus SRV line: %s", srv_str);
return srv_str;
void
sr_compute_srv(void)
{
- size_t reveal_num = 0;
+ uint64_t reveal_num = 0;
char *reveals = NULL;
smartlist_t *chunks, *commits;
digestmap_t *state_commits;
SR_DIGEST_ALG)) {
goto end;
}
- tor_assert(reveal_num < UINT8_MAX);
- current_srv = generate_srv(hashed_reveals, (uint8_t) reveal_num,
+ current_srv = generate_srv(hashed_reveals, reveal_num,
sr_state_get_previous_srv());
sr_state_set_current_srv(current_srv);
/* We have a fresh SRV, flag our state. */
sr_parse_srv(const smartlist_t *args)
{
char *value;
- int num_reveals, ok, ret;
+ int ok, ret;
+ uint64_t num_reveals;
sr_srv_t *srv = NULL;
tor_assert(args);
}
/* First argument is the number of reveal values */
- num_reveals = (int)tor_parse_long(smartlist_get(args, 0),
- 10, 0, INT32_MAX, &ok, NULL);
+ num_reveals = tor_parse_uint64(smartlist_get(args, 0),
+ 10, 0, UINT64_MAX, &ok, NULL);
if (!ok) {
goto end;
}
* timestamp and the hashed random number. This adds up to 40 bytes. */
#define SR_REVEAL_LEN (sizeof(uint64_t) + DIGEST256_LEN)
/* 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 \
- (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.
* Formula is taken from base64_encode_size. */
/* A shared random value (SRV). */
typedef struct sr_srv_t {
/* 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. */
uint8_t value[DIGEST256_LEN];
} sr_srv_t;
/* Array of variables that are saved to disk as a persistent state. */
static config_var_t state_vars[] = {
- V(Version, INT, "0"),
+ V(Version, UINT, "0"),
V(TorVersion, STRING, NULL),
V(ValidAfter, ISOTIME, NULL),
V(ValidUntil, ISOTIME, NULL),
return;
}
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. */