Skip to content

Commit

Permalink
.to_montgomery() -> .retrieve
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Jan 27, 2024
1 parent 31c5d8b commit f4efee6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dsa/src/generate/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn common(
let g = loop {
let params = BoxedMontyParams::new_vartime(Odd::new((*p).clone()).unwrap());
let form = BoxedMontyForm::new(h.clone(), params);
let g = form.pow(&e).to_montgomery();
let g = form.pow(&e).retrieve();

if !bool::from(g.is_one()) {
break NonZero::new(g).unwrap();
Expand All @@ -78,5 +78,5 @@ pub fn public(components: &Components, x: &NonZero<BoxedUint>) -> NonZero<BoxedU
let params = BoxedMontyParams::new_vartime(Odd::new((**p).clone()).unwrap());
let form = BoxedMontyForm::new((**g).clone(), params);

NonZero::new(form.pow(x).to_montgomery()).unwrap()
NonZero::new(form.pow(x).retrieve()).unwrap()
}
2 changes: 1 addition & 1 deletion dsa/src/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl SigningKey {

let params = BoxedMontyParams::new(Odd::new(k).unwrap());
let form = BoxedMontyForm::new((**g).clone(), params);
let r = NonZero::new(form.pow(p).to_montgomery() % q).unwrap();
let r = NonZero::new(form.pow(p).retrieve() % q).unwrap();

let n = q.bits() / 8;
let block_size = hash.len(); // Hash function output size
Expand Down
4 changes: 2 additions & 2 deletions dsa/src/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl VerifyingKey {
let params = BoxedMontyParams::new_vartime(Odd::new((**components.p()).clone()).unwrap());
let form = BoxedMontyForm::new((*y).clone(), params);

if *y < two() || form.pow(components.q()).to_montgomery() != BoxedUint::one() {
if *y < two() || form.pow(components.q()).retrieve() != BoxedUint::one() {
return Err(signature::Error::new());
}

Expand Down Expand Up @@ -85,7 +85,7 @@ impl VerifyingKey {
let g_form = BoxedMontyForm::new((**g).clone(), u1_params);
let y_form = BoxedMontyForm::new((**y).clone(), u2_params);

let v = (g_form.pow(p).to_montgomery() * y_form.pow(p).to_montgomery() % p) % q;
let v = (g_form.pow(p).retrieve() * y_form.pow(p).retrieve() % p) % q;

Some(v == **r)
}
Expand Down
8 changes: 2 additions & 6 deletions dsa/tests/deterministic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ fn dsa_2048_signing_key() -> SigningKey {
92B871CD8F9C36D3292B5509CA8CAA77A2ADFC7BFD77DDA6F71125A7456FEA15\
3E433256A2261C6A06ED3693797E7995FAD5AABBCFBE3EDA2741E375404AE25B",
);
let q = decode_hex_number(
"F2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F",
);
let q = decode_hex_number("F2C3119374CE76C9356990B465374A17F23F9ED35089BD969F61C6DDE9998C1F");
let g = decode_hex_number(
"5C7FF6B06F8F143FE8288433493E4769C4D988ACE5BE25A0E24809670716C613\
D7B0CEE6932F8FAA7C44D2CB24523DA53FBE4F6EC3595892D1AA58C4328A06C4\
Expand All @@ -78,9 +76,7 @@ fn dsa_2048_signing_key() -> SigningKey {
DC4473F996BDCE6EED1CABED8B6F116F7AD9CF505DF0F998E34AB27514B0FFE7",
);

let x = decode_hex_number(
"69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC",
);
let x = decode_hex_number("69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC");
let y = decode_hex_number(
"667098C654426C78D7F8201EAC6C203EF030D43605032C2F1FA937E5237DBD94\
9F34A0A2564FE126DC8B715C5141802CE0979C8246463C40E6B6BDAA2513FA61\
Expand Down
2 changes: 1 addition & 1 deletion dsa/tests/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn verify_validity() {
);
assert_eq!(
**signing_key.verifying_key().y(),
form.pow(signing_key.x()).to_montgomery(),
form.pow(signing_key.x()).retrieve(),
"Requirement y=(g^x)%p not met"
);
}
2 changes: 1 addition & 1 deletion dsa/tests/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ fn validate_verifying_key() {
let form = BoxedMontyForm::new((**verifying_key.y()).clone(), params);

// Taken from the parameter validation from bouncy castle
assert_eq!(form.pow(p).to_montgomery(), BoxedUint::one());
assert_eq!(form.pow(p).retrieve(), BoxedUint::one());
}

0 comments on commit f4efee6

Please sign in to comment.