本文整理汇总了C++中BigInt::bits方法的典型用法代码示例。如果您正苦于以下问题:C++ BigInt::bits方法的具体用法?C++ BigInt::bits怎么用?C++ BigInt::bits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigInt
的用法示例。
在下文中一共展示了BigInt::bits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: multi_exponentiate
PointGFp multi_exponentiate(const PointGFp& p1, const BigInt& z1,
const PointGFp& p2, const BigInt& z2)
{
const PointGFp p3 = p1 + p2;
PointGFp H(p1.curve); // create as zero
size_t bits_left = std::max(z1.bits(), z2.bits());
std::vector<BigInt> ws(9);
while(bits_left)
{
H.mult2(ws);
const bool z1_b = z1.get_bit(bits_left - 1);
const bool z2_b = z2.get_bit(bits_left - 1);
if(z1_b == true && z2_b == true)
H.add(p3, ws);
else if(z1_b)
H.add(p1, ws);
else if(z2_b)
H.add(p2, ws);
--bits_left;
}
if(z1.is_negative() != z2.is_negative())
H.negate();
return H;
}
开发者ID:BenjaminSchiborr,项目名称:safe,代码行数:32,代码来源:point_gfp.cpp示例2: multi_exponentiate
PointGFp multi_exponentiate(const PointGFp& x, const BigInt& z1,
const PointGFp& y, const BigInt& z2)
{
const size_t z_bits = round_up(std::max(z1.bits(), z2.bits()), 2);
std::vector<BigInt> ws(PointGFp::WORKSPACE_SIZE);
PointGFp x2 = x;
x2.mult2(ws);
const PointGFp x3(x2.plus(x, ws));
PointGFp y2 = y;
y2.mult2(ws);
const PointGFp y3(y2.plus(y, ws));
const PointGFp M[16] = {
x.zero(), // 0000
x, // 0001
x2, // 0010
x3, // 0011
y, // 0100
y.plus(x, ws), // 0101
y.plus(x2, ws), // 0110
y.plus(x3, ws), // 0111
y2, // 1000
y2.plus(x, ws), // 1001
y2.plus(x2, ws), // 1010
y2.plus(x3, ws), // 1011
y3, // 1100
y3.plus(x, ws), // 1101
y3.plus(x2, ws), // 1110
y3.plus(x3, ws), // 1111
};
PointGFp H = x.zero();
for(size_t i = 0; i != z_bits; i += 2)
{
if(i > 0)
{
H.mult2(ws);
H.mult2(ws);
}
const uint8_t z1_b = z1.get_substring(z_bits - i - 2, 2);
const uint8_t z2_b = z2.get_substring(z_bits - i - 2, 2);
const uint8_t z12 = (4*z2_b) + z1_b;
H.add(M[z12], ws);
}
if(z1.is_negative() != z2.is_negative())
H.negate();
return H;
}
开发者ID:noloader,项目名称:botan,代码行数:59,代码来源:point_gfp.cpp示例3: exponentiation
BigInt Montgomery_Exponentation_State::exponentiation(const BigInt& scalar) const
{
const size_t exp_nibbles = (scalar.bits() + m_window_bits - 1) / m_window_bits;
Montgomery_Int x(m_params, m_params->R1(), false);
secure_vector<word> e_bits(m_params->p_words());
secure_vector<word> ws;
for(size_t i = exp_nibbles; i > 0; --i)
{
for(size_t j = 0; j != m_window_bits; ++j)
{
x.square_this(ws);
}
const uint32_t nibble = scalar.get_substring(m_window_bits*(i-1), m_window_bits);
const_time_lookup(e_bits, m_g, nibble);
x.mul_by(e_bits, ws);
}
return x.value();
}
开发者ID:binary1248,项目名称:SFNUL,代码行数:25,代码来源:monty_exp.cpp示例4: return
/*
* Division Operator
*/
BigInt operator/(const BigInt& x, const BigInt& y)
{
if(y.sig_words() == 1 && is_power_of_2(y.word_at(0)))
return (x >> (y.bits() - 1));
BigInt q, r;
divide(x, y, q, r);
return q;
}
开发者ID:evpo,项目名称:EncryptPad,代码行数:12,代码来源:big_ops3.cpp示例5: random_integer
/*
* Generate a random integer within given range
*/
BigInt BigInt::random_integer(RandomNumberGenerator& rng,
const BigInt& min, const BigInt& max)
{
BigInt range = max - min;
if(range <= 0)
throw Invalid_Argument("random_integer: invalid min/max values");
return (min + (BigInt(rng, range.bits() + 2) % range));
}
开发者ID:AlexNk,项目名称:botan,代码行数:13,代码来源:big_rand.cpp示例6: set_base
/*
* Set the base
*/
void Fixed_Window_Exponentiator::set_base(const BigInt& base)
{
m_window_bits = Power_Mod::window_bits(m_exp.bits(), base.bits(), m_hints);
m_g.resize(1U << m_window_bits);
m_g[0] = 1;
m_g[1] = base;
for(size_t i = 2; i != m_g.size(); ++i)
m_g[i] = m_reducer.multiply(m_g[i-1], m_g[1]);
}
开发者ID:Hackmanit,项目名称:botan,代码行数:14,代码来源:powm_fw.cpp示例7: k
/*************************************************
* IF_Core Constructor *
*************************************************/
IF_Core::IF_Core(RandomNumberGenerator& rng,
const BigInt& e, const BigInt& n, const BigInt& d,
const BigInt& p, const BigInt& q,
const BigInt& d1, const BigInt& d2, const BigInt& c)
{
op = Engine_Core::if_op(e, n, d, p, q, d1, d2, c);
if(BLINDING_BITS)
{
BigInt k(rng, std::min(n.bits()-1, BLINDING_BITS));
blinder = Blinder(power_mod(k, e, n), inverse_mod(k, n), n);
}
}
开发者ID:graydon,项目名称:monotone,代码行数:16,代码来源:pk_core.cpp示例8: random_integer
/*
* Generate a random integer within given range
*/
BigInt BigInt::random_integer(RandomNumberGenerator& rng,
const BigInt& min, const BigInt& max)
{
BigInt r;
const size_t bits = max.bits();
do
{
r.randomize(rng, bits, false);
}
while(r < min || r >= max);
return r;
}
开发者ID:fxdupont,项目名称:botan,代码行数:18,代码来源:big_rand.cpp示例9: encrypt_number
u64bit encrypt_number(u64bit cc_number, int length,
const std::string& key_str,
const std::string& tweak){
BigInt n = 1;
for(int j=0; j<length; ++j){
n = n * 10;
}
u64bit cc_ranked = cc_rank(cc_number);
SymmetricKey key = sha1(key_str);
BigInt c = FPE::fe1_encrypt(n, cc_ranked, key, sha1(tweak));
if(c.bits() > 50)
throw std::runtime_error("FPE produced a number too large");
u64bit enc_cc = 0;
for(u32bit i = 0; i != 7; ++i)
enc_cc = (enc_cc << 8) | c.byte_at(6-i);
return cc_derank(enc_cc);
}
开发者ID:devsunny,项目名称:common-tools,代码行数:17,代码来源:botan_fpe.cpp示例10: exponentiation
BigInt Montgomery_Exponentation_State::exponentiation(const BigInt& k) const
{
const size_t exp_nibbles = (k.bits() + m_window_bits - 1) / m_window_bits;
BigInt x = m_R_mod;
const size_t z_size = 2*(m_p_words + 1);
BigInt z(BigInt::Positive, z_size);
secure_vector<word> workspace(z.size());
secure_vector<word> e(m_p_words);
for(size_t i = exp_nibbles; i > 0; --i)
{
for(size_t j = 0; j != m_window_bits; ++j)
{
bigint_monty_sqr(z, x, m_p.data(), m_p_words, m_mod_prime,
workspace.data());
x = z;
}
const uint32_t nibble = k.get_substring(m_window_bits*(i-1), m_window_bits);
BigInt::const_time_lookup(e, m_g, nibble);
bigint_mul(z.mutable_data(), z.size(),
x.data(), x.size(), x.sig_words(),
e.data(), m_p_words, m_p_words,
workspace.data());
bigint_monty_redc(z.mutable_data(),
m_p.data(), m_p_words, m_mod_prime,
workspace.data());
x = z;
}
x.grow_to(2*m_p_words + 1);
bigint_monty_redc(x.mutable_data(),
m_p.data(), m_p_words, m_mod_prime,
workspace.data());
return x;
}
开发者ID:noloader,项目名称:botan,代码行数:46,代码来源:monty_exp.cpp示例11:
Blinder::Blinder(const BigInt& modulus,
RandomNumberGenerator& rng,
std::function<BigInt (const BigInt&)> fwd,
std::function<BigInt (const BigInt&)> inv) :
m_reducer(modulus),
m_rng(rng),
m_fwd_fn(fwd),
m_inv_fn(inv),
m_modulus_bits(modulus.bits()),
m_e{},
m_d{},
m_counter{}
{
const BigInt k = blinding_nonce();
m_e = m_fwd_fn(k);
m_d = m_inv_fn(k);
}
开发者ID:fxdupont,项目名称:botan,代码行数:17,代码来源:blinding.cpp示例12: k
Blinder::Blinder(const BigInt& modulus,
std::function<BigInt (const BigInt&)> fwd_func,
std::function<BigInt (const BigInt&)> inv_func)
{
m_reducer = Modular_Reducer(modulus);
#if defined(BOTAN_HAS_SYSTEM_RNG)
auto& rng = system_rng();
#else
AutoSeeded_RNG rng;
#endif
const BigInt k(rng, modulus.bits() - 1);
m_e = fwd_func(k);
m_d = inv_func(k);
}
开发者ID:AlexNk,项目名称:botan,代码行数:17,代码来源:blinding.cpp示例13: zero_of
PointGFp operator*(const BigInt& scalar, const PointGFp& point)
{
//BOTAN_ASSERT(point.on_the_curve(), "Input is on the curve");
const CurveGFp& curve = point.get_curve();
const size_t scalar_bits = scalar.bits();
std::vector<BigInt> ws(9);
if(scalar_bits <= 2)
{
const byte abs_val = scalar.byte_at(0);
if(abs_val == 0)
return PointGFp::zero_of(curve);
PointGFp result = point;
if(abs_val == 2)
result.mult2(ws);
if(scalar.is_negative())
result.negate();
return result;
}
PointGFp R[2] = { PointGFp(curve), point };
for(size_t i = scalar_bits; i > 0; i--)
{
const size_t b = scalar.get_bit(i - 1);
R[b ^ 1].add(R[b], ws);
R[b].mult2(ws);
}
if(scalar.is_negative())
R[0].negate();
//BOTAN_ASSERT(R[0].on_the_curve(), "Output is on the curve");
return R[0];
}
开发者ID:Jesse-V,项目名称:botan,代码行数:44,代码来源:point_gfp.cpp示例14: set_base
/*
* Set the base
*/
void Montgomery_Exponentiator::set_base(const BigInt& base)
{
m_window_bits = Power_Mod::window_bits(m_exp.bits(), base.bits(), m_hints);
m_g.resize((1 << m_window_bits));
BigInt z(BigInt::Positive, 2 * (m_mod_words + 1));
secure_vector<word> workspace(z.size());
m_g[0] = 1;
bigint_monty_mul(z, m_g[0], m_R2_mod,
m_modulus.data(), m_mod_words, m_mod_prime,
workspace.data());
m_g[0] = z;
m_g[1] = (base >= m_modulus) ? (base % m_modulus) : base;
bigint_monty_mul(z, m_g[1], m_R2_mod,
m_modulus.data(), m_mod_words, m_mod_prime,
workspace.data());
m_g[1] = z;
const BigInt& x = m_g[1];
for(size_t i = 2; i != m_g.size(); ++i)
{
const BigInt& y = m_g[i-1];
bigint_monty_mul(z, x, y, m_modulus.data(), m_mod_words, m_mod_prime,
workspace.data());
m_g[i] = z;
}
}
开发者ID:jurajsomorovsky,项目名称:botan,代码行数:39,代码来源:powm_mnt.cpp示例15: PointGFp
PointGFp operator*(const BigInt& scalar, const PointGFp& point)
{
const CurveGFp& curve = point.get_curve();
if(scalar.is_zero())
return PointGFp(curve); // zero point
std::vector<BigInt> ws(9);
if(scalar.abs() <= 2) // special cases for small values
{
byte value = scalar.abs().byte_at(0);
PointGFp result = point;
if(value == 2)
result.mult2(ws);
if(scalar.is_negative())
result.negate();
return result;
}
const size_t scalar_bits = scalar.bits();
#if 0
PointGFp x1 = PointGFp(curve);
PointGFp x2 = point;
size_t bits_left = scalar_bits;
// Montgomery Ladder
while(bits_left)
{
const bool bit_set = scalar.get_bit(bits_left - 1);
if(bit_set)
{
x1.add(x2, ws);
x2.mult2(ws);
}
else
{
x2.add(x1, ws);
x1.mult2(ws);
}
--bits_left;
}
if(scalar.is_negative())
x1.negate();
return x1;
#else
const size_t window_size = 4;
std::vector<PointGFp> Ps(1 << window_size);
Ps[0] = PointGFp(curve);
Ps[1] = point;
for(size_t i = 2; i != Ps.size(); ++i)
{
Ps[i] = Ps[i-1];
Ps[i].add(point, ws);
}
PointGFp H(curve); // create as zero
size_t bits_left = scalar_bits;
while(bits_left >= window_size)
{
for(size_t i = 0; i != window_size; ++i)
H.mult2(ws);
const u32bit nibble = scalar.get_substring(bits_left - window_size,
window_size);
H.add(Ps[nibble], ws);
bits_left -= window_size;
}
while(bits_left)
{
H.mult2(ws);
if(scalar.get_bit(bits_left-1))
H.add(point, ws);
--bits_left;
}
if(scalar.is_negative())
H.negate();
return H;
#endif
//.........这里部分代码省略.........
开发者ID:BenjaminSchiborr,项目名称:safe,代码行数:101,代码来源:point_gfp.cpp本文标签属性:
示例:示例英文
代码:代码大全可复制