Optimize key generation.
GitOrigin-RevId: e0958f470a15aa83066d20685c15a056d853a42a
This commit is contained in:
parent
d02f0ffba9
commit
219c35f007
@ -295,12 +295,8 @@ class TlsHelloStore {
|
|||||||
auto key = dest_.substr(0, 32);
|
auto key = dest_.substr(0, 32);
|
||||||
while (true) {
|
while (true) {
|
||||||
Random::secure_bytes(key);
|
Random::secure_bytes(key);
|
||||||
key[31] = static_cast<char>(key[31] & 127);
|
BigNum x = BigNum::from_binary(key);
|
||||||
BigNum x = BigNum::from_le_binary(key);
|
BigNum::mod_mul(x, x, x, mod, big_num_context);
|
||||||
if (!is_quadratic_residue(x)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigNum y = x.clone();
|
BigNum y = x.clone();
|
||||||
BigNum coef = BigNum::from_decimal("486662").move_as_ok();
|
BigNum coef = BigNum::from_decimal("486662").move_as_ok();
|
||||||
BigNum::mod_add(y, y, coef, mod, big_num_context);
|
BigNum::mod_add(y, y, coef, mod, big_num_context);
|
||||||
@ -310,6 +306,7 @@ class TlsHelloStore {
|
|||||||
BigNum::mod_mul(y, y, x, mod, big_num_context);
|
BigNum::mod_mul(y, y, x, mod, big_num_context);
|
||||||
// y = x^3 + 486662 * x^2 + x
|
// y = x^3 + 486662 * x^2 + x
|
||||||
if (is_quadratic_residue(y)) {
|
if (is_quadratic_residue(y)) {
|
||||||
|
key.copy_from(x.to_le_binary(32));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user