static int get_faked_bytes(unsigned char *buf, int num)
{
- int i;
-
if (fake_rand_bytes == NULL)
return saved_rand->bytes(buf, num);
- if (!TEST_size_t_le(fake_rand_bytes_offset + num, fake_rand_size))
+ if (!TEST_size_t_gt(fake_rand_size, 0))
return 0;
- for (i = 0; i != num; ++i)
- buf[i] = fake_rand_bytes[fake_rand_bytes_offset + i];
- fake_rand_bytes_offset += num;
+ while (num-- > 0) {
+ if (fake_rand_bytes_offset >= fake_rand_size)
+ fake_rand_bytes_offset = 0;
+ *buf++ = fake_rand_bytes[fake_rand_bytes_offset++];
+ }
+
return 1;
}
start_fake_rand(k_hex);
if (!TEST_true(sm2_encrypt(key, digest, (const uint8_t *)message, msg_len,
- ctext, &ctext_len))
- || !TEST_size_t_eq(fake_rand_bytes_offset, fake_rand_size)) {
+ ctext, &ctext_len))) {
restore_rand();
goto done;
}
start_fake_rand(k_hex);
sig = sm2_do_sign(key, EVP_sm3(), (const uint8_t *)userid, strlen(userid),
(const uint8_t *)message, msg_len);
- if (!TEST_ptr(sig)
- || !TEST_size_t_eq(fake_rand_bytes_offset, fake_rand_size)) {
+ if (!TEST_ptr(sig)) {
restore_rand();
goto done;
}