Botan 3.11.0
Crypto and TLS for C&
Botan::BlindedScalarBits< C, WindowBits > Class Template Referencefinal

#include <pcurves_impl.h>

Public Member Functions

size_t bits () const
 BlindedScalarBits (BlindedScalarBits &&other)=delete
 BlindedScalarBits (const BlindedScalarBits &other)=delete
 BlindedScalarBits (const typename C::Scalar &scalar, RandomNumberGenerator &rng)
size_t get_window (size_t offset) const
BlindedScalarBitsoperator= (BlindedScalarBits &&other)=delete
BlindedScalarBitsoperator= (const BlindedScalarBits &other)=delete
 ~BlindedScalarBits ()

Static Public Attributes

static constexpr size_t Bits = C::Scalar::BITS + BlindingBits

Detailed Description

template<typename C, size_t WindowBits>
class Botan::BlindedScalarBits< C, WindowBits >

Blinded Scalar

This randomizes the scalar representation by computing s + n*k, where n is the group order and k is a random value

Note that the field arithmetic and point multiplication algorithms implemented in this file are already constant time; blinding is used here as an additional precaution to guard against compilers introducing conditional jumps where not expected.

If the provided RNG is not seeded, blinding is skipped and the scalar is used directly. This allows blinding to be disabled at runtime.

Definition at line 1293 of file pcurves_impl.h.

Constructor & Destructor Documentation

◆ BlindedScalarBits() [1/3]

template<typename C, size_t WindowBits>
Botan::BlindedScalarBits< C, WindowBits >::BlindedScalarBits ( const typename C::Scalar & scalar,
RandomNumberGenerator & rng )
inline

Definition at line 1307 of file pcurves_impl.h.

1307 {
1308 if(BlindingBits > 0 && rng.is_seeded()) {
1309 constexpr size_t MaskWords = (BlindingBits + WordInfo<W>::bits - 1) / WordInfo<W>::bits;
1310 constexpr size_t MaskBytes = MaskWords * WordInfo<W>::bytes;
1311
1312 constexpr size_t n_words = C::Words;
1313
1314 uint8_t maskb[MaskBytes + (BlindingBits == 0 ? 1 : 0)] = {0};
1315 rng.randomize(maskb, MaskBytes);
1316
1317 W mask[n_words] = {0};
1319
1320 // Mask to exactly BlindingBits
1321 constexpr size_t ExcessBits = MaskWords * WordInfo<W>::bits - BlindingBits;
1322 if constexpr(ExcessBits > 0) {
1323 constexpr W ExcessMask = (static_cast<W>(1) << (WordInfo<W>::bits - ExcessBits)) - 1;
1324 mask[MaskWords - 1] &= ExcessMask;
1325 }
1326
1327 // Set top and bottom bits of mask
1328 constexpr size_t TopMaskBit = (BlindingBits - 1) % WordInfo<W>::bits;
1329 mask[(BlindingBits - 1) / WordInfo<W>::bits] |= static_cast<W>(1) << TopMaskBit;
1330 mask[0] |= 1;
1331
1332 W mask_n[2 * n_words] = {0};
1333
1334 const auto sw = scalar.to_words();
1335
1336 // Compute masked scalar s + k*n
1338 bigint_add2(mask_n, 2 * n_words, sw.data(), sw.size());
1339
1342 m_bits = C::Scalar::BITS + BlindingBits;
1343 } else {
1344 // No RNG available, skip blinding
1345 m_bytes.resize(C::Scalar::BYTES);
1346 scalar.serialize_to(std::span{m_bytes}.template first<C::Scalar::BYTES>());
1347 m_bits = C::Scalar::BITS;
1348 }
1349
1350 CT::poison(m_bytes.data(), m_bytes.size());
1351 }
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:56
constexpr auto bigint_add2(W x[], size_t x_size, const W y[], size_t y_size) -> W
Definition mp_core.h:94
constexpr void comba_mul(W z[2 *N], const W x[N], const W y[N])
Definition mp_core.h:801
constexpr auto load_le(ParamTs &&... params)
Definition loadstor.h:495

◆ ~BlindedScalarBits()

template<typename C, size_t WindowBits>
Botan::BlindedScalarBits< C, WindowBits >::~BlindedScalarBits ( )
inline

Definition at line 1358 of file pcurves_impl.h.

1358 {
1359 secure_zeroize_buffer(m_bytes.data(), m_bytes.size());
1360 CT::unpoison(m_bytes.data(), m_bytes.size());
1361 }
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:67
void secure_zeroize_buffer(void *ptr, size_t n)
Definition mem_utils.cpp:29

◆ BlindedScalarBits() [2/3]

template<typename C, size_t WindowBits>
Botan::BlindedScalarBits< C, WindowBits >::BlindedScalarBits ( const BlindedScalarBits< C, WindowBits > & other)
delete

◆ BlindedScalarBits() [3/3]

template<typename C, size_t WindowBits>
Botan::BlindedScalarBits< C, WindowBits >::BlindedScalarBits ( BlindedScalarBits< C, WindowBits > && other)
delete

Member Function Documentation

◆ bits()

template<typename C, size_t WindowBits>
size_t Botan::BlindedScalarBits< C, WindowBits >::bits ( ) const
inline

Definition at line 1305 of file pcurves_impl.h.

1305{ return m_bits; }

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

◆ get_window()

template<typename C, size_t WindowBits>
size_t Botan::BlindedScalarBits< C, WindowBits >::get_window ( size_t offset) const
inline

Definition at line 1353 of file pcurves_impl.h.

1353 {
1354 // Extract a WindowBits sized window out of s, depending on offset.
1356 }
constexpr size_t read_window_bits(std::span< const W, N > words, size_t offset)
Definition mp_core.h:1054

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

◆ operator=() [1/2]

template<typename C, size_t WindowBits>
BlindedScalarBits & Botan::BlindedScalarBits< C, WindowBits >::operator= ( BlindedScalarBits< C, WindowBits > && other)
delete

◆ operator=() [2/2]

template<typename C, size_t WindowBits>
BlindedScalarBits & Botan::BlindedScalarBits< C, WindowBits >::operator= ( const BlindedScalarBits< C, WindowBits > & other)
delete

Member Data Documentation

◆ Bits

template<typename C, size_t WindowBits>
size_t Botan::BlindedScalarBits< C, WindowBits >::Bits = C::Scalar::BITS + BlindingBits
staticconstexpr

Definition at line 1303 of file pcurves_impl.h.


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