void Montgomery_Params::square_this(BigInt& x, secure_vector<word>& ws) const { const size_t output_size = 2*m_p_words + 2; if(ws.size() < 2*output_size) ws.resize(2*output_size); word* z_data = &ws[0]; word* ws_data = &ws[output_size]; BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words); bigint_sqr(z_data, output_size, x.data(), x.size(), std::min(m_p_words, x.size()), ws_data, output_size); bigint_monty_redc(z_data, m_p.data(), m_p_words, m_p_dash, ws_data, output_size); if(x.size() < output_size) x.grow_to(output_size); copy_mem(x.mutable_data(), z_data, output_size); }
/* * Square a BigInt */ BigInt square(const BigInt& x) { const size_t x_sw = x.sig_words(); BigInt z(BigInt::Positive, round_up<size_t>(2*x_sw, 16)); SecureVector<word> workspace(z.size()); bigint_sqr(z.get_reg(), z.size(), workspace, x.data(), x.size(), x_sw); return z; }
void bigint_monty_sqr(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word p[], size_t p_size, word p_dash, word ws[]) { bigint_sqr(&z[0], z_size, &ws[0], &x[0], x_size, x_sw); bigint_monty_redc(&z[0], &p[0], p_size, p_dash, &ws[0]); }
/* * Square a BigInt */ BigInt square(const BigInt& x) { const size_t x_sw = x.sig_words(); BigInt z(BigInt::Positive, round_up(2*x_sw, 16)); secure_vector<word> workspace(z.size()); bigint_sqr(z.mutable_data(), z.size(), workspace.data(), x.data(), x.size(), x_sw); return z; }
BigInt Montgomery_Params::sqr(const BigInt& x, secure_vector<word>& ws) const { const size_t output_size = 2*m_p_words + 2; if(ws.size() < output_size) ws.resize(output_size); BigInt z(BigInt::Positive, output_size); BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words); bigint_sqr(z.mutable_data(), z.size(), x.data(), x.size(), std::min(m_p_words, x.size()), ws.data(), ws.size()); bigint_monty_redc(z.mutable_data(), m_p.data(), m_p_words, m_p_dash, ws.data(), ws.size()); return z; }