Botan 3.5.0
Crypto and TLS for C&
Botan::WindowedMulTable< C, W > Class Template Referencefinal

#include <pcurves_impl.h>

Public Types

typedef C::AffinePoint AffinePoint
 
using BlindedScalar = BlindedScalarBits<C, WindowBits>
 
typedef C::ProjectivePoint ProjectivePoint
 
typedef C::Scalar Scalar
 

Public Member Functions

ProjectivePoint mul (const Scalar &s, RandomNumberGenerator &rng) const
 
 WindowedMulTable (const AffinePoint &p)
 

Static Public Attributes

static constexpr size_t TableSize = (1 << WindowBits) - 1
 
static constexpr size_t WindowBits = W
 
static constexpr size_t Windows = (BlindedScalar::Bits + WindowBits - 1) / WindowBits
 

Detailed Description

template<typename C, size_t W>
class Botan::WindowedMulTable< C, W >

Precomputed point multiplication table

This is a standard fixed window multiplication using W-bit wide window.

Definition at line 1158 of file pcurves_impl.h.

Member Typedef Documentation

◆ AffinePoint

template<typename C , size_t W>
typedef C::AffinePoint Botan::WindowedMulTable< C, W >::AffinePoint

Definition at line 1161 of file pcurves_impl.h.

◆ BlindedScalar

template<typename C , size_t W>
using Botan::WindowedMulTable< C, W >::BlindedScalar = BlindedScalarBits<C, WindowBits>

Definition at line 1167 of file pcurves_impl.h.

◆ ProjectivePoint

template<typename C , size_t W>
typedef C::ProjectivePoint Botan::WindowedMulTable< C, W >::ProjectivePoint

Definition at line 1162 of file pcurves_impl.h.

◆ Scalar

template<typename C , size_t W>
typedef C::Scalar Botan::WindowedMulTable< C, W >::Scalar

Definition at line 1160 of file pcurves_impl.h.

Constructor & Destructor Documentation

◆ WindowedMulTable()

template<typename C , size_t W>
Botan::WindowedMulTable< C, W >::WindowedMulTable ( const AffinePoint & p)
inline

Definition at line 1176 of file pcurves_impl.h.

1176 : m_table{} {
1177 std::vector<ProjectivePoint> table;
1178 table.reserve(TableSize);
1179
1180 table.push_back(ProjectivePoint::from_affine(p));
1181 for(size_t i = 1; i != TableSize; ++i) {
1182 if(i % 2 == 1) {
1183 table.push_back(table[i / 2].dbl());
1184 } else {
1185 table.push_back(table[i - 1] + table[0]);
1186 }
1187 }
1188
1189 m_table = ProjectivePoint::to_affine_batch(table);
1190 }
static constexpr size_t TableSize

References Botan::WindowedMulTable< C, W >::TableSize.

Member Function Documentation

◆ mul()

template<typename C , size_t W>
ProjectivePoint Botan::WindowedMulTable< C, W >::mul ( const Scalar & s,
RandomNumberGenerator & rng ) const
inline

Definition at line 1192 of file pcurves_impl.h.

1192 {
1193 const BlindedScalar bits(s, rng);
1194
1195 auto accum = [&]() {
1196 const size_t w_0 = bits.get_window((Windows - 1) * WindowBits);
1197 // Guaranteed because we set the high bit of the randomizer
1198 BOTAN_DEBUG_ASSERT(w_0 != 0);
1199 auto pt = ProjectivePoint::from_affine(AffinePoint::ct_select(m_table, w_0));
1200 pt.ct_poison();
1201 pt.randomize_rep(rng);
1202 return pt;
1203 }();
1204
1205 for(size_t i = 1; i != Windows; ++i) {
1206 accum = accum.dbl_n(WindowBits);
1207 const size_t w_i = bits.get_window((Windows - i - 1) * WindowBits);
1208
1209 /*
1210 This point addition cannot be a doubling (except once)
1211
1212 Consider the sequence of points that are operated on, and specifically
1213 their discrete logarithms. We start out at the point at infinity
1214 (dlog 0) and then add the initial window which is precisely P*w_0
1215
1216 We then perform WindowBits doublings, so accum's dlog at the point
1217 of the addition in the first iteration of the loop (when i == 1) is
1218 at least 2^W * w_0.
1219
1220 Since we know w_0 > 0, then in every iteration of the loop, accums
1221 dlog will always be greater than the dlog of the table element we
1222 just looked up (something between 0 and 2^W-1), and thus the
1223 addition into accum cannot be a doubling.
1224
1225 However due to blinding this argument fails, since we perform
1226 multiplications using a scalar that is larger than the group
1227 order. In this case it's possible that the dlog of accum becomes
1228 `order + x` (or, effectively, `x`) and `x` is smaller than 2^W.
1229 In this case, a doubling may occur. Future iterations of the loop
1230 cannot be doublings by the same argument above. Since the blinding
1231 factor is always less than the group order (substantially so),
1232 it is not possible for the dlog of accum to overflow a second time.
1233 */
1234 accum += AffinePoint::ct_select(m_table, w_i);
1235
1236 if(i <= 3) {
1237 accum.randomize_rep(rng);
1238 }
1239 }
1240
1241 accum.ct_unpoison();
1242 return accum;
1243 }
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:98
static constexpr size_t Windows
BlindedScalarBits< C, WindowBits > BlindedScalar
static constexpr size_t WindowBits

References BOTAN_DEBUG_ASSERT, Botan::BlindedScalarBits< C, WindowBits >::get_window(), Botan::WindowedMulTable< C, W >::WindowBits, and Botan::WindowedMulTable< C, W >::Windows.

Member Data Documentation

◆ TableSize

template<typename C , size_t W>
size_t Botan::WindowedMulTable< C, W >::TableSize = (1 << WindowBits) - 1
staticconstexpr

Definition at line 1174 of file pcurves_impl.h.

Referenced by Botan::WindowedMulTable< C, W >::WindowedMulTable().

◆ WindowBits

template<typename C , size_t W>
size_t Botan::WindowedMulTable< C, W >::WindowBits = W
staticconstexpr

Definition at line 1164 of file pcurves_impl.h.

Referenced by Botan::WindowedMulTable< C, W >::mul().

◆ Windows

template<typename C , size_t W>
size_t Botan::WindowedMulTable< C, W >::Windows = (BlindedScalar::Bits + WindowBits - 1) / WindowBits
staticconstexpr

Definition at line 1169 of file pcurves_impl.h.

Referenced by Botan::WindowedMulTable< C, W >::mul().


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