mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
testsc: add random_advance_counter().
In test_primegen, we loop round retrieving random data until we find some that will permit a successful prime generation, so that we can log only the successful attempts, and not the failures (which don't have to be time-safe). But this itself introduces a potential mismatch between logs, because the simplistic RNG used in testsc will have different control flow depending on how far through a buffer of hash data it is at the start of a given run. random_advance_counter() gives it a fresh buffer, so calling that at the start of a run should normalise this out. The code to do that was already in the middle of random_read(); I've just pulled it out into a separately callable function. This hasn't _actually_ caused failures in test_primegen, but I'm not sure why not. (Perhaps just luck.) But it did cause a failure in another test of a similar nature, so before I commit _that_ test (and the thing it's testing), I'd better fix this.
This commit is contained in:
parent
1500da80f1
commit
3adfb1aa5b
@ -114,19 +114,23 @@ static void random_seed(const char *seedstr)
|
||||
random_buf_limit = 0;
|
||||
}
|
||||
|
||||
static void random_advance_counter(void)
|
||||
{
|
||||
ssh_hash_reset(random_hash);
|
||||
put_asciz(random_hash, random_seedstr);
|
||||
put_uint64(random_hash, random_counter);
|
||||
random_counter++;
|
||||
random_buf_limit = ssh_hash_alg(random_hash)->hlen;
|
||||
ssh_hash_digest(random_hash, random_buf);
|
||||
}
|
||||
|
||||
void random_read(void *vbuf, size_t size)
|
||||
{
|
||||
assert(random_seedstr);
|
||||
uint8_t *buf = (uint8_t *)vbuf;
|
||||
while (size-- > 0) {
|
||||
if (random_buf_limit == 0) {
|
||||
ssh_hash_reset(random_hash);
|
||||
put_asciz(random_hash, random_seedstr);
|
||||
put_uint64(random_hash, random_counter);
|
||||
random_counter++;
|
||||
random_buf_limit = ssh_hash_alg(random_hash)->hlen;
|
||||
ssh_hash_digest(random_hash, random_buf);
|
||||
}
|
||||
if (random_buf_limit == 0)
|
||||
random_advance_counter();
|
||||
*buf++ = random_buf[random_buf_limit--];
|
||||
}
|
||||
}
|
||||
@ -1514,6 +1518,7 @@ static void test_primegen(const PrimeGenerationPolicy *policy)
|
||||
|
||||
for (size_t i = 0; i < looplimit(2); i++) {
|
||||
while (true) {
|
||||
random_advance_counter();
|
||||
struct random_state st = random_get_state();
|
||||
|
||||
PrimeCandidateSource *pcs = pcs_new(128);
|
||||
|
Loading…
Reference in New Issue
Block a user