31 #ifndef _SCC_CRYPTO_BIGNUM_H
32 #define _SCC_CRYPTO_BIGNUM_H
40 namespace scc::crypto {
60 std::unique_ptr<BignumCtx> m_bnctx;
127 void set(
const void *,
int);
146 void get(
void *,
int)
const;
276 for (
int i = 0; i <
width(); i++)
291 for (
int i = 0; i < std::max(
width(), b.
width()); i++)
306 for (
int i = 0; i < std::max(
width(), b.
width()); i++)
321 for (
int i = 0; i < std::max(
width(), b.
width()); i++)
369 return bn.is_prime();
376 int cmp(uint32_t w)
const;
690 std::string
str(
bool=
false)
const;
697 void PrintTo(
const Bignum&, std::ostream*);
scc::crypto::Bignum exp(const scc::crypto::Bignum &, const scc::crypto::Bignum &)
Exponent helper.
scc::crypto::Bignum gcd(const scc::crypto::Bignum &, const scc::crypto::Bignum &)
Greatest common divisor helper.
std::ostream & operator<<(std::ostream &, const scc::crypto::Bignum &)
Print the bignum to a stream.
Bignum operator^(const Bignum &a) const
Xor operator.
bool is_bit_set(int) const
Is the bit set?
void sub(const Bignum &)
Subtract a-b.
void exp(uint32_t b)
Exponent a^b.
void get(void *, int) const
Octal (byte) output of a positive number.
void div(uint32_t b, Bignum *rem)
Divide a/b.
Bignum operator^=(const Bignum &a)
Xor assign operator.
Bignum operator-=(const Bignum &a)
Subtract assign operator.
const void * const_bn() const
Bignum context for use by external services.
void mul(uint32_t b)
Word multiply.
void set_2sc(const void *, int)
Set integer from twos complement input stream.
void mod(const Bignum &)
Modulus ab.
std::string str(bool=false) const
Return a string representation in decimal or hex.
void lshift(int)
Left bit shift.
Bignum & operator<<=(int shift)
Right shift assign operator.
void set_width(int)
Set the number to a specified bit width.
bool operator>=(const Bignum &o) const
Greater than equal operator.
int cmp(uint32_t w) const
Arithmetic compare for an integer.
void move(Bignum &)
Move into this bignum.
void exp(const Bignum &)
Exponent a^b.
Bignum operator%(const Bignum &a) const
Modulus operator.
void bit_xor(const Bignum &b)
Bitwise xor a^b.
void * bn()
Bignum context for use by external services.
Bignum operator*(const Bignum &a) const
Multiply operator.
void clear_bit(int)
Clear a bit.
Bignum & operator++()
Prefix addition operator.
void set(uint32_t)
Set to a word.
void gcd(const Bignum &)
Greatest common divisor for a and b.
void negate()
Negate (change sign).
Bignum(uint32_t w)
Word constructor.
Bignum & operator=(Bignum &&other)
Move assignment.
int len() const
Required length of get() output in bytes.
void set_bit(int)
Set a bit.
void copy(const Bignum &)
Copy into this bignum.
Bignum operator<<(int shift) const
Right shift operator.
Bignum()
Construct and set to 0.
void get_2sc(void *, int) const
Octal (byte) output, in two's complement form.
void mul(const Bignum &)
Mulitply a*b.
Bignum & operator--()
Prefix decrement.
static bool is_prime(uint32_t w)
Is prime for an integer.
int width() const
Number of significant bits.
void mod(uint32_t b)
Word modulus.
int len_2sc() const
Get the length of octal output in twos complement form.
void clear()
Clear and set to 0.
Bignum & operator>>=(int shift)
Right shift assign operator.
void add(const Bignum &)
Add a+b.
Bignum operator*=(const Bignum &a)
Multiply assign operator.
Bignum operator/(const Bignum &a) const
Divide operator.
Bignum operator&=(const Bignum &a)
And assign operator.
void gcd(uint32_t b)
Greatest common divisor of a and b.
Bignum operator/=(const Bignum &a)
Divide assign operator.
void div(const Bignum &, Bignum *)
Divide a/b.
bool operator<=(const Bignum &o) const
Less than equal operator.
Bignum operator|=(const Bignum &a)
Or assign operator.
Bignum operator>>(int shift) const
Right shift operator.
Bignum operator~() const
Not operator.
void gen_prime(int)
Generate a random pseudo-prime number of the specified bit width.
Bignum operator|(const Bignum &a) const
Or operator.
bool is_prime(int=-1)
Perform a Miller-Rabin prime test to test primality.
bool operator==(const Bignum &o) const
Equal operator.
void gen_rand(int, bool=false, bool=false)
Generate a random number of the specified bit width.
void bit_and(const Bignum &b)
Bitwise not a&b.
Bignum(const Bignum &other)
Copy constructor.
Bignum operator+(const Bignum &a) const
Add operator.
bool operator!=(const Bignum &o) const
Not equal operator.
void sub(uint32_t b)
Subtract an integer.
void set(const void *, int)
Set a positive integer from input bytes.
Bignum(Bignum &&other)
Move constructor.
Bignum operator&(const Bignum &a) const
And operator.
void add(uint32_t b)
Word add a+b.
void bit_or(const Bignum &b)
Bitwise or a|b.
int cmp(const Bignum &) const
Arithmetic compare.
bool operator>(const Bignum &o) const
Greater than operator.
bool is_negative() const
Is negative?
Bignum(const void *loc, int len)
Set to data.
bool operator<(const Bignum &o) const
Less than operator.
Bignum operator%=(const Bignum &a)
Modulus assign operator.
void rshift(int)
Right bit shift.
void bit_not()
Bitwise not ~a.
Bignum operator-()
Negation operator -a.
Bignum operator+=(const Bignum &a)
Add assign operator.