friend BigUInt operator + (const BigUInt &left, const BigUInt &right) { BigUInt result; unsigned int i; if (left.m_data.size() > right.m_data.size()) { result.resize(left.m_data.size()); for (i=0; i < right.m_data.size(); ++i) { result.m_data[i] = left.m_data[i] + right.m_data[i]; } for (; i< left.m_data.size(); ++i) { result.m_data[i] = left.m_data[i]; } } else { result.resize(right.m_data.size()); for (i=0; i < left.m_data.size(); ++i) { result.m_data[i] = left.m_data[i] + right.m_data[i]; } for (; i< right.m_data.size(); ++i) { result.m_data[i] = right.m_data[i]; } } result.normalize(); return result; }
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); }
static BigUInt multOffset(const BigUInt &left, int value, int offset) { BigUInt result; result.resize(offset + left.m_data.size()); for (unsigned int i=0; i < left.m_data.size(); ++i) { result.m_data[i+offset] = left.m_data[i] * value; } result.normalize(); return result; }
void poly_eval_uint_mod(const BigPoly &poly_to_evaluate, const BigUInt &value, const BigUInt &modulus, BigUInt &destination, const MemoryPoolHandle &pool) { if (poly_to_evaluate.significant_coeff_bit_count() > modulus.significant_bit_count()) { throw invalid_argument("poly_to_evaluate is not reduced"); } if (value.significant_bit_count() > modulus.significant_bit_count()) { throw invalid_argument("value is not reduced"); } if (!pool) { throw invalid_argument("pool is uninitialized"); } int poly_to_eval_coeff_uint64_count = poly_to_evaluate.coeff_uint64_count(); int modulus_bit_count = modulus.significant_bit_count(); if (poly_to_evaluate.is_zero()) { destination.set_zero(); } if (value.is_zero()) { destination.resize(modulus_bit_count); modulo_uint(poly_to_evaluate.data(), poly_to_eval_coeff_uint64_count, Modulus(modulus.data(), modulus.uint64_count(), pool), destination.data(), pool); return; } ConstPointer value_ptr = duplicate_uint_if_needed(value, modulus.uint64_count(), false, pool); destination.resize(modulus_bit_count); util::poly_eval_uint_mod(poly_to_evaluate.data(), poly_to_evaluate.coeff_count(), value_ptr.get(), Modulus(modulus.data(), modulus.uint64_count(), pool), destination.data(), pool); }