diff --git a/src/ibe/waters.rs b/src/ibe/waters.rs index 83cf1c8..bcad2fb 100644 --- a/src/ibe/waters.rs +++ b/src/ibe/waters.rs @@ -170,22 +170,19 @@ impl IBE for Waters { /// Decrypt ciphertext to a message using a user secret key. fn decrypt(usk: &UserSecretKey, c: &CipherText) -> Msg { - let m = c.c1 - + multi_miller_loop(&[ - (&c.c3, &G2Prepared::from(usk.d2)), - (&-usk.d1, &G2Prepared::from(c.c2)), - ]) - .final_exponentiation(); - - m + c.c1 + multi_miller_loop(&[ + (&c.c3, &G2Prepared::from(usk.d2)), + (&-usk.d1, &G2Prepared::from(c.c2)), + ]) + .final_exponentiation() } } impl Parameters { - pub fn to_bytes(&self) -> [u8; PARAMETERSIZE] { + pub fn to_bytes(self) -> [u8; PARAMETERSIZE] { let mut res = [0u8; PARAMETERSIZE]; - for i in 0..CHUNKS { - *array_mut_ref![&mut res, i * 48, 48] = self.0[i].to_compressed(); + for (i, p) in self.0.iter().enumerate() { + *array_mut_ref![&mut res, i * 48, 48] = p.to_compressed(); } res } @@ -193,10 +190,10 @@ impl Parameters { pub fn from_bytes(bytes: &[u8; PARAMETERSIZE]) -> CtOption { let mut res = [G1Affine::default(); CHUNKS]; let mut is_some = Choice::from(1u8); - for i in 0..CHUNKS { + for (i, slot) in res.iter_mut().enumerate() { is_some &= G1Affine::from_compressed(array_ref![bytes, i * 48, 48]) .map(|s| { - res[i] = s; + *slot = s; }) .is_some(); } @@ -208,7 +205,7 @@ impl ConditionallySelectable for Parameters { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self { let mut res = [G1Affine::default(); CHUNKS]; for (i, (ai, bi)) in a.0.iter().zip(b.0.iter()).enumerate() { - res[i] = G1Affine::conditional_select(&ai, &bi, choice); + res[i] = G1Affine::conditional_select(ai, bi, choice); } Parameters(res) } @@ -216,11 +213,7 @@ impl ConditionallySelectable for Parameters { impl Clone for Parameters { fn clone(&self) -> Self { - let mut res = [G1Affine::default(); CHUNKS]; - for (src, dst) in self.0.iter().zip(res.as_mut().iter_mut()) { - *dst = *src; - } - Parameters(res) + *self } } @@ -254,11 +247,7 @@ impl Derive for Identity { impl Clone for Identity { fn clone(&self) -> Self { - let mut res = [u8::default(); HASH_BYTE_LEN]; - for (src, dst) in self.0.iter().zip(res.as_mut().iter_mut()) { - *dst = *src; - } - Identity(res) + *self } } diff --git a/src/ibe/waters_naccache.rs b/src/ibe/waters_naccache.rs index 4bd6fa6..58dad1b 100644 --- a/src/ibe/waters_naccache.rs +++ b/src/ibe/waters_naccache.rs @@ -173,14 +173,11 @@ impl IBE for WatersNaccache { /// Decrypt ciphertext to a message using a user secret key. fn decrypt(usk: &UserSecretKey, c: &CipherText) -> Msg { - let m = c.c1 - + multi_miller_loop(&[ - (&usk.d2, &G2Prepared::from(c.c3)), - (&-c.c2, &G2Prepared::from(usk.d1)), - ]) - .final_exponentiation(); - - m + c.c1 + multi_miller_loop(&[ + (&usk.d2, &G2Prepared::from(c.c3)), + (&-c.c2, &G2Prepared::from(usk.d1)), + ]) + .final_exponentiation() } } @@ -188,17 +185,17 @@ impl ConditionallySelectable for Parameters { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self { let mut res = [G2Affine::default(); CHUNKS]; for (i, (ai, bi)) in a.0.iter().zip(b.0.iter()).enumerate() { - res[i] = G2Affine::conditional_select(&ai, &bi, choice); + res[i] = G2Affine::conditional_select(ai, bi, choice); } Parameters(res) } } impl Parameters { - pub fn to_bytes(&self) -> [u8; PARAMETERSIZE] { + pub fn to_bytes(self) -> [u8; PARAMETERSIZE] { let mut res = [0u8; PARAMETERSIZE]; - for i in 0..CHUNKS { - *array_mut_ref![&mut res, i * 96, 96] = self.0[i].to_compressed(); + for (i, p) in self.0.iter().enumerate() { + *array_mut_ref![&mut res, i * 96, 96] = p.to_compressed(); } res } @@ -206,10 +203,10 @@ impl Parameters { pub fn from_bytes(bytes: &[u8; PARAMETERSIZE]) -> CtOption { let mut res = [G2Affine::default(); CHUNKS]; let mut is_some = Choice::from(1u8); - for i in 0..CHUNKS { + for (i, slot) in res.iter_mut().enumerate() { is_some &= G2Affine::from_compressed(array_ref![bytes, i * 96, 96]) .map(|s| { - res[i] = s; + *slot = s; }) .is_some(); } diff --git a/src/kem/kiltz_vahlis_one.rs b/src/kem/kiltz_vahlis_one.rs index 5e1af1c..54b9bfb 100644 --- a/src/kem/kiltz_vahlis_one.rs +++ b/src/kem/kiltz_vahlis_one.rs @@ -175,10 +175,10 @@ impl IBKEM for KV1 { } impl HashParameters { - pub fn to_bytes(&self) -> [u8; HASH_PARAMETER_SIZE] { + pub fn to_bytes(self) -> [u8; HASH_PARAMETER_SIZE] { let mut res = [0u8; HASH_PARAMETER_SIZE]; - for i in 0..N { - *array_mut_ref![&mut res, i * 48, 48] = self.0[i].to_compressed(); + for (i, p) in self.0.iter().enumerate() { + *array_mut_ref![&mut res, i * 48, 48] = p.to_compressed(); } res } @@ -186,11 +186,11 @@ impl HashParameters { pub fn from_bytes(bytes: &[u8; HASH_PARAMETER_SIZE]) -> CtOption { let mut res = [G1Affine::default(); N]; let mut is_some = Choice::from(1u8); - for i in 0..N { + for (i, slot) in res.iter_mut().enumerate() { // See comment in PublicKey::from_bytes on cofactor. is_some &= G1Affine::from_compressed_unchecked(array_ref![bytes, i * 48, 48]) .map(|s| { - res[i] = s; + *slot = s; }) .is_some(); } @@ -202,7 +202,7 @@ impl ConditionallySelectable for HashParameters { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self { let mut res = [G1Affine::default(); N]; for (i, (ai, bi)) in a.0.iter().zip(b.0.iter()).enumerate() { - res[i] = G1Affine::conditional_select(&ai, &bi, choice); + res[i] = G1Affine::conditional_select(ai, bi, choice); } HashParameters(res) } @@ -216,11 +216,7 @@ impl PartialEq for HashParameters { impl Clone for HashParameters { fn clone(&self) -> Self { - let mut res = [G1Affine::default(); N]; - for (src, dst) in self.0.iter().zip(res.as_mut().iter_mut()) { - *dst = *src; - } - Self(res) + *self } }