mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
Make consensus diff sha3 operations mockable.
(We'll want this for fuzzing)
This commit is contained in:
parent
6a36e5ff3b
commit
653c6d129e
@ -51,6 +51,14 @@ consensus_compute_digest,(const char *cons,
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** DOCDOC */
|
||||||
|
MOCK_IMPL(STATIC int,
|
||||||
|
consensus_digest_eq,(const uint8_t *d1,
|
||||||
|
const uint8_t *d2))
|
||||||
|
{
|
||||||
|
return fast_memeq(d1, d2, DIGEST256_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
/** Create (allocate) a new slice from a smartlist. Assumes that the start
|
/** Create (allocate) a new slice from a smartlist. Assumes that the start
|
||||||
* and the end indexes are within the bounds of the initial smartlist. The end
|
* and the end indexes are within the bounds of the initial smartlist. The end
|
||||||
* element is not part of the resulting slice. If end is -1, the slice is to
|
* element is not part of the resulting slice. If end is -1, the slice is to
|
||||||
@ -965,8 +973,8 @@ consdiff_apply_diff(const smartlist_t *cons1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* See that the consensus that was given to us matches its hash. */
|
/* See that the consensus that was given to us matches its hash. */
|
||||||
if (fast_memneq(digests1->sha3_256, e_cons1_hash,
|
if (!consensus_digest_eq(digests1->sha3_256,
|
||||||
DIGEST256_LEN)) {
|
(const uint8_t*)e_cons1_hash)) {
|
||||||
char hex_digest1[HEX_DIGEST256_LEN+1];
|
char hex_digest1[HEX_DIGEST256_LEN+1];
|
||||||
char e_hex_digest1[HEX_DIGEST256_LEN+1];
|
char e_hex_digest1[HEX_DIGEST256_LEN+1];
|
||||||
log_warn(LD_CONSDIFF, "Refusing to apply consensus diff because "
|
log_warn(LD_CONSDIFF, "Refusing to apply consensus diff because "
|
||||||
@ -1002,8 +1010,8 @@ consdiff_apply_diff(const smartlist_t *cons1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* See that the resulting consensus matches its hash. */
|
/* See that the resulting consensus matches its hash. */
|
||||||
if (fast_memneq(cons2_digests.sha3_256, e_cons2_hash,
|
if (!consensus_digest_eq(cons2_digests.sha3_256,
|
||||||
DIGEST256_LEN)) {
|
(const uint8_t*)e_cons2_hash)) {
|
||||||
log_warn(LD_CONSDIFF, "Refusing to apply consensus diff because "
|
log_warn(LD_CONSDIFF, "Refusing to apply consensus diff because "
|
||||||
"the resulting consensus doesn't match the digest as found in "
|
"the resulting consensus doesn't match the digest as found in "
|
||||||
"the consensus diff header.");
|
"the consensus diff header.");
|
||||||
|
@ -62,8 +62,13 @@ STATIC int smartlist_slice_string_pos(const smartlist_slice_t *slice,
|
|||||||
STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
|
STATIC void set_changed(bitarray_t *changed1, bitarray_t *changed2,
|
||||||
const smartlist_slice_t *slice1,
|
const smartlist_slice_t *slice1,
|
||||||
const smartlist_slice_t *slice2);
|
const smartlist_slice_t *slice2);
|
||||||
STATIC int consensus_compute_digest(const char *cons,
|
|
||||||
consensus_digest_t *digest_out);
|
MOCK_DECL(STATIC int,
|
||||||
|
consensus_compute_digest,(const char *cons,
|
||||||
|
consensus_digest_t *digest_out));
|
||||||
|
MOCK_DECL(STATIC int,
|
||||||
|
consensus_digest_eq,(const uint8_t *d1,
|
||||||
|
const uint8_t *d2));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user