Exemplo n.º 1
0
    void exponentiate_uint_mod(const BigUInt &operand, const BigUInt &exponent, 
        const BigUInt &modulus, BigUInt &destination, const MemoryPoolHandle &pool)
    {
        if (operand.significant_bit_count() > modulus.significant_bit_count())
        {
            throw invalid_argument("operand is not reduced");
        }
        if (operand.is_zero() && exponent == 0)
        {
            throw invalid_argument("undefined operation");
        }
        if (!pool)
        {
            throw invalid_argument("pool is uninitialized");
        }

        if (operand.is_zero())
        {
            destination.set_zero();
            return;
        }

        if (destination.bit_count() != modulus.significant_bit_count())
        {
            destination.resize(modulus.significant_bit_count());
        }

        ConstPointer operand_ptr = duplicate_uint_if_needed(operand, modulus.uint64_count(), false, pool);
        util::exponentiate_uint_mod(operand_ptr.get(), exponent.data(), exponent.uint64_count(), Modulus(modulus.data(), modulus.uint64_count(), pool), destination.data(), pool);
    }
Exemplo n.º 2
0
 BigUInt BigUInt::operator -(const BigUInt& operand2) const
 {
     int result_bits = max(bit_count_, operand2.bit_count());
     BigUInt result(result_bits);
     sub_uint_uint(value_, uint64_count(), operand2.pointer(), operand2.uint64_count(), false, result.uint64_count(), result.pointer());
     filter_highbits_uint(result.pointer(), result.uint64_count(), result_bits);
     return result;
 }
Exemplo n.º 3
0
 BigUInt BigUInt::operator |(const BigUInt& operand2) const
 {
     int result_bits = max(bit_count_, operand2.bit_count());
     BigUInt result(result_bits);
     int uint64_count = result.uint64_count();
     if (uint64_count != this->uint64_count())
     {
         result = *this;
         or_uint_uint(result.pointer(), operand2.pointer(), uint64_count, result.pointer());
     }
     else if (uint64_count != operand2.uint64_count())
     {
         result = operand2;
         or_uint_uint(result.pointer(), value_, uint64_count, result.pointer());
     }
     else
     {
         or_uint_uint(value_, operand2.pointer(), uint64_count, result.pointer());
     }
     return result;
 }
Exemplo n.º 4
0
 BigUInt::BigUInt(const BigUInt& copy) : value_(nullptr), bit_count_(0), is_alias_(false)
 {
     resize(copy.bit_count());
     operator =(copy);
 }