Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Redundant consts #27

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/bit_packing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace bit_packing {
//
// See section 5.2 ( which describes bit packing ) of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const size_t sbw>
template<size_t sbw>
static inline constexpr void
encode(std::span<const field::zq_t, ntt::N> poly, std::span<uint8_t, ntt::N * sbw / 8> arr)
requires(dilithium_params::check_sbw(sbw))
Expand Down Expand Up @@ -184,7 +184,7 @@ encode(std::span<const field::zq_t, ntt::N> poly, std::span<uint8_t, ntt::N * sb
// This is just the opposite of above `encode` routine. You may want to see
// Dilithium specification's section 5.2
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const size_t sbw>
template<size_t sbw>
static inline constexpr void
decode(std::span<const uint8_t, ntt::N * sbw / 8> arr, std::span<field::zq_t, ntt::N> poly)
requires(dilithium_params::check_sbw(sbw))
Expand Down Expand Up @@ -331,7 +331,7 @@ decode(std::span<const uint8_t, ntt::N * sbw / 8> arr, std::span<field::zq_t, nt
// bits into (ω + k) -bytes, following the description in section 5.4 ( see
// point `Signature` on page 21 ) of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const size_t k, const size_t ω>
template<size_t k, size_t ω>
static inline constexpr void
encode_hint_bits(std::span<const field::zq_t, k * ntt::N> h, std::span<uint8_t, ω + k> arr)
{
Expand Down Expand Up @@ -361,7 +361,7 @@ encode_hint_bits(std::span<const field::zq_t, k * ntt::N> h, std::span<uint8_t,
// Returns boolean result denoting status of decoding of byte serialized hint
// bits. For example, say return value is true, it denotes that decoding has
// failed.
template<const size_t k, const size_t ω>
template<size_t k, size_t ω>
static inline constexpr bool
decode_hint_bits(std::span<const uint8_t, ω + k> arr, std::span<field::zq_t, k * ntt::N> h)
{
Expand Down
31 changes: 12 additions & 19 deletions include/dilithium.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace dilithium {
// Note, ebw = ceil(log2(2 * η + 1))
//
// See section 5.4 of specification for public key and secret key byte length.
template<const size_t k, const size_t l, const size_t d, const uint32_t η>
template<size_t k, size_t l, size_t d, uint32_t η>
static inline void
keygen(std::span<const uint8_t, 32> seed,
std::span<uint8_t, dilithium_utils::pub_key_len<k, d>()> pubkey,
Expand Down Expand Up @@ -133,16 +133,16 @@ keygen(std::span<const uint8_t, 32> seed,
//
// See section 5.4 of specification for understanding how signature is byte
// serialized.
template<const size_t k,
const size_t l,
const size_t d,
const uint32_t η,
const uint32_t γ1,
const uint32_t γ2,
const uint32_t τ,
const uint32_t β,
const size_t ω,
const bool randomized = false>
template<size_t k,
size_t l,
size_t d,
uint32_t η,
uint32_t γ1,
uint32_t γ2,
uint32_t τ,
uint32_t β,
size_t ω,
bool randomized = false>
static inline void
sign(std::span<const uint8_t, dilithium_utils::sec_key_len<k, l, η, d>()> seckey,
std::span<const uint8_t> msg,
Expand Down Expand Up @@ -323,14 +323,7 @@ sign(std::span<const uint8_t, dilithium_utils::sec_key_len<k, l, η, d>()> secke
//
// Verification algorithm is described in figure 4 of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const size_t k,
const size_t l,
const size_t d,
const uint32_t γ1,
const uint32_t γ2,
const uint32_t τ,
const uint32_t β,
const size_t ω>
template<size_t k, size_t l, size_t d, uint32_t γ1, uint32_t γ2, uint32_t τ, uint32_t β, size_t ω>
static inline bool
verify(std::span<const uint8_t, dilithium_utils::pub_key_len<k, d>()> pubkey,
std::span<const uint8_t> msg,
Expand Down
2 changes: 1 addition & 1 deletion include/ntt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ constexpr auto INV_N = field::zq_t(N).inv();
// See
// https://github.com/itzmeanjan/kyber/blob/3cd41a5/include/ntt.hpp#L74-L93
// for source of inspiration.
template<const size_t mbw>
template<size_t mbw>
static inline constexpr size_t
bit_rev(const size_t v)
requires(mbw == LOG2N)
Expand Down
14 changes: 7 additions & 7 deletions include/poly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace poly {

// Given a degree-255 polynomial over Z_q | q = 2^23 - 2^13 + 1, this routine
// attempts to extract out high and low order bits from each of 256 coefficients
template<const size_t d>
template<size_t d>
static inline constexpr void
power2round(std::span<const field::zq_t, ntt::N> poly,
std::span<field::zq_t, ntt::N> poly_hi,
Expand Down Expand Up @@ -40,7 +40,7 @@ mul(std::span<const field::zq_t, ntt::N> polya,

// Given a degree-255 polynomial, which has all of its coefficients in [-x, x],
// this routine subtracts each coefficient from x, so that they stay in [0, 2x].
template<const uint32_t x>
template<uint32_t x>
static inline constexpr void
sub_from_x(std::span<field::zq_t, ntt::N> poly)
{
Expand All @@ -53,7 +53,7 @@ sub_from_x(std::span<field::zq_t, ntt::N> poly)

// Given a degree-255 polynomial, this routine extracts out high order bits (
// using decompose routine ), while not mutating source polynomial
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr void
highbits(std::span<const field::zq_t, ntt::N> src, std::span<field::zq_t, ntt::N> dst)
{
Expand All @@ -64,7 +64,7 @@ highbits(std::span<const field::zq_t, ntt::N> src, std::span<field::zq_t, ntt::N

// Given a degree-255 polynomial, this routine extracts out low order bits (
// using decompose routine ), while not mutating source polynomial
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr void
lowbits(std::span<const field::zq_t, ntt::N> src, std::span<field::zq_t, ntt::N> dst)
{
Expand Down Expand Up @@ -95,7 +95,7 @@ infinity_norm(std::span<const field::zq_t, ntt::N> poly)

// Given two degree-255 polynomials, this routine computes hint bit for each
// coefficient, using `make_hint` routine.
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr void
make_hint(std::span<const field::zq_t, ntt::N> polya,
std::span<const field::zq_t, ntt::N> polyb,
Expand All @@ -110,7 +110,7 @@ make_hint(std::span<const field::zq_t, ntt::N> polya,
// polynomial r with arbitrary coefficients ∈ Z_q, this routine recovers high
// order bits of r + z s.t. hint bit was computed using `make_hint` routine and
// z is another degree-255 polynomial with small coefficients.
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr void
use_hint(std::span<const field::zq_t, ntt::N> polyh,
std::span<const field::zq_t, ntt::N> polyr,
Expand Down Expand Up @@ -138,7 +138,7 @@ count_1s(std::span<const field::zq_t, ntt::N> poly)

// Given a degree-255 polynomial, this routine shifts each coefficient
// leftwards, by d bits
template<const size_t d>
template<size_t d>
static inline constexpr void
shl(std::span<field::zq_t, ntt::N> poly)
{
Expand Down
34 changes: 17 additions & 17 deletions include/polyvec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using const_poly_t = std::span<const field::zq_t, ntt::N>;
using poly_t = std::span<field::zq_t, ntt::N>;

// Applies NTT on a vector ( of dimension k x 1 ) of degree-255 polynomials
template<const size_t k>
template<size_t k>
static inline constexpr void
ntt(std::span<field::zq_t, k * ntt::N> vec)
{
Expand All @@ -25,7 +25,7 @@ ntt(std::span<field::zq_t, k * ntt::N> vec)
}

// Applies iNTT on a vector ( of dimension k x 1 ) of degree-255 polynomials
template<const size_t k>
template<size_t k>
static inline constexpr void
intt(std::span<field::zq_t, k * ntt::N> vec)
{
Expand All @@ -37,7 +37,7 @@ intt(std::span<field::zq_t, k * ntt::N> vec)

// Compresses vector ( of dimension k x 1 ) of degree-255 polynomials by
// extracting out high and low order bits
template<const size_t k, const size_t d>
template<size_t k, size_t d>
static inline constexpr void
power2round(std::span<const field::zq_t, k * ntt::N> poly,
std::span<field::zq_t, k * ntt::N> poly_hi,
Expand All @@ -55,7 +55,7 @@ power2round(std::span<const field::zq_t, k * ntt::N> poly,
// Given two matrices ( in NTT domain ) of compatible dimension, where each
// matrix element is a degree-255 polynomial over Z_q | q = 2^23 -2^13 + 1, this
// routine attempts to multiply and compute resulting matrix
template<const size_t a_rows, const size_t a_cols, const size_t b_rows, const size_t b_cols>
template<size_t a_rows, size_t a_cols, size_t b_rows, size_t b_cols>
static inline constexpr void
matrix_multiply(std::span<const field::zq_t, a_rows * a_cols * ntt::N> a,
std::span<const field::zq_t, b_rows * b_cols * ntt::N> b,
Expand Down Expand Up @@ -86,7 +86,7 @@ matrix_multiply(std::span<const field::zq_t, a_rows * a_cols * ntt::N> a,
// Given a vector ( of dimension k x 1 ) of degree-255 polynomials, this
// routine adds it to another polynomial vector of same dimension s.t.
// destination vector is mutated.
template<const size_t k>
template<size_t k>
static inline constexpr void
add_to(std::span<const field::zq_t, k * ntt::N> src, std::span<field::zq_t, k * ntt::N> dst)
{
Expand All @@ -101,7 +101,7 @@ add_to(std::span<const field::zq_t, k * ntt::N> src, std::span<field::zq_t, k *

// Given a vector ( of dimension k x 1 ) of degree-255 polynomials, this
// routine negates each coefficient.
template<const size_t k>
template<size_t k>
static inline constexpr void
neg(std::span<field::zq_t, k * ntt::N> vec)
{
Expand All @@ -117,7 +117,7 @@ neg(std::span<field::zq_t, k * ntt::N> vec)
// Given a vector ( of dimension k x 1 ) of degree-255 polynomials s.t. each
// coefficient ∈ [-x, x], this routine subtracts each coefficient from x so that
// coefficients now stay in [0, 2x].
template<const size_t k, const uint32_t x>
template<size_t k, uint32_t x>
static inline constexpr void
sub_from_x(std::span<field::zq_t, k * ntt::N> vec)
{
Expand All @@ -130,7 +130,7 @@ sub_from_x(std::span<field::zq_t, k * ntt::N> vec)
// Given a vector ( of dimension k x 1 ) of degree-255 polynomials, this routine
// encodes each of those polynomials into 32 x sbw -bytes, writing to a
// (k x 32 x sbw) -bytes destination array.
template<const size_t k, const size_t sbw>
template<size_t k, size_t sbw>
static inline constexpr void
encode(std::span<const field::zq_t, k * ntt::N> src, std::span<uint8_t, k * sbw * ntt::N / 8> dst)
{
Expand All @@ -149,7 +149,7 @@ encode(std::span<const field::zq_t, k * ntt::N> src, std::span<uint8_t, k * sbw
// Given a byte array of length (k x 32 x sbw) -bytes, this routine decodes them
// into k degree-255 polynomials, writing them to a column vector of dimension
// k x 1.
template<const size_t k, const size_t sbw>
template<size_t k, size_t sbw>
static inline constexpr void
decode(std::span<const uint8_t, k * sbw * ntt::N / 8> src, std::span<field::zq_t, k * ntt::N> dst)
{
Expand All @@ -167,7 +167,7 @@ decode(std::span<const uint8_t, k * sbw * ntt::N / 8> src, std::span<field::zq_t

// Given a vector ( of dimension k x 1 ) of degree-255 polynomials, this routine
// extracts out high order bits from each coefficient
template<const size_t k, const uint32_t alpha>
template<size_t k, uint32_t alpha>
static inline constexpr void
highbits(std::span<const field::zq_t, k * ntt::N> src, std::span<field::zq_t, k * ntt::N> dst)
{
Expand All @@ -179,7 +179,7 @@ highbits(std::span<const field::zq_t, k * ntt::N> src, std::span<field::zq_t, k

// Given a vector ( of dimension k x 1 ) of degree-255 polynomials, this routine
// extracts out low order bits from each coefficient, while not mutating operand
template<const size_t k, const uint32_t alpha>
template<size_t k, uint32_t alpha>
static inline constexpr void
lowbits(std::span<const field::zq_t, k * ntt::N> src, std::span<field::zq_t, k * ntt::N> dst)
{
Expand All @@ -193,7 +193,7 @@ lowbits(std::span<const field::zq_t, k * ntt::N> src, std::span<field::zq_t, k *
// multiplier polynomial, this routine performs k pointwise polynomial
// multiplications when each of these polynomials are in their NTT
// representation, while not mutating operand polynomials.
template<const size_t k>
template<size_t k>
static inline constexpr void
mul_by_poly(std::span<const field::zq_t, ntt::N> poly,
std::span<const field::zq_t, k * ntt::N> src_vec,
Expand All @@ -210,7 +210,7 @@ mul_by_poly(std::span<const field::zq_t, ntt::N> poly,
//
// See point `Sizes of elements` in section 2.1 of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const size_t k>
template<size_t k>
static inline constexpr field::zq_t
infinity_norm(std::span<const field::zq_t, k * ntt::N> vec)
{
Expand All @@ -226,7 +226,7 @@ infinity_norm(std::span<const field::zq_t, k * ntt::N> vec)

// Given two vector ( of dimension k x 1 ) of degree-255 polynomials, this
// routine computes hint bit for each coefficient, using `make_hint` routine.
template<const size_t k, const uint32_t alpha>
template<size_t k, uint32_t alpha>
static inline constexpr void
make_hint(std::span<const field::zq_t, k * ntt::N> polya,
std::span<const field::zq_t, k * ntt::N> polyb,
Expand All @@ -243,7 +243,7 @@ make_hint(std::span<const field::zq_t, k * ntt::N> polya,
// Recovers high order bits of a vector of degree-255 polynomials ( i.e. r + z
// ) s.t. hint bits ( say h ) and another polynomial vector ( say r ) are
// provided.
template<const size_t k, const uint32_t alpha>
template<size_t k, uint32_t alpha>
static inline constexpr void
use_hint(std::span<const field::zq_t, k * ntt::N> polyh,
std::span<const field::zq_t, k * ntt::N> polyr,
Expand All @@ -259,7 +259,7 @@ use_hint(std::span<const field::zq_t, k * ntt::N> polyh,

// Given a vector ( of dimension k x 1 ) of degree-255 polynomials, this routine
// counts number of coefficients having value 1.
template<const size_t k>
template<size_t k>
static inline constexpr size_t
count_1s(std::span<const field::zq_t, k * ntt::N> vec)
{
Expand All @@ -275,7 +275,7 @@ count_1s(std::span<const field::zq_t, k * ntt::N> vec)

// Given a vector ( of dimension k x 1 ) of degree-255 polynomials, this routine
// shifts each coefficient leftwards by d bits
template<const size_t k, const size_t d>
template<size_t k, size_t d>
static inline constexpr void
shl(std::span<field::zq_t, k * ntt::N> vec)
{
Expand Down
12 changes: 6 additions & 6 deletions include/reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace reduction {
//
// This implementation collects some ideas from
// https://github.com/pq-crystals/dilithium/blob/3e9b9f1/ref/rounding.c#L5-L23
template<const size_t d>
template<size_t d>
static inline constexpr std::pair<field::zq_t, field::zq_t>
power2round(const field::zq_t r)
requires(dilithium_params::check_d(d))
Expand All @@ -45,7 +45,7 @@ power2round(const field::zq_t r)
//
// See definition of this routine in figure 3 of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr std::pair<field::zq_t, field::zq_t>
decompose(const field::zq_t r)
requires(dilithium_params::check_γ2(alpha / 2))
Expand Down Expand Up @@ -74,7 +74,7 @@ decompose(const field::zq_t r)
//
// See definition of this routine in figure 3 of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr field::zq_t
highbits(const field::zq_t r)
{
Expand All @@ -87,7 +87,7 @@ highbits(const field::zq_t r)
//
// See definition of this routine in figure 3 of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr field::zq_t
lowbits(const field::zq_t r)
{
Expand All @@ -103,7 +103,7 @@ lowbits(const field::zq_t r)
//
// See definition of this routine in figure 3 of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr field::zq_t
make_hint(const field::zq_t z, const field::zq_t r)
{
Expand All @@ -118,7 +118,7 @@ make_hint(const field::zq_t z, const field::zq_t r)
//
// See definition of this routine in figure 3 of Dilithium specification
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
template<const uint32_t alpha>
template<uint32_t alpha>
static inline constexpr field::zq_t
use_hint(const field::zq_t h, const field::zq_t r)
{
Expand Down
Loading