mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Use black_box to help obscure the dalek-ff-group bool -> Choice conversion
I have no idea if this will actually help, yet it can't hurt. Feature gated due to MSRV requirements. Fixes #242.
This commit is contained in:
@@ -29,3 +29,6 @@ curve25519-dalek = "^3.2"
|
||||
|
||||
[dev-dependencies]
|
||||
ff-group-tests = { path = "../ff-group-tests" }
|
||||
|
||||
[features]
|
||||
black_box = []
|
||||
|
||||
@@ -43,7 +43,14 @@ pub mod field;
|
||||
|
||||
// Convert a boolean to a Choice in a *presumably* constant time manner
|
||||
fn choice(value: bool) -> Choice {
|
||||
Choice::from(u8::from(value))
|
||||
#[cfg(not(feature = "black_box"))]
|
||||
let res = Choice::from(u8::from(value));
|
||||
#[cfg(feature = "black_box")]
|
||||
let res = {
|
||||
use core::hint::black_box;
|
||||
Choice::from(black_box(u8::from(black_box(value))))
|
||||
};
|
||||
res
|
||||
}
|
||||
|
||||
macro_rules! deref_borrow {
|
||||
|
||||
Reference in New Issue
Block a user