Botan 3.6.0
Crypto and TLS for C&
Botan::CRYSTALS::BitPackingTrait< range, PolyTrait > Struct Template Referencefinal

#include <pqcrystals_encoding.h>

Public Types

using collector_array = std::array<sink_t, collectors_per_pack>
 
using collector_bytearray = std::array<uint8_t, collector_bytes_per_pack>
 
using sink_t = uint64_t
 
using T = typename PolyTrait::T
 
using unsigned_T = std::make_unsigned_t<T>
 

Static Public Attributes

static constexpr size_t bits_in_collector = sizeof(sink_t) * 8
 
static constexpr size_t bits_per_coeff = bitlen(range)
 
static constexpr size_t bits_per_pack
 
static constexpr size_t bytes_per_pack = bits_per_pack / 8
 
static constexpr size_t coeffs_per_pack = bits_per_pack / bits_per_coeff
 
static constexpr size_t collector_bytes_per_pack = collectors_per_pack * sizeof(sink_t)
 
static constexpr size_t collectors_per_pack = (bytes_per_pack + sizeof(sink_t) - 1) / sizeof(sink_t)
 
static constexpr sink_t value_mask = (1 << bits_per_coeff) - 1
 

Detailed Description

template<int32_t range, crystals_trait PolyTrait>
struct Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >

Helper for base implementations of NIST FIPS 204, Algorithms 16-19 and NIST FIPS 203 Algorithms 5-6. It pre-computes generic values to bit-(un)pack polynomial coefficients at compile-time.

The base implementations are also templated with the range parameter forcing the compiler to generate specialized code for each supported range.

Definition at line 66 of file pqcrystals_encoding.h.

Member Typedef Documentation

◆ collector_array

template<int32_t range, crystals_trait PolyTrait>
using Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::collector_array = std::array<sink_t, collectors_per_pack>

Definition at line 89 of file pqcrystals_encoding.h.

◆ collector_bytearray

template<int32_t range, crystals_trait PolyTrait>
using Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::collector_bytearray = std::array<uint8_t, collector_bytes_per_pack>

Definition at line 90 of file pqcrystals_encoding.h.

◆ sink_t

template<int32_t range, crystals_trait PolyTrait>
using Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::sink_t = uint64_t

Definition at line 69 of file pqcrystals_encoding.h.

◆ T

template<int32_t range, crystals_trait PolyTrait>
using Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::T = typename PolyTrait::T

Definition at line 67 of file pqcrystals_encoding.h.

◆ unsigned_T

template<int32_t range, crystals_trait PolyTrait>
using Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::unsigned_T = std::make_unsigned_t<T>

Definition at line 68 of file pqcrystals_encoding.h.

Member Data Documentation

◆ bits_in_collector

template<int32_t range, crystals_trait PolyTrait>
size_t Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::bits_in_collector = sizeof(sink_t) * 8
staticconstexpr

Definition at line 73 of file pqcrystals_encoding.h.

◆ bits_per_coeff

template<int32_t range, crystals_trait PolyTrait>
size_t Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::bits_per_coeff = bitlen(range)
staticconstexpr

Definition at line 74 of file pqcrystals_encoding.h.

◆ bits_per_pack

template<int32_t range, crystals_trait PolyTrait>
size_t Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::bits_per_pack
staticconstexpr
Initial value:
= [] {
size_t smallest_aligned_pack = std::lcm(bits_per_coeff, size_t(8));
return (smallest_aligned_pack < bits_in_collector)
? (bits_in_collector / smallest_aligned_pack) * smallest_aligned_pack
: smallest_aligned_pack;
}()
static constexpr size_t bits_in_collector
static constexpr size_t bits_per_coeff

Definition at line 75 of file pqcrystals_encoding.h.

75 {
76 // Ensure that the bit-packing is byte-aligned and scale it
77 // to utilize the collector's bit-width as much as possible.
78 size_t smallest_aligned_pack = std::lcm(bits_per_coeff, size_t(8));
79 return (smallest_aligned_pack < bits_in_collector)
80 ? (bits_in_collector / smallest_aligned_pack) * smallest_aligned_pack
81 : smallest_aligned_pack;
82 }();

◆ bytes_per_pack

template<int32_t range, crystals_trait PolyTrait>
size_t Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::bytes_per_pack = bits_per_pack / 8
staticconstexpr

Definition at line 83 of file pqcrystals_encoding.h.

◆ coeffs_per_pack

template<int32_t range, crystals_trait PolyTrait>
size_t Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::coeffs_per_pack = bits_per_pack / bits_per_coeff
staticconstexpr

Definition at line 84 of file pqcrystals_encoding.h.

◆ collector_bytes_per_pack

template<int32_t range, crystals_trait PolyTrait>
size_t Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::collector_bytes_per_pack = collectors_per_pack * sizeof(sink_t)
staticconstexpr

Definition at line 86 of file pqcrystals_encoding.h.

◆ collectors_per_pack

template<int32_t range, crystals_trait PolyTrait>
size_t Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::collectors_per_pack = (bytes_per_pack + sizeof(sink_t) - 1) / sizeof(sink_t)
staticconstexpr

Definition at line 85 of file pqcrystals_encoding.h.

◆ value_mask

template<int32_t range, crystals_trait PolyTrait>
sink_t Botan::CRYSTALS::BitPackingTrait< range, PolyTrait >::value_mask = (1 << bits_per_coeff) - 1
staticconstexpr

Definition at line 87 of file pqcrystals_encoding.h.


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