Skip to content

Commit

Permalink
Constant-time Kronecker delta
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Jan 2, 2024
1 parent bc5c934 commit 613c9a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ merlin = { version = "3.0.0", default-features = false }
rand_core = { version = "0.6.4", default-features = false }
serde = { version = "1.0.193", optional = true, default-features = false, features = ["alloc", "derive"] }
snafu = { version = "0.7.5", default-features = false }
subtle = { version = "2.5.0", default-features = false, features = ["core_hint_black_box"] }
zeroize = { version = "1.7.0", default-features = false, features = ["alloc"] }

[dev-dependencies]
Expand Down
11 changes: 5 additions & 6 deletions src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rand_core::CryptoRngCore;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use snafu::prelude::*;
use subtle::{ConditionallySelectable, ConstantTimeEq};
use zeroize::Zeroizing;

use crate::{statement::Statement, witness::Witness};
Expand Down Expand Up @@ -49,13 +50,11 @@ pub enum ProofError {
InvalidChallenge,
}

/// Kronecker delta function with scalar output.
/// Constant-time Kronecker delta function with scalar output.
fn delta(x: u32, y: u32) -> Scalar {
if x == y {
Scalar::ONE
} else {
Scalar::ZERO
}
let mut result = Scalar::ZERO;
result.conditional_assign(&Scalar::ONE, x.ct_eq(&y));
result
}

/// Get nonzero powers of a challenge value from a transcript.
Expand Down

0 comments on commit 613c9a0

Please sign in to comment.