Avoid if, like upstream

This commit is contained in:
Jacek Sieka 2020-04-11 09:59:44 +02:00
parent 3db2e94813
commit 1dd68bcd47
No known key found for this signature in database
GPG Key ID: A1B09461ABB656B8
1 changed files with 15 additions and 15 deletions

View File

@ -81,23 +81,23 @@ int secp256k1_ecdh_raw(const secp256k1_context* ctx, unsigned char *result, cons
secp256k1_pubkey_load(ctx, &pt, point); secp256k1_pubkey_load(ctx, &pt, point);
secp256k1_scalar_set_b32(&s, scalar, &overflow); secp256k1_scalar_set_b32(&s, scalar, &overflow);
if (overflow || secp256k1_scalar_is_zero(&s)) {
ret = 0; overflow |= secp256k1_scalar_is_zero(&s);
} else { secp256k1_scalar_cmov(&s, &secp256k1_scalar_one, overflow);
secp256k1_ecmult_const(&res, &pt, &s);
secp256k1_ge_set_gej(&pt, &res); secp256k1_ecmult_const(&res, &pt, &s, 256);
/* Output the point in compressed form. secp256k1_ge_set_gej(&pt, &res);
* Note we cannot use secp256k1_eckey_pubkey_serialize here since it does not
* expect its output to be secret and has a timing sidechannel. */ /* Output the point in compressed form.
secp256k1_fe_normalize(&pt.x); * Note we cannot use secp256k1_eckey_pubkey_serialize here since it does not
secp256k1_fe_normalize(&pt.y); * expect its output to be secret and has a timing sidechannel. */
result[0] = 0x02 | secp256k1_fe_is_odd(&pt.y); secp256k1_fe_normalize(&pt.x);
secp256k1_fe_get_b32(&result[1], &pt.x); secp256k1_fe_normalize(&pt.y);
ret = 1; result[0] = 0x02 | secp256k1_fe_is_odd(&pt.y);
} secp256k1_fe_get_b32(&result[1], &pt.x);
secp256k1_scalar_clear(&s); secp256k1_scalar_clear(&s);
return ret; return !overflow;
} }
#endif /* SECP256K1_MODULE_ECDH_MAIN_H */ #endif /* SECP256K1_MODULE_ECDH_MAIN_H */