Botan 3.6.0
Crypto and TLS for C&
Botan::EC_Point_Var_Point_Precompute Class Referencefinal

#include <point_mul.h>

Public Member Functions

 EC_Point_Var_Point_Precompute (const EC_Point &point, RandomNumberGenerator &rng, std::vector< BigInt > &ws)
 
EC_Point mul (const BigInt &k, RandomNumberGenerator &rng, const BigInt &group_order, std::vector< BigInt > &ws) const
 

Detailed Description

Definition at line 41 of file point_mul.h.

Constructor & Destructor Documentation

◆ EC_Point_Var_Point_Precompute()

Botan::EC_Point_Var_Point_Precompute::EC_Point_Var_Point_Precompute ( const EC_Point & point,
RandomNumberGenerator & rng,
std::vector< BigInt > & ws )

Definition at line 161 of file point_mul.cpp.

163 :
164 m_curve(ipoint.get_curve()), m_p_words(m_curve.get_p_words()), m_window_bits(4) {
165 if(ws.size() < EC_Point::WORKSPACE_SIZE) {
166 ws.resize(EC_Point::WORKSPACE_SIZE);
167 }
168
169 auto point = ipoint;
170 point.randomize_repr(rng);
171
172 std::vector<EC_Point> U(static_cast<size_t>(1) << m_window_bits);
173 U[0] = point.zero();
174 U[1] = point;
175
176 for(size_t i = 2; i < U.size(); i += 2) {
177 U[i] = U[i / 2].double_of(ws);
178 U[i + 1] = U[i].plus(point, ws);
179 }
180
181 // Hack to handle Blinded_Point_Multiply
182 if(rng.is_seeded()) {
183 // Skipping zero point since it can't be randomized
184 for(size_t i = 1; i != U.size(); ++i) {
185 U[i].randomize_repr(rng);
186 }
187 }
188
189 m_T.resize(U.size() * 3 * m_p_words);
190
191 word* p = &m_T[0];
192 for(size_t i = 0; i != U.size(); ++i) {
193 U[i].get_x().encode_words(p, m_p_words);
194 U[i].get_y().encode_words(p + m_p_words, m_p_words);
195 U[i].get_z().encode_words(p + 2 * m_p_words, m_p_words);
196 p += 3 * m_p_words;
197 }
198}

References Botan::RandomNumberGenerator::is_seeded(), Botan::EC_Point::randomize_repr(), and Botan::EC_Point::WORKSPACE_SIZE.

Member Function Documentation

◆ mul()

EC_Point Botan::EC_Point_Var_Point_Precompute::mul ( const BigInt & k,
RandomNumberGenerator & rng,
const BigInt & group_order,
std::vector< BigInt > & ws ) const

Definition at line 200 of file point_mul.cpp.

203 {
204 if(k.is_negative()) {
205 throw Invalid_Argument("EC_Point_Var_Point_Precompute scalar must be positive");
206 }
207 if(ws.size() < EC_Point::WORKSPACE_SIZE) {
208 ws.resize(EC_Point::WORKSPACE_SIZE);
209 }
210
211 // Choose a small mask m and use k' = k + m*order (Coron's 1st countermeasure)
212 const BigInt mask(rng, blinding_size(group_order), false);
213 const BigInt scalar = k + group_order * mask;
214
215 const size_t elem_size = 3 * m_p_words;
216 const size_t window_elems = static_cast<size_t>(1) << m_window_bits;
217
218 size_t windows = round_up(scalar.bits(), m_window_bits) / m_window_bits;
219 EC_Point R(m_curve);
220 secure_vector<word> e(elem_size);
221
222 if(windows > 0) {
223 windows--;
224
225 const uint32_t w = scalar.get_substring(windows * m_window_bits, m_window_bits);
226
227 clear_mem(e.data(), e.size());
228 for(size_t i = 1; i != window_elems; ++i) {
229 const auto wmask = CT::Mask<word>::is_equal(w, i);
230
231 for(size_t j = 0; j != elem_size; ++j) {
232 e[j] |= wmask.if_set_return(m_T[i * elem_size + j]);
233 }
234 }
235
236 R.add(&e[0], m_p_words, &e[m_p_words], m_p_words, &e[2 * m_p_words], m_p_words, ws);
237
238 /*
239 Randomize after adding the first nibble as before the addition R
240 is zero, and we cannot effectively randomize the point
241 representation of the zero point.
242 */
243 R.randomize_repr(rng, ws[0].get_word_vector());
244 }
245
246 while(windows) {
247 R.mult2i(m_window_bits, ws);
248
249 const uint32_t w = scalar.get_substring((windows - 1) * m_window_bits, m_window_bits);
250
251 clear_mem(e.data(), e.size());
252 for(size_t i = 1; i != window_elems; ++i) {
253 const auto wmask = CT::Mask<word>::is_equal(w, i);
254
255 for(size_t j = 0; j != elem_size; ++j) {
256 e[j] |= wmask.if_set_return(m_T[i * elem_size + j]);
257 }
258 }
259
260 R.add(&e[0], m_p_words, &e[m_p_words], m_p_words, &e[2 * m_p_words], m_p_words, ws);
261
262 windows--;
263 }
264
265 BOTAN_ASSERT_NOMSG(R.on_the_curve());
266
267 return R;
268}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
static constexpr Mask< T > is_equal(T x, T y)
Definition ct_utils.h:434
constexpr size_t round_up(size_t n, size_t align_to)
Definition rounding.h:25
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61
constexpr void clear_mem(T *ptr, size_t n)
Definition mem_ops.h:120

References Botan::EC_Point::add(), Botan::BigInt::bits(), BOTAN_ASSERT_NOMSG, Botan::clear_mem(), Botan::BigInt::get_substring(), Botan::BigInt::is_negative(), Botan::EC_Point::mult2i(), Botan::EC_Point::on_the_curve(), Botan::EC_Point::randomize_repr(), and Botan::round_up().


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