pub trait BigInt: Clone + Sized + Send + Sync + Eq + PartialOrd + Neg + Add<Output = Self> + Sub<Output = Self> + Mul<Output = Self> + Rem<Output = Self> + MulAssign + DivAssign {
// Required methods
fn from_i64(v: i64) -> Self;
fn from_bytes_be(bytes: &[u8]) -> Self;
fn to_bytes_be(&self) -> Vec<u8>;
fn gcdext<'a>(&self, y: &'a Self) -> (Self, Self, Self);
fn powm<'a>(&self, e: &'a Self, m: &Self) -> Self;
fn next_prime(&self) -> Self;
fn size_in_bits(&self) -> usize;
}Expand description
A trait describing an arbitrary precision integer.
Required Methods§
sourcefn from_bytes_be(bytes: &[u8]) -> Self
fn from_bytes_be(bytes: &[u8]) -> Self
Constructs a BigInt from a slice of bytes, with the most
significant byte first.
sourcefn to_bytes_be(&self) -> Vec<u8>
fn to_bytes_be(&self) -> Vec<u8>
Constructs a byte vector of the BigInt with the most significant
byte first.
sourcefn gcdext<'a>(&self, y: &'a Self) -> (Self, Self, Self)
fn gcdext<'a>(&self, y: &'a Self) -> (Self, Self, Self)
Returns (g, a, b) where g is the greatest common divisor of self
and y satisfying g = a * self + b * y.
sourcefn next_prime(&self) -> Self
fn next_prime(&self) -> Self
Returns the next prime greater than self.
sourcefn size_in_bits(&self) -> usize
fn size_in_bits(&self) -> usize
Returns the size of self in bits.
Implementations on Foreign Types§
source§impl BigInt for BigInt
Available on crate feature bigint only.
impl BigInt for BigInt
Available on crate feature
bigint only.source§fn from_i64(v: i64) -> Self
fn from_i64(v: i64) -> Self
use num_bigint::BigInt;
let x: BigInt = <BigInt as clacc::BigInt>::from_i64(256);
let y: BigInt = 256.into();
assert_eq!(x, y);source§fn from_bytes_be(bytes: &[u8]) -> Self
fn from_bytes_be(bytes: &[u8]) -> Self
use num_bigint::BigInt;
let x: BigInt = <BigInt as clacc::BigInt>::from_bytes_be(
vec![0x01, 0x00].as_slice(),
);
let y: BigInt = 256.into();
assert_eq!(x, y);source§fn to_bytes_be(&self) -> Vec<u8>
fn to_bytes_be(&self) -> Vec<u8>
use num_bigint::BigInt;
let x = vec![0x01, 0x00];
let y: BigInt = 256.into();
assert_eq!(x, <BigInt as clacc::BigInt>::to_bytes_be(&y));source§fn gcdext(&self, y: &Self) -> (Self, Self, Self)
fn gcdext(&self, y: &Self) -> (Self, Self, Self)
use num_bigint::BigInt;
let x: BigInt = 240.into();
let y: BigInt = 46.into();
let (g, a, b) = <BigInt as clacc::BigInt>::gcdext(&x, &y);
assert_eq!(g, 2.into());
assert_eq!(a, (-9).into());
assert_eq!(b, 47.into());source§fn powm(&self, e: &Self, m: &Self) -> Self
fn powm(&self, e: &Self, m: &Self) -> Self
use num_bigint::BigInt;
let b: BigInt = 5.into();
let e: BigInt = 3.into();
let m: BigInt = 13.into();
let c = <BigInt as clacc::BigInt>::powm(&b, &e, &m);
assert_eq!(c, 8.into());use num_bigint::BigInt;
let b: BigInt = 3.into();
let e: BigInt = (-1).into();
let m: BigInt = 11.into();
let c = <BigInt as clacc::BigInt>::powm(&b, &e, &m);
assert_eq!(c, 4.into());source§fn next_prime(&self) -> Self
fn next_prime(&self) -> Self
use num_bigint::BigInt;
let x: BigInt = 32.into();
let p = <BigInt as clacc::BigInt>::next_prime(&x);
assert_eq!(p, 37.into());source§fn size_in_bits(&self) -> usize
fn size_in_bits(&self) -> usize
use num_bigint::BigInt;
let a: BigInt = 3.into();
assert_eq!(<BigInt as clacc::BigInt>::size_in_bits(&a), 2);
let b: BigInt = 256.into();
assert_eq!(<BigInt as clacc::BigInt>::size_in_bits(&b), 9);source§impl BigInt for Mpz
Available on crate feature gmp only.
impl BigInt for Mpz
Available on crate feature
gmp only.source§fn from_i64(v: i64) -> Self
fn from_i64(v: i64) -> Self
use gmp::mpz::Mpz;
let x: Mpz = <Mpz as clacc::BigInt>::from_i64(256);
let y: Mpz = 256.into();
assert_eq!(x, y);source§fn from_bytes_be(bytes: &[u8]) -> Self
fn from_bytes_be(bytes: &[u8]) -> Self
use gmp::mpz::Mpz;
let x: Mpz = <Mpz as clacc::BigInt>::from_bytes_be(
vec![0x01, 0x00].as_slice(),
);
let y: Mpz = 256.into();
assert_eq!(x, y);source§fn to_bytes_be(&self) -> Vec<u8>
fn to_bytes_be(&self) -> Vec<u8>
use gmp::mpz::Mpz;
let x = vec![0x01, 0x00];
let y: Mpz = 256.into();
assert_eq!(x, <Mpz as clacc::BigInt>::to_bytes_be(&y));source§fn gcdext(&self, y: &Self) -> (Self, Self, Self)
fn gcdext(&self, y: &Self) -> (Self, Self, Self)
use gmp::mpz::Mpz;
let x: Mpz = 240.into();
let y: Mpz = 46.into();
let (g, a, b) = <Mpz as clacc::BigInt>::gcdext(&x, &y);
assert_eq!(g, 2.into());
assert_eq!(a, (-9).into());
assert_eq!(b, 47.into());source§fn powm(&self, e: &Self, m: &Self) -> Self
fn powm(&self, e: &Self, m: &Self) -> Self
use gmp::mpz::Mpz;
let b: Mpz = 5.into();
let e: Mpz = 3.into();
let m: Mpz = 13.into();
let c = <Mpz as clacc::BigInt>::powm(&b, &e, &m);
assert_eq!(c, 8.into());source§fn next_prime(&self) -> Self
fn next_prime(&self) -> Self
use gmp::mpz::Mpz;
let x: Mpz = 32.into();
let p = <Mpz as clacc::BigInt>::next_prime(&x);
assert_eq!(p, 37.into());source§fn size_in_bits(&self) -> usize
fn size_in_bits(&self) -> usize
use gmp::mpz::Mpz;
let a: Mpz = 3.into();
assert_eq!(<Mpz as clacc::BigInt>::size_in_bits(&a), 2);
let b: Mpz = 256.into();
assert_eq!(<Mpz as clacc::BigInt>::size_in_bits(&b), 9);