use num_bigint::{
BigInt,
Sign,
ToBigInt,
};
use num_integer::Integer;
use num_modular::ModularUnaryOps;
use std::ops::Neg;
#[cfg_attr(docsrs, doc(cfg(feature = "bigint")))]
impl crate::BigInt for BigInt {
fn from_i64(v: i64) -> Self {
return v.into()
}
fn from_bytes_be(bytes: &[u8]) -> Self {
BigInt::from_bytes_be(Sign::Plus, bytes)
}
fn to_bytes_be(&self) -> Vec<u8> {
BigInt::to_bytes_be(self).1
}
fn gcdext(&self, y: &Self) -> (Self, Self, Self) {
let gcd = self.extended_gcd(y);
(gcd.gcd, gcd.x, gcd.y)
}
fn powm(&self, e: &Self, m: &Self) -> Self {
match e.sign() {
Sign::Plus | Sign::NoSign => self.modpow(e, m),
Sign::Minus => {
self.to_biguint().unwrap().invm(
&m.to_biguint().unwrap(),
).unwrap().to_bigint().unwrap().modpow(&e.neg(), m)
},
}
}
fn size_in_bits(&self) -> usize {
BigInt::bits(self) as usize
}
}