Botan 3.6.0
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 270 of file point_mul.cpp.

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

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