Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/bigint/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,10 @@ pub(super) fn from_signed_bytes_be(digits: &[u8]) -> BigInt {

if sign == Sign::Minus {
// two's-complement the content to retrieve the magnitude
let mut digits = Vec::from(digits);
twos_complement_be(&mut digits);
BigInt::from_biguint(sign, BigUint::from_bytes_be(&*digits))
let mut digits = digits.to_vec();
digits.reverse();
twos_complement_le(&mut digits);
BigInt::from_biguint(sign, BigUint::from_bytes_le(&digits))
} else {
BigInt::from_biguint(sign, BigUint::from_bytes_be(digits))
}
Expand All @@ -395,9 +396,9 @@ pub(super) fn from_signed_bytes_le(digits: &[u8]) -> BigInt {

if sign == Sign::Minus {
// two's-complement the content to retrieve the magnitude
let mut digits = Vec::from(digits);
let mut digits = digits.to_vec();
twos_complement_le(&mut digits);
BigInt::from_biguint(sign, BigUint::from_bytes_le(&*digits))
BigInt::from_biguint(sign, BigUint::from_bytes_le(&digits))
} else {
BigInt::from_biguint(sign, BigUint::from_bytes_le(digits))
}
Expand Down Expand Up @@ -460,10 +461,8 @@ where
{
let mut carry = true;
for d in digits {
*d = !*d;
if carry {
*d = d.wrapping_add(1);
carry = d.is_zero();
}
let (val, tmp_carry) = (!*d).overflowing_add(carry as u8);
*d = val;
carry = tmp_carry;
}
}