MCPcopy Create free account
hub / github.com/RustCrypto/utils / CtNeg

Interface CtNeg

ctutils/src/traits/ct_neg.rs:11–22  ·  view source on GitHub ↗

Constant-time conditional negation: negates a value when `choice` is [`Choice::TRUE`]. Integer implementations use wrapping negation, including signed and non-zero integers. Negating a signed integer's minimum value therefore returns that value.

Source from the content-addressed store, hash-verified

9/// Integer implementations use wrapping negation, including signed and non-zero integers.
10/// Negating a signed integer's minimum value therefore returns that value.
11pub trait CtNeg: Sized {
12 /// Conditionally negate `self`, returning `-self` if `choice` is [`Choice::TRUE`], or `self`
13 /// otherwise.
14 #[must_use]
15 fn ct_neg(&self, choice: Choice) -> Self;
16
17 /// Conditionally negate `self` in-place, replacing it with `-self` if `choice` is
18 /// [`Choice::TRUE`].
19 fn ct_neg_assign(&mut self, choice: Choice) {
20 *self = self.ct_neg(choice);
21 }
22}
23
24// Impl `CtNeg` for a signed integer (`i*`) type which impls `CtSelect`
25macro_rules! impl_signed_ct_neg {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected