2
* Blinding for public key operations
3
* (C) 1999-2010,2015 Jack Lloyd
5
* Botan is released under the Simplified BSD License (see license.txt)
8
#include <botan/blinding.h>
12
Blinder::Blinder(const BigInt& modulus,
13
RandomNumberGenerator& rng,
14
std::function<BigInt (const BigInt&)> fwd,
15
std::function<BigInt (const BigInt&)> inv) :
20
m_modulus_bits(modulus.bits()),
25
const BigInt k = blinding_nonce();
30
BigInt Blinder::blinding_nonce() const
32
return BigInt(m_rng, m_modulus_bits - 1);
35
BigInt Blinder::blind(const BigInt& i) const
37
if(!m_reducer.initialized())
38
throw Exception("Blinder not initialized, cannot blind");
42
if((BOTAN_BLINDING_REINIT_INTERVAL > 0) && (m_counter > BOTAN_BLINDING_REINIT_INTERVAL))
44
const BigInt k = blinding_nonce();
51
m_e = m_reducer.square(m_e);
52
m_d = m_reducer.square(m_d);
55
return m_reducer.multiply(i, m_e);
58
BigInt Blinder::unblind(const BigInt& i) const
60
if(!m_reducer.initialized())
61
throw Exception("Blinder not initialized, cannot unblind");
63
return m_reducer.multiply(i, m_d);