Botan 3.9.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 281 of file point_mul.cpp.

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

References EC_Point_Multi_Point_Precompute(), 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().

Referenced by EC_Point_Multi_Point_Precompute().

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

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

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(), multi_exp(), Botan::EC_Point::negate(), Botan::round_up(), Botan::EC_Point::WORKSPACE_SIZE, and Botan::EC_Point::zero().

Referenced by multi_exp(), and Botan::multi_exponentiate().


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