Botan 3.7.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 278 of file point_mul.cpp.

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

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 331 of file point_mul.cpp.

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