Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::PointGFp_Multi_Point_Precompute Class Referencefinal

#include <point_mul.h>

Public Member Functions

PointGFp multi_exp (const BigInt &k1, const BigInt &k2) const
 
 PointGFp_Multi_Point_Precompute (const PointGFp &g1, const PointGFp &g2)
 

Detailed Description

Definition at line 66 of file point_mul.h.

Constructor & Destructor Documentation

◆ PointGFp_Multi_Point_Precompute()

Botan::PointGFp_Multi_Point_Precompute::PointGFp_Multi_Point_Precompute ( const PointGFp g1,
const PointGFp g2 
)

Definition at line 320 of file point_mul.cpp.

322 {
323 if(x.on_the_curve() == false || y.on_the_curve() == false)
324 {
325 m_M.push_back(x.zero());
326 return;
327 }
328
329 std::vector<BigInt> ws(PointGFp::WORKSPACE_SIZE);
330
331 PointGFp x2 = x;
332 x2.mult2(ws);
333
334 const PointGFp x3(x2.plus(x, ws));
335
336 PointGFp y2 = y;
337 y2.mult2(ws);
338
339 const PointGFp y3(y2.plus(y, ws));
340
341 m_M.reserve(15);
342
343 m_M.push_back(x);
344 m_M.push_back(x2);
345 m_M.push_back(x3);
346
347 m_M.push_back(y);
348 m_M.push_back(y.plus(x, ws));
349 m_M.push_back(y.plus(x2, ws));
350 m_M.push_back(y.plus(x3, ws));
351
352 m_M.push_back(y2);
353 m_M.push_back(y2.plus(x, ws));
354 m_M.push_back(y2.plus(x2, ws));
355 m_M.push_back(y2.plus(x3, ws));
356
357 m_M.push_back(y3);
358 m_M.push_back(y3.plus(x, ws));
359 m_M.push_back(y3.plus(x2, ws));
360 m_M.push_back(y3.plus(x3, ws));
361
362 bool no_infinity = true;
363 for(auto& pt : m_M)
364 {
365 if(pt.is_zero())
366 no_infinity = false;
367 }
368
369 if(no_infinity)
370 {
371 PointGFp::force_all_affine(m_M, ws[0].get_word_vector());
372 }
373
374 m_no_infinity = no_infinity;
375 }
static void force_all_affine(std::vector< PointGFp > &points, secure_vector< word > &ws)
Definition: point_gfp.cpp:419

References Botan::PointGFp::force_all_affine(), Botan::PointGFp::mult2(), Botan::PointGFp::on_the_curve(), Botan::PointGFp::plus(), Botan::PointGFp::WORKSPACE_SIZE, and Botan::PointGFp::zero().

Member Function Documentation

◆ multi_exp()

PointGFp Botan::PointGFp_Multi_Point_Precompute::multi_exp ( const BigInt k1,
const BigInt k2 
) const

Definition at line 377 of file point_mul.cpp.

379 {
380 if(m_M.size() == 1)
381 return m_M[0];
382
383 std::vector<BigInt> ws(PointGFp::WORKSPACE_SIZE);
384
385 const size_t z_bits = round_up(std::max(z1.bits(), z2.bits()), 2);
386
387 PointGFp H = m_M[0].zero();
388
389 for(size_t i = 0; i != z_bits; i += 2)
390 {
391 if(i > 0)
392 {
393 H.mult2i(2, ws);
394 }
395
396 const uint32_t z1_b = z1.get_substring(z_bits - i - 2, 2);
397 const uint32_t z2_b = z2.get_substring(z_bits - i - 2, 2);
398
399 const uint32_t z12 = (4*z2_b) + z1_b;
400
401 // This function is not intended to be const time
402 if(z12)
403 {
404 if(m_no_infinity)
405 H.add_affine(m_M[z12-1], ws);
406 else
407 H.add(m_M[z12-1], ws);
408 }
409 }
410
411 if(z1.is_negative() != z2.is_negative())
412 H.negate();
413
414 return H;
415 }
size_t round_up(size_t n, size_t align_to)
Definition: rounding.h:21

References Botan::PointGFp::add(), Botan::PointGFp::add_affine(), Botan::BigInt::bits(), Botan::BigInt::get_substring(), Botan::BigInt::is_negative(), Botan::PointGFp::mult2i(), Botan::PointGFp::negate(), Botan::round_up(), and Botan::PointGFp::WORKSPACE_SIZE.

Referenced by Botan::multi_exponentiate(), and Botan::EC_Group::point_multiply().


The documentation for this class was generated from the following files: