MCPcopy Create free account
hub / github.com/RustCrypto/RSA / modulus_blinding_arithmetic

Function modulus_blinding_arithmetic

src/algorithms/blinding.rs:167–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

165
166 #[test]
167 fn modulus_blinding_arithmetic() {
168 for bits in [64, 128, 192] {
169 let prime = Odd::new(BoxedUint::max(bits)).expect("odd modulus");
170 let blinded_bits = bits + BoxedUint::zero_with_precision(129).bits_precision();
171 let p = prime.as_ref().resize_unchecked(blinded_bits);
172 let mut rng = MockRng(
173 [0u128, 1, u128::MAX]
174 .map(|r| r.to_le_bytes().to_vec())
175 .into(),
176 );
177 for expected in [
178 p.clone(),
179 p.shl(1).wrapping_add(&p),
180 p.shl(129).wrapping_sub(&p),
181 ] {
182 let blinded = blind_modulus(&mut rng, &prime).expect("blinded modulus");
183 assert_eq!(blinded.as_ref(), &expected);
184 assert_eq!(blinded.bits_precision(), blinded_bits);
185 }
186 assert!(rng.0.is_empty());
187 }
188 }
189
190 #[test]
191 fn modulus_blinding_reduces_to_original_prime() {

Callers

nothing calls this directly

Calls 4

MockRngClass · 0.85
blind_modulusFunction · 0.85
as_refMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected