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

#include <pcurves_impl.h>

Public Member Functions

constexpr 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 + (BlindingEnabled ? BlindingBits : 0)
static constexpr size_t Bytes = (Bits + 7) / 8

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 you would like a "go faster" button, change the BlindingEnabled variable below to false.

Definition at line 1259 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 1301 of file pcurves_impl.h.

1301 {
1302 if constexpr(BlindingEnabled) {
1303 constexpr size_t mask_words = BlindingBits / WordInfo<W>::bits;
1304 constexpr size_t mask_bytes = mask_words * WordInfo<W>::bytes;
1305
1306 constexpr size_t n_words = C::Words;
1307
1308 uint8_t maskb[mask_bytes] = {0};
1309 if(rng.is_seeded()) {
1310 rng.randomize(maskb, mask_bytes);
1311 } else {
1312 // If we don't have an RNG we don't have many good options. We
1313 // could just omit the blinding entirely, but this changes the
1314 // size of the blinded scalar, which we're expecting otherwise is
1315 // knowable at compile time. So generate a mask by XORing the
1316 // bytes of the scalar together. At worst, it's equivalent to
1317 // omitting the blinding entirely.
1318
1320 scalar.serialize_to(sbytes);
1321 for(size_t i = 0; i != sbytes.size(); ++i) {
1322 maskb[i % mask_bytes] ^= sbytes[i];
1323 }
1324 }
1325
1326 W mask[n_words] = {0};
1329 mask[0] |= 1;
1330
1331 W mask_n[2 * n_words] = {0};
1332
1333 const auto sw = scalar.to_words();
1334
1335 // Compute masked scalar s + k*n
1337 bigint_add2(mask_n, 2 * n_words, sw.data(), sw.size());
1338
1341 } else {
1342 static_assert(Bytes == C::Scalar::BYTES);
1343 m_bytes.resize(Bytes);
1344 scalar.serialize_to(std::span{m_bytes}.template first<Bytes>());
1345 }
1346
1347 CT::poison(m_bytes.data(), m_bytes.size());
1348 }
static constexpr size_t Bytes
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:54
constexpr auto bigint_add2(W x[], size_t x_size, const W y[], size_t y_size) -> W
Definition mp_core.h:96
constexpr void comba_mul(W z[2 *N], const W x[N], const W y[N])
Definition mp_core.h:699
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 1355 of file pcurves_impl.h.

1355 {
1356 secure_scrub_memory(m_bytes.data(), m_bytes.size());
1357 CT::unpoison(m_bytes.data(), m_bytes.size());
1358 }
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:65
void secure_scrub_memory(void *ptr, size_t n)
Definition mem_utils.cpp:24

◆ 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
inlineconstexpr

Definition at line 1299 of file pcurves_impl.h.

1299{ return Bits; }
static constexpr size_t 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 1350 of file pcurves_impl.h.

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

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 + (BlindingEnabled ? BlindingBits : 0)
staticconstexpr

Definition at line 1296 of file pcurves_impl.h.

◆ Bytes

template<typename C, size_t WindowBits>
size_t Botan::BlindedScalarBits< C, WindowBits >::Bytes = (Bits + 7) / 8
staticconstexpr

Definition at line 1297 of file pcurves_impl.h.


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