Botan 3.6.1
Crypto and TLS for C&
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 274 of file point_mul.cpp.

274 {
275 if(x.on_the_curve() == false || y.on_the_curve() == false) {
276 m_M.push_back(x.zero());
277 return;
278 }
279
280 std::vector<BigInt> ws(EC_Point::WORKSPACE_SIZE);
281
282 EC_Point x2 = x;
283 x2.mult2(ws);
284
285 const EC_Point x3(x2.plus(x, ws));
286
287 EC_Point y2 = y;
288 y2.mult2(ws);
289
290 const EC_Point y3(y2.plus(y, ws));
291
292 m_M.reserve(15);
293
294 m_M.push_back(x);
295 m_M.push_back(x2);
296 m_M.push_back(x3);
297
298 m_M.push_back(y);
299 m_M.push_back(y.plus(x, ws));
300 m_M.push_back(y.plus(x2, ws));
301 m_M.push_back(y.plus(x3, ws));
302
303 m_M.push_back(y2);
304 m_M.push_back(y2.plus(x, ws));
305 m_M.push_back(y2.plus(x2, ws));
306 m_M.push_back(y2.plus(x3, ws));
307
308 m_M.push_back(y3);
309 m_M.push_back(y3.plus(x, ws));
310 m_M.push_back(y3.plus(x2, ws));
311 m_M.push_back(y3.plus(x3, ws));
312
313 bool no_infinity = true;
314 for(auto& pt : m_M) {
315 if(pt.is_zero()) {
316 no_infinity = false;
317 }
318 }
319
320 if(no_infinity) {
321 EC_Point::force_all_affine(m_M, ws[0].get_word_vector());
322 }
323
324 m_no_infinity = no_infinity;
325}
static void force_all_affine(std::span< EC_Point > points, secure_vector< word > &ws)
Definition ec_point.cpp:387

References Botan::EC_Point::mult2(), Botan::EC_Point::on_the_curve(), Botan::EC_Point::plus(), 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 327 of file point_mul.cpp.

327 {
328 if(m_M.size() == 1) {
329 return m_M[0];
330 }
331
332 std::vector<BigInt> ws(EC_Point::WORKSPACE_SIZE);
333
334 const size_t z_bits = round_up(std::max(z1.bits(), z2.bits()), 2);
335
336 EC_Point H = m_M[0].zero();
337
338 for(size_t i = 0; i != z_bits; i += 2) {
339 if(i > 0) {
340 H.mult2i(2, ws);
341 }
342
343 const uint32_t z1_b = z1.get_substring(z_bits - i - 2, 2);
344 const uint32_t z2_b = z2.get_substring(z_bits - i - 2, 2);
345
346 const uint32_t z12 = (4 * z2_b) + z1_b;
347
348 // This function is not intended to be const time
349 if(z12) {
350 if(m_no_infinity) {
351 H.add_affine(m_M[z12 - 1], ws);
352 } else {
353 H.add(m_M[z12 - 1], ws);
354 }
355 }
356 }
357
358 if(z1.is_negative() != z2.is_negative()) {
359 H.negate();
360 }
361
362 return H;
363}
constexpr size_t round_up(size_t n, size_t align_to)
Definition rounding.h:25

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::zero().

Referenced by Botan::EC_Mul2Table_Data_BN::mul2_vartime(), Botan::EC_Mul2Table_Data_BN::mul2_vartime_x_mod_order_eq(), and Botan::multi_exponentiate().


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