Botan 3.4.0
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::EC_Point_Multi_Point_Precompute Class Referencefinal

#include <point_mul.h>

Public Member Functions

 EC_Point_Multi_Point_Precompute (const EC_Point &g1, const EC_Point &g2)
 
EC_Point multi_exp (const BigInt &k1, const BigInt &k2) const
 

Detailed Description

Definition at line 64 of file point_mul.h.

Constructor & Destructor Documentation

◆ EC_Point_Multi_Point_Precompute()

Botan::EC_Point_Multi_Point_Precompute::EC_Point_Multi_Point_Precompute ( const EC_Point & g1,
const EC_Point & g2 )

Definition at line 295 of file point_mul.cpp.

295 {
296 if(x.on_the_curve() == false || y.on_the_curve() == false) {
297 m_M.push_back(x.zero());
298 return;
299 }
300
301 std::vector<BigInt> ws(EC_Point::WORKSPACE_SIZE);
302
303 EC_Point x2 = x;
304 x2.mult2(ws);
305
306 const EC_Point x3(x2.plus(x, ws));
307
308 EC_Point y2 = y;
309 y2.mult2(ws);
310
311 const EC_Point y3(y2.plus(y, ws));
312
313 m_M.reserve(15);
314
315 m_M.push_back(x);
316 m_M.push_back(x2);
317 m_M.push_back(x3);
318
319 m_M.push_back(y);
320 m_M.push_back(y.plus(x, ws));
321 m_M.push_back(y.plus(x2, ws));
322 m_M.push_back(y.plus(x3, ws));
323
324 m_M.push_back(y2);
325 m_M.push_back(y2.plus(x, ws));
326 m_M.push_back(y2.plus(x2, ws));
327 m_M.push_back(y2.plus(x3, ws));
328
329 m_M.push_back(y3);
330 m_M.push_back(y3.plus(x, ws));
331 m_M.push_back(y3.plus(x2, ws));
332 m_M.push_back(y3.plus(x3, ws));
333
334 bool no_infinity = true;
335 for(auto& pt : m_M) {
336 if(pt.is_zero()) {
337 no_infinity = false;
338 }
339 }
340
341 if(no_infinity) {
342 EC_Point::force_all_affine(m_M, ws[0].get_word_vector());
343 }
344
345 m_no_infinity = no_infinity;
346}
static void force_all_affine(std::vector< EC_Point > &points, secure_vector< word > &ws)
Definition ec_point.cpp:388

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

Member Function Documentation

◆ multi_exp()

EC_Point Botan::EC_Point_Multi_Point_Precompute::multi_exp ( const BigInt & k1,
const BigInt & k2 ) const

Definition at line 348 of file point_mul.cpp.

348 {
349 if(m_M.size() == 1) {
350 return m_M[0];
351 }
352
353 std::vector<BigInt> ws(EC_Point::WORKSPACE_SIZE);
354
355 const size_t z_bits = round_up(std::max(z1.bits(), z2.bits()), 2);
356
357 EC_Point H = m_M[0].zero();
358
359 for(size_t i = 0; i != z_bits; i += 2) {
360 if(i > 0) {
361 H.mult2i(2, ws);
362 }
363
364 const uint32_t z1_b = z1.get_substring(z_bits - i - 2, 2);
365 const uint32_t z2_b = z2.get_substring(z_bits - i - 2, 2);
366
367 const uint32_t z12 = (4 * z2_b) + z1_b;
368
369 // This function is not intended to be const time
370 if(z12) {
371 if(m_no_infinity) {
372 H.add_affine(m_M[z12 - 1], ws);
373 } else {
374 H.add(m_M[z12 - 1], ws);
375 }
376 }
377 }
378
379 if(z1.is_negative() != z2.is_negative()) {
380 H.negate();
381 }
382
383 return H;
384}
size_t round_up(size_t n, size_t align_to)
Definition rounding.h:21

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

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


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