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

#include <pcurves_impl.h>

Public Member Functions

 BlindedScalarBits (const typename C::Scalar &scalar, RandomNumberGenerator &rng)
 
size_t get_window (size_t offset) const
 
 ~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

Definition at line 951 of file pcurves_impl.h.

Constructor & Destructor Documentation

◆ BlindedScalarBits()

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

Definition at line 968 of file pcurves_impl.h.

968 {
969 if constexpr(BlindingEnabled) {
970 constexpr size_t mask_words = BlindingBits / WordInfo<W>::bits;
971 constexpr size_t mask_bytes = mask_words * WordInfo<W>::bytes;
972
973 constexpr size_t n_words = C::NW.size();
974
975 uint8_t maskb[mask_bytes] = {0};
976 rng.randomize(maskb, mask_bytes);
977
978 W mask[n_words] = {0};
979 load_le(mask, maskb, mask_words);
980 mask[mask_words - 1] |= WordInfo<W>::top_bit;
981
982 W mask_n[2 * n_words] = {0};
983
984 const auto sw = scalar.to_words();
985
986 // Compute masked scalar s + k*n
987 comba_mul<n_words>(mask_n, mask, C::NW.data());
988 bigint_add2_nc(mask_n, 2 * n_words, sw.data(), sw.size());
989
990 std::reverse(mask_n, mask_n + 2 * n_words);
991 m_bytes = store_be<std::vector<uint8_t>>(mask_n);
992 } else {
993 static_assert(Bytes == C::Scalar::BYTES);
994 m_bytes.resize(Bytes);
995 scalar.serialize_to(std::span{m_bytes}.template first<Bytes>());
996 }
997
998 CT::poison(m_bytes.data(), m_bytes.size());
999 }
static constexpr size_t Bytes
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:46
constexpr void comba_mul(W z[2 *N], const W x[N], const W y[N])
Definition mp_core.h:948
constexpr auto load_le(ParamTs &&... params)
Definition loadstor.h:458
constexpr auto bigint_add2_nc(W x[], size_t x_size, const W y[], size_t y_size) -> W
Definition mp_core.h:206
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:707

References Botan::bigint_add2_nc(), Botan::BlindedScalarBits< C, WindowBits >::Bytes, Botan::comba_mul(), Botan::load_le(), Botan::CT::poison(), Botan::RandomNumberGenerator::randomize(), and Botan::store_be().

◆ ~BlindedScalarBits()

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

Definition at line 1006 of file pcurves_impl.h.

1006 {
1007 secure_scrub_memory(m_bytes.data(), m_bytes.size());
1008 CT::unpoison(m_bytes.data(), m_bytes.size());
1009 }
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:57
void secure_scrub_memory(void *ptr, size_t n)
Definition os_utils.cpp:89

References Botan::secure_scrub_memory(), and Botan::CT::unpoison().

Member Function Documentation

◆ get_window()

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

Definition at line 1001 of file pcurves_impl.h.

1001 {
1002 // Extract a WindowBits sized window out of s, depending on offset.
1003 return read_window_bits<WindowBits>(std::span{m_bytes}, offset);
1004 }

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

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

◆ Bytes

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

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