Skip to content

Commit 0396fb3

Browse files
committed
use descriptive field names in schnorr::ID
1 parent 3a58aee commit 0396fb3

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/schnorr.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,55 @@ pub struct ID {
1818
/// ID
1919
pub id: Scalar,
2020
/// Commitment to the proof random value
21-
pub R: Point,
21+
pub random_commitment: Point,
2222
/// Sigma protocol response
23-
pub s: Scalar,
23+
pub sigma_response: Scalar,
2424
}
2525

2626
#[allow(non_snake_case)]
2727
impl ID {
2828
/// Construct a new schnorr ID that proves ownership of private key `x` bound to `id`
2929
pub fn new<RNG: RngCore + CryptoRng>(id: &Scalar, x: &Scalar, rng: &mut RNG) -> Self {
3030
let r = Scalar::random(rng);
31-
let R = r * G;
32-
let X = x * G;
33-
let c = Self::challenge(id, &R, &X);
34-
let s = r + c * x;
31+
let random_commitment = r * G;
32+
let public_key = x * G;
33+
let c = Self::challenge(id, &random_commitment, &public_key);
34+
let sigma_response = r + c * x;
3535

36-
Self { id: *id, R, s }
36+
Self {
37+
id: *id,
38+
random_commitment,
39+
sigma_response,
40+
}
3741
}
3842

3943
/// Compute the schnorr challenge
40-
pub fn challenge(id: &Scalar, R: &Point, X: &Point) -> Scalar {
44+
pub fn challenge(id: &Scalar, random_commitment: &Point, public_key: &Point) -> Scalar {
4145
let mut hasher = Sha256::new();
4246
let tag = "WSTS/polynomial-constant";
4347

4448
hasher.update(tag.as_bytes());
4549
hasher.update(id.to_bytes());
46-
hasher.update(R.compress().as_bytes());
47-
hasher.update(X.compress().as_bytes());
50+
hasher.update(random_commitment.compress().as_bytes());
51+
hasher.update(public_key.compress().as_bytes());
4852

4953
hash_to_scalar(&mut hasher)
5054
}
5155

52-
/// Verify the proof against the public key `X`
53-
pub fn verify(&self, X: &Point) -> bool {
54-
let c = Self::challenge(&self.id, &self.R, X);
55-
&self.s * &G == &self.R + c * X
56+
/// Verify the proof against the public key
57+
pub fn verify(&self, public_key: &Point) -> bool {
58+
let c = Self::challenge(&self.id, &self.random_commitment, public_key);
59+
&self.sigma_response * &G == &self.random_commitment + c * public_key
5660
}
5761

5862
/// Zero out the schnorr proof
5963
pub fn zero(&mut self) {
60-
self.R = Point::new();
61-
self.s = Scalar::zero();
64+
self.random_commitment = Point::new();
65+
self.sigma_response = Scalar::zero();
6266
}
6367

6468
/// Check if schnorr proof is zeroed out
6569
pub fn is_zero(&self) -> bool {
66-
self.R == Point::new() && self.s == Scalar::zero()
70+
self.random_commitment == Point::new() && self.sigma_response == Scalar::zero()
6771
}
6872
}

src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ pub mod test_helpers {
362362
if party_id == bad_party_id {
363363
// alter the schnorr proof so it will fail verification
364364
let mut bad_comm = comm.clone();
365-
bad_comm.id.s += Scalar::from(1);
365+
bad_comm.id.sigma_response += Scalar::from(1);
366366
(party_id, bad_comm)
367367
} else {
368368
(party_id, comm)

0 commit comments

Comments
 (0)