Botan 3.5.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 267 of file point_mul.cpp.

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

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

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

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


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