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

#include <pcurves_impl.h>

Public Types

using Curve = C

Public Member Functions

size_t bits () const
 BlindedScalarBits (BlindedScalarBits &&other)=delete
 BlindedScalarBits (const BlindedScalarBits &other)=delete
template<typename Randomness>
 BlindedScalarBits (const typename C::Scalar &scalar, const Randomness &randomness, size_t idx=0)
size_t get_window (size_t offset) const
BlindedScalarBits & operator= (BlindedScalarBits &&other)=delete
BlindedScalarBits & operator= (const BlindedScalarBits &other)=delete
 ~BlindedScalarBits ()

Static Public Attributes

static constexpr size_t Bits = C::Scalar::BITS + BlindingBits
static constexpr size_t MaskBytes = MaskWords * WordInfo<W>::bytes
static constexpr size_t MaskWords = (BlindingBits + WordInfo<W>::bits - 1) / WordInfo<W>::bits

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 1345 of file pcurves_impl.h.

Member Typedef Documentation

◆ Curve

template<typename C, size_t WindowBits>
using Botan::BlindedScalarBits< C, WindowBits >::Curve = C

Definition at line 1354 of file pcurves_impl.h.

Constructor & Destructor Documentation

◆ BlindedScalarBits() [1/3]

template<typename C, size_t WindowBits>
template<typename Randomness>
Botan::BlindedScalarBits< C, WindowBits >::BlindedScalarBits ( const typename C::Scalar & scalar,
const Randomness & randomness,
size_t idx = 0 )
inline

Blind the scalar using the idx'th mask of the provided BlindingRandomness

Definition at line 1368 of file pcurves_impl.h.

1368 {
1369 // Conditional ok: caller's RNG state (seeded vs not) is presumed public
1370 if(BlindingBits > 0 && randomness.seeded()) {
1371 constexpr size_t n_words = C::Words;
1372
1373 W mask[n_words] = {0};
1374 load_le(mask, randomness.mask(idx).data(), MaskWords);
1375
1376 // Mask to exactly BlindingBits
1377 constexpr size_t ExcessBits = MaskWords * WordInfo<W>::bits - BlindingBits;
1378 if constexpr(ExcessBits > 0) {
1379 constexpr W ExcessMask = (static_cast<W>(1) << (WordInfo<W>::bits - ExcessBits)) - 1;
1380 mask[MaskWords - 1] &= ExcessMask;
1381 }
1382
1383 // Set top and bottom bits of mask
1384 constexpr size_t TopMaskBit = (BlindingBits - 1) % WordInfo<W>::bits;
1385 mask[(BlindingBits - 1) / WordInfo<W>::bits] |= static_cast<W>(1) << TopMaskBit;
1386 mask[0] |= 1;
1387
1388 W mask_n[2 * n_words] = {0};
1389
1390 const auto sw = scalar.to_words();
1391
1392 // Compute masked scalar s + k*n
1394 bigint_add2(mask_n, 2 * n_words, sw.data(), sw.size());
1395
1398 m_bits = C::Scalar::BITS + BlindingBits;
1399 } else {
1400 // No RNG available, skip blinding
1401 m_bytes.resize(C::Scalar::BYTES);
1402 scalar.serialize_to(std::span{m_bytes}.template first<C::Scalar::BYTES>());
1403 m_bits = C::Scalar::BITS;
1404 }
1405 }
static constexpr size_t MaskWords
constexpr auto bigint_add2(W x[], size_t x_size, const W y[], size_t y_size) -> W
Definition mp_core.h:98
constexpr void comba_mul(W z[2 *N], const W x[N], const W y[N])
Definition mp_core.h:981
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 1412 of file pcurves_impl.h.

1412{ secure_zeroize_buffer(m_bytes.data(), m_bytes.size()); }
void secure_zeroize_buffer(void *ptr, size_t n)
Definition mem_utils.cpp:28

◆ 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 1362 of file pcurves_impl.h.

1362{ return m_bits; }

◆ get_window()

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

Definition at line 1407 of file pcurves_impl.h.

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

◆ 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 1357 of file pcurves_impl.h.

◆ MaskBytes

template<typename C, size_t WindowBits>
size_t Botan::BlindedScalarBits< C, WindowBits >::MaskBytes = MaskWords * WordInfo<W>::bytes
staticconstexpr

Definition at line 1360 of file pcurves_impl.h.

◆ MaskWords

template<typename C, size_t WindowBits>
size_t Botan::BlindedScalarBits< C, WindowBits >::MaskWords = (BlindingBits + WordInfo<W>::bits - 1) / WordInfo<W>::bits
staticconstexpr

Definition at line 1359 of file pcurves_impl.h.


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