diff --git a/coins/monero/src/transaction.rs b/coins/monero/src/transaction.rs index 3a1d5889..6dd6c7b1 100644 --- a/coins/monero/src/transaction.rs +++ b/coins/monero/src/transaction.rs @@ -71,7 +71,7 @@ impl Output { pub fn serialize(&self, w: &mut W) -> std::io::Result<()> { write_varint(&self.amount, w)?; - w.write_all(&[2 + (if self.view_tag.is_some() { 1 } else { 0 })])?; + w.write_all(&[2 + u8::from(self.view_tag.is_some())])?; w.write_all(&self.key.to_bytes())?; if let Some(view_tag) = self.view_tag { w.write_all(&[view_tag])?; diff --git a/coins/monero/src/wallet/address.rs b/coins/monero/src/wallet/address.rs index 36587215..aa11eefb 100644 --- a/coins/monero/src/wallet/address.rs +++ b/coins/monero/src/wallet/address.rs @@ -133,9 +133,7 @@ impl ToString for Address { if let AddressType::Featured(subaddress, payment_id, guaranteed) = self.meta.kind { // Technically should be a VarInt, yet we don't have enough features it's needed data.push( - (if subaddress { 1 } else { 0 }) + - ((if payment_id.is_some() { 1 } else { 0 }) << 1) + - ((if guaranteed { 1 } else { 0 }) << 2), + u8::from(subaddress) + (u8::from(payment_id.is_some()) << 1) + (u8::from(guaranteed) << 2), ); } if let Some(id) = self.meta.kind.payment_id() { diff --git a/coins/monero/src/wallet/send/mod.rs b/coins/monero/src/wallet/send/mod.rs index 0eff16cd..53cd9855 100644 --- a/coins/monero/src/wallet/send/mod.rs +++ b/coins/monero/src/wallet/send/mod.rs @@ -223,7 +223,7 @@ impl SignableTransaction { if change && change_address.is_none() { Err(TransactionError::NoChange)?; } - let outputs = payments.len() + (if change { 1 } else { 0 }); + let outputs = payments.len() + usize::from(change); // Calculate the extra length let extra = Extra::fee_weight(outputs, data.as_ref()); diff --git a/crypto/dalek-ff-group/src/field.rs b/crypto/dalek-ff-group/src/field.rs index cac19b25..1c89e63f 100644 --- a/crypto/dalek-ff-group/src/field.rs +++ b/crypto/dalek-ff-group/src/field.rs @@ -165,8 +165,7 @@ impl FieldElement { let mut bits = 0; for (i, bit) in other.to_le_bits().iter().rev().enumerate() { bits <<= 1; - let bit = *bit as u8; - assert_eq!(bit | 1, 1); + let bit = u8::from(*bit); bits |= bit; if ((i + 1) % 4) == 0 { diff --git a/crypto/dalek-ff-group/src/lib.rs b/crypto/dalek-ff-group/src/lib.rs index 31c8edae..5bf162b9 100644 --- a/crypto/dalek-ff-group/src/lib.rs +++ b/crypto/dalek-ff-group/src/lib.rs @@ -37,9 +37,7 @@ pub mod field; // Convert a boolean to a Choice in a *presumably* constant time manner fn choice(value: bool) -> Choice { - let bit = value as u8; - debug_assert_eq!(bit | 1, 1); - Choice::from(bit) + Choice::from(u8::from(value)) } macro_rules! deref_borrow { diff --git a/crypto/dleq/src/cross_group/mod.rs b/crypto/dleq/src/cross_group/mod.rs index 7d2501e2..6f0aa27b 100644 --- a/crypto/dleq/src/cross_group/mod.rs +++ b/crypto/dleq/src/cross_group/mod.rs @@ -226,8 +226,7 @@ where break; } - let mut bit = *raw_bit as u8; - debug_assert_eq!(bit | 1, 1); + let mut bit = u8::from(*raw_bit); *raw_bit = false; // Accumulate this bit @@ -246,7 +245,7 @@ where these_bits, &mut blinding_key, )); - these_bits = 0; + these_bits.zeroize(); } } debug_assert_eq!(bits.len(), capacity / bits_per_group); diff --git a/crypto/dleq/src/cross_group/scalar.rs b/crypto/dleq/src/cross_group/scalar.rs index 5000c223..44343135 100644 --- a/crypto/dleq/src/cross_group/scalar.rs +++ b/crypto/dleq/src/cross_group/scalar.rs @@ -34,9 +34,8 @@ pub fn scalar_normalize( res1 = res1.double(); res2 = res2.double(); - let mut bit = *raw_bit as u8; - debug_assert_eq!(bit | 1, 1); - *raw_bit = false; + let mut bit = u8::from(*raw_bit); + *raw_bit = 0; res1 += F0::from(bit.into()); res2 += F1::from(bit.into()); diff --git a/crypto/ed448/src/backend.rs b/crypto/ed448/src/backend.rs index a4cc5921..a46a1067 100644 --- a/crypto/ed448/src/backend.rs +++ b/crypto/ed448/src/backend.rs @@ -61,8 +61,7 @@ macro_rules! field { let mut bits = 0; for (i, bit) in other.to_le_bits().iter().rev().enumerate() { bits <<= 1; - let bit = *bit as u8; - assert_eq!(bit | 1, 1); + let bit = u8::from(*bit); bits |= bit; if ((i + 1) % 4) == 0 { diff --git a/crypto/ed448/src/point.rs b/crypto/ed448/src/point.rs index d5500a8d..3949b97a 100644 --- a/crypto/ed448/src/point.rs +++ b/crypto/ed448/src/point.rs @@ -227,8 +227,7 @@ impl Mul for Point { let mut bits = 0; for (i, bit) in other.to_le_bits().iter().rev().enumerate() { bits <<= 1; - let bit = *bit as u8; - assert_eq!(bit | 1, 1); + let bit = u8::from(*bit); bits |= bit; if ((i + 1) % 4) == 0 { @@ -320,7 +319,7 @@ fn addition_multiplication_serialization() { let mut accum = Point::identity(); for x in 1 .. 10 { accum += Point::generator(); - let mul = Point::generator() * Scalar::from(x as u8); + let mul = Point::generator() * Scalar::from(u8::try_from(x).unwrap()); assert_eq!(accum, mul); assert_eq!(Point::from_bytes(&mul.to_bytes()).unwrap(), mul); } diff --git a/crypto/frost/src/tests/literal/ed448.rs b/crypto/frost/src/tests/literal/ed448.rs index c013ebcd..218bf269 100644 --- a/crypto/frost/src/tests/literal/ed448.rs +++ b/crypto/frost/src/tests/literal/ed448.rs @@ -128,7 +128,8 @@ fn ed448_non_ietf() { "e7c423399b36a33ece81aaa75e419a9dc4387edc99682f9e4742c9b1", "a9c2392cfe30510fd33f069a42dde987544dabd7ad307a62ae1c6b13", "00" - ).to_string() + ) + .to_string(), }, ); } diff --git a/crypto/multiexp/src/lib.rs b/crypto/multiexp/src/lib.rs index bdfa1107..ac4a9c4a 100644 --- a/crypto/multiexp/src/lib.rs +++ b/crypto/multiexp/src/lib.rs @@ -31,8 +31,7 @@ where #[allow(unused_assignments)] for (i, mut raw_bit) in bits.iter_mut().enumerate() { - let mut bit = *raw_bit as u8; - debug_assert_eq!(bit | 1, 1); + let mut bit = u8::from(*raw_bit); *raw_bit = false; groupings[p][i / w_usize] |= bit << (i % w_usize);