reformat source tree with increased *ColumnLimit*

Signed-off-by: Anjan Roy <hello@itzmeanjan.in>
This commit is contained in:
Anjan Roy
2023-12-05 22:20:52 +04:00
parent 1febce46ca
commit ce3ba6ed56
9 changed files with 26 additions and 59 deletions

View File

@@ -81,7 +81,7 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma BreakInheritanceList: BeforeComma
BreakStringLiterals: true BreakStringLiterals: true
ColumnLimit: 120 ColumnLimit: 172
CommentPragmas: '^ IWYU pragma:' CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false CompactNamespaces: false
ConstructorInitializerIndentWidth: 2 ConstructorInitializerIndentWidth: 2

View File

@@ -48,7 +48,7 @@ public:
inline constexpr zq_t operator+(const zq_t rhs) const inline constexpr zq_t operator+(const zq_t rhs) const
{ {
const uint32_t t0 = this->v + rhs.v; const uint32_t t0 = this->v + rhs.v;
const uint32_t mask = (-static_cast<uint32_t>(t0 >= Q)); const auto mask = -static_cast<uint32_t>(t0 >= Q);
const uint32_t t1 = t0 - (mask & Q); const uint32_t t1 = t0 - (mask & Q);
return zq_t(t1); return zq_t(t1);
@@ -143,8 +143,8 @@ private:
const uint32_t t2 = t1 * Q; const uint32_t t2 = t1 * Q;
const uint32_t t = v - t2; const uint32_t t = v - t2;
const bool flg = t >= Q; const auto mask = -static_cast<uint32_t>(t >= Q);
const uint32_t t_prime = t - flg * Q; const uint32_t t_prime = t - (mask & Q);
return t_prime; return t_prime;
} }

View File

@@ -144,8 +144,7 @@ encapsulate(std::span<const uint8_t, 32> m,
// https://pq-crystals.org/kyber/data/kyber-specification-round3-20210804.pdf // https://pq-crystals.org/kyber/data/kyber-specification-round3-20210804.pdf
template<size_t k, size_t eta1, size_t eta2, size_t du, size_t dv> template<size_t k, size_t eta1, size_t eta2, size_t du, size_t dv>
static inline shake256::shake256_t static inline shake256::shake256_t
decapsulate(std::span<const uint8_t, kyber_utils::get_kem_secret_key_len<k>()> seckey, decapsulate(std::span<const uint8_t, kyber_utils::get_kem_secret_key_len<k>()> seckey, std::span<const uint8_t, kyber_utils::get_kem_cipher_len<k, du, dv>()> cipher)
std::span<const uint8_t, kyber_utils::get_kem_cipher_len<k, du, dv>()> cipher)
requires(kyber_params::check_decap_params(k, eta1, eta2, du, dv)) requires(kyber_params::check_decap_params(k, eta1, eta2, du, dv))
{ {
constexpr size_t sklen = k * 12 * 32; constexpr size_t sklen = k * 12 * 32;

View File

@@ -28,10 +28,7 @@ constexpr size_t CIPHER_LEN = kyber_utils::get_kem_cipher_len<k, du, dv>();
// secret key is 3168 -bytes, given 32 -bytes seed d ( used in CPA-PKE ) and 32 // secret key is 3168 -bytes, given 32 -bytes seed d ( used in CPA-PKE ) and 32
// -bytes seed z ( used in CCA-KEM ). // -bytes seed z ( used in CCA-KEM ).
inline void inline void
keygen(std::span<const uint8_t, 32> d, keygen(std::span<const uint8_t, 32> d, std::span<const uint8_t, 32> z, std::span<uint8_t, PKEY_LEN> pubkey, std::span<uint8_t, SKEY_LEN> seckey)
std::span<const uint8_t, 32> z,
std::span<uint8_t, PKEY_LEN> pubkey,
std::span<uint8_t, SKEY_LEN> seckey)
{ {
kem::keygen<k, η1>(d, z, pubkey, seckey); kem::keygen<k, η1>(d, z, pubkey, seckey);
} }
@@ -44,9 +41,7 @@ keygen(std::span<const uint8_t, 32> d,
// //
// Returned KDF can be used for deriving shared key of arbitrary bytes length. // Returned KDF can be used for deriving shared key of arbitrary bytes length.
inline shake256::shake256_t inline shake256::shake256_t
encapsulate(std::span<const uint8_t, 32> m, encapsulate(std::span<const uint8_t, 32> m, std::span<const uint8_t, PKEY_LEN> pubkey, std::span<uint8_t, CIPHER_LEN> cipher)
std::span<const uint8_t, PKEY_LEN> pubkey,
std::span<uint8_t, CIPHER_LEN> cipher)
{ {
return kem::encapsulate<k, η1, η2, du, dv>(m, pubkey, cipher); return kem::encapsulate<k, η1, η2, du, dv>(m, pubkey, cipher);
} }

View File

@@ -28,10 +28,7 @@ constexpr size_t CIPHER_LEN = kyber_utils::get_kem_cipher_len<k, du, dv>();
// key is 1632 -bytes, given 32 -bytes seed d ( used in CPA-PKE ) and 32 -bytes // key is 1632 -bytes, given 32 -bytes seed d ( used in CPA-PKE ) and 32 -bytes
// seed z ( used in CCA-KEM ). // seed z ( used in CCA-KEM ).
inline void inline void
keygen(std::span<const uint8_t, 32> d, keygen(std::span<const uint8_t, 32> d, std::span<const uint8_t, 32> z, std::span<uint8_t, PKEY_LEN> pubkey, std::span<uint8_t, SKEY_LEN> seckey)
std::span<const uint8_t, 32> z,
std::span<uint8_t, PKEY_LEN> pubkey,
std::span<uint8_t, SKEY_LEN> seckey)
{ {
kem::keygen<k, η1>(d, z, pubkey, seckey); kem::keygen<k, η1>(d, z, pubkey, seckey);
} }
@@ -44,9 +41,7 @@ keygen(std::span<const uint8_t, 32> d,
// //
// Returned KDF can be used for deriving shared key of arbitrary bytes length. // Returned KDF can be used for deriving shared key of arbitrary bytes length.
inline shake256::shake256_t inline shake256::shake256_t
encapsulate(std::span<const uint8_t, 32> m, encapsulate(std::span<const uint8_t, 32> m, std::span<const uint8_t, PKEY_LEN> pubkey, std::span<uint8_t, CIPHER_LEN> cipher)
std::span<const uint8_t, PKEY_LEN> pubkey,
std::span<uint8_t, CIPHER_LEN> cipher)
{ {
return kem::encapsulate<k, η1, η2, du, dv>(m, pubkey, cipher); return kem::encapsulate<k, η1, η2, du, dv>(m, pubkey, cipher);
} }

View File

@@ -27,10 +27,7 @@ constexpr size_t CIPHER_LEN = kyber_utils::get_kem_cipher_len<k, du, dv>();
// key is 2400 -bytes, given 32 -bytes seed d ( used in CPA-PKE ) and 32 -bytes // key is 2400 -bytes, given 32 -bytes seed d ( used in CPA-PKE ) and 32 -bytes
// seed z ( used in CCA-KEM ). // seed z ( used in CCA-KEM ).
inline void inline void
keygen(std::span<const uint8_t, 32> d, keygen(std::span<const uint8_t, 32> d, std::span<const uint8_t, 32> z, std::span<uint8_t, PKEY_LEN> pubkey, std::span<uint8_t, SKEY_LEN> seckey)
std::span<const uint8_t, 32> z,
std::span<uint8_t, PKEY_LEN> pubkey,
std::span<uint8_t, SKEY_LEN> seckey)
{ {
kem::keygen<k, η1>(d, z, pubkey, seckey); kem::keygen<k, η1>(d, z, pubkey, seckey);
} }
@@ -43,9 +40,7 @@ keygen(std::span<const uint8_t, 32> d,
// //
// Returned KDF can be used for deriving shared key of arbitrary bytes length. // Returned KDF can be used for deriving shared key of arbitrary bytes length.
inline shake256::shake256_t inline shake256::shake256_t
encapsulate(std::span<const uint8_t, 32> m, encapsulate(std::span<const uint8_t, 32> m, std::span<const uint8_t, PKEY_LEN> pubkey, std::span<uint8_t, CIPHER_LEN> cipher)
std::span<const uint8_t, PKEY_LEN> pubkey,
std::span<uint8_t, CIPHER_LEN> cipher)
{ {
return kem::encapsulate<k, η1, η2, du, dv>(m, pubkey, cipher); return kem::encapsulate<k, η1, η2, du, dv>(m, pubkey, cipher);
} }

View File

@@ -28,9 +28,7 @@ namespace pke {
// benchmarking underlying PKE's key generation implementation. // benchmarking underlying PKE's key generation implementation.
template<size_t k, size_t eta1> template<size_t k, size_t eta1>
static inline void static inline void
keygen(std::span<const uint8_t, 32> d, keygen(std::span<const uint8_t, 32> d, std::span<uint8_t, k * 12 * 32 + 32> pubkey, std::span<uint8_t, k * 12 * 32> seckey)
std::span<uint8_t, k * 12 * 32 + 32> pubkey,
std::span<uint8_t, k * 12 * 32> seckey)
requires(kyber_params::check_keygen_params(k, eta1)) requires(kyber_params::check_keygen_params(k, eta1))
{ {
// step 2 // step 2
@@ -171,9 +169,7 @@ encrypt(std::span<const uint8_t, k * 12 * 32 + 32> pubkey,
// https://pq-crystals.org/kyber/data/kyber-specification-round3-20210804.pdf // https://pq-crystals.org/kyber/data/kyber-specification-round3-20210804.pdf
template<size_t k, size_t du, size_t dv> template<size_t k, size_t du, size_t dv>
static inline void static inline void
decrypt(std::span<const uint8_t, k * 12 * 32> seckey, decrypt(std::span<const uint8_t, k * 12 * 32> seckey, std::span<const uint8_t, k * du * 32 + dv * 32> enc, std::span<uint8_t, 32> dec)
std::span<const uint8_t, k * du * 32 + dv * 32> enc,
std::span<uint8_t, 32> dec)
requires(kyber_params::check_decrypt_params(k, du, dv)) requires(kyber_params::check_decrypt_params(k, du, dv))
{ {
constexpr size_t encoff = k * du * 32; constexpr size_t encoff = k * du * 32;

View File

@@ -124,8 +124,7 @@ cbd(std::span<const uint8_t, 64 * eta> prf, std::span<field::zq_t, ntt::N> poly)
const size_t boff = i * 3; const size_t boff = i * 3;
const size_t poff = i << 2; const size_t poff = i << 2;
const uint32_t word = (static_cast<uint32_t>(prf[boff + 2]) << 16) | (static_cast<uint32_t>(prf[boff + 1]) << 8) | const uint32_t word = (static_cast<uint32_t>(prf[boff + 2]) << 16) | (static_cast<uint32_t>(prf[boff + 1]) << 8) | static_cast<uint32_t>(prf[boff + 0]);
static_cast<uint32_t>(prf[boff + 0]);
const uint32_t t0 = (word >> 0) & mask24; const uint32_t t0 = (word >> 0) & mask24;
const uint32_t t1 = (word >> 1) & mask24; const uint32_t t1 = (word >> 1) & mask24;

View File

@@ -26,14 +26,10 @@ encode(std::span<const field::zq_t, ntt::N> poly, std::span<uint8_t, 32 * l> arr
for (size_t i = 0; i < itr_cnt; i++) { for (size_t i = 0; i < itr_cnt; i++) {
const size_t off = i << 3; const size_t off = i << 3;
arr[i] = (static_cast<uint8_t>(poly[off + 7].raw() & one) << 7) | arr[i] = (static_cast<uint8_t>(poly[off + 7].raw() & one) << 7) | (static_cast<uint8_t>(poly[off + 6].raw() & one) << 6) |
(static_cast<uint8_t>(poly[off + 6].raw() & one) << 6) | (static_cast<uint8_t>(poly[off + 5].raw() & one) << 5) | (static_cast<uint8_t>(poly[off + 4].raw() & one) << 4) |
(static_cast<uint8_t>(poly[off + 5].raw() & one) << 5) | (static_cast<uint8_t>(poly[off + 3].raw() & one) << 3) | (static_cast<uint8_t>(poly[off + 2].raw() & one) << 2) |
(static_cast<uint8_t>(poly[off + 4].raw() & one) << 4) | (static_cast<uint8_t>(poly[off + 1].raw() & one) << 1) | (static_cast<uint8_t>(poly[off + 0].raw() & one) << 0);
(static_cast<uint8_t>(poly[off + 3].raw() & one) << 3) |
(static_cast<uint8_t>(poly[off + 2].raw() & one) << 2) |
(static_cast<uint8_t>(poly[off + 1].raw() & one) << 1) |
(static_cast<uint8_t>(poly[off + 0].raw() & one) << 0);
} }
} else if constexpr (l == 4) { } else if constexpr (l == 4) {
constexpr size_t itr_cnt = ntt::N >> 1; constexpr size_t itr_cnt = ntt::N >> 1;
@@ -65,11 +61,9 @@ encode(std::span<const field::zq_t, ntt::N> poly, std::span<uint8_t, 32 * l> arr
const auto t7 = poly[poff + 7].raw(); const auto t7 = poly[poff + 7].raw();
arr[boff + 0] = (static_cast<uint8_t>(t1 & mask3) << 5) | (static_cast<uint8_t>(t0 & mask5) << 0); arr[boff + 0] = (static_cast<uint8_t>(t1 & mask3) << 5) | (static_cast<uint8_t>(t0 & mask5) << 0);
arr[boff + 1] = (static_cast<uint8_t>(t3 & mask1) << 7) | (static_cast<uint8_t>(t2 & mask5) << 2) | arr[boff + 1] = (static_cast<uint8_t>(t3 & mask1) << 7) | (static_cast<uint8_t>(t2 & mask5) << 2) | static_cast<uint8_t>((t1 >> 3) & mask2);
static_cast<uint8_t>((t1 >> 3) & mask2);
arr[boff + 2] = (static_cast<uint8_t>(t4 & mask4) << 4) | static_cast<uint8_t>((t3 >> 1) & mask4); arr[boff + 2] = (static_cast<uint8_t>(t4 & mask4) << 4) | static_cast<uint8_t>((t3 >> 1) & mask4);
arr[boff + 3] = (static_cast<uint8_t>(t6 & mask2) << 6) | (static_cast<uint8_t>(t5 & mask5) << 1) | arr[boff + 3] = (static_cast<uint8_t>(t6 & mask2) << 6) | (static_cast<uint8_t>(t5 & mask5) << 1) | static_cast<uint8_t>((t4 >> 4) & mask1);
static_cast<uint8_t>((t4 >> 4) & mask1);
arr[boff + 4] = (static_cast<uint8_t>(t7 & mask5) << 3) | static_cast<uint8_t>((t6 >> 2) & mask3); arr[boff + 4] = (static_cast<uint8_t>(t7 & mask5) << 3) | static_cast<uint8_t>((t6 >> 2) & mask3);
} }
} else if constexpr (l == 10) { } else if constexpr (l == 10) {
@@ -201,16 +195,12 @@ decode(std::span<const uint8_t, 32 * l> arr, std::span<field::zq_t, ntt::N> poly
const size_t boff = i * 5; const size_t boff = i * 5;
const auto t0 = static_cast<uint16_t>(arr[boff + 0] & mask5); const auto t0 = static_cast<uint16_t>(arr[boff + 0] & mask5);
const auto t1 = const auto t1 = static_cast<uint16_t>((arr[boff + 1] & mask2) << 3) | static_cast<uint16_t>((arr[boff + 0] >> 5) & mask3);
static_cast<uint16_t>((arr[boff + 1] & mask2) << 3) | static_cast<uint16_t>((arr[boff + 0] >> 5) & mask3);
const auto t2 = static_cast<uint16_t>((arr[boff + 1] >> 2) & mask5); const auto t2 = static_cast<uint16_t>((arr[boff + 1] >> 2) & mask5);
const auto t3 = const auto t3 = static_cast<uint16_t>((arr[boff + 2] & mask4) << 1) | static_cast<uint16_t>((arr[boff + 1] >> 7) & mask1);
static_cast<uint16_t>((arr[boff + 2] & mask4) << 1) | static_cast<uint16_t>((arr[boff + 1] >> 7) & mask1); const auto t4 = static_cast<uint16_t>((arr[boff + 3] & mask1) << 4) | static_cast<uint16_t>((arr[boff + 2] >> 4) & mask4);
const auto t4 =
static_cast<uint16_t>((arr[boff + 3] & mask1) << 4) | static_cast<uint16_t>((arr[boff + 2] >> 4) & mask4);
const auto t5 = static_cast<uint16_t>((arr[boff + 3] >> 1) & mask5); const auto t5 = static_cast<uint16_t>((arr[boff + 3] >> 1) & mask5);
const auto t6 = const auto t6 = static_cast<uint16_t>((arr[boff + 4] & mask3) << 2) | static_cast<uint16_t>((arr[boff + 3] >> 6) & mask2);
static_cast<uint16_t>((arr[boff + 4] & mask3) << 2) | static_cast<uint16_t>((arr[boff + 3] >> 6) & mask2);
const auto t7 = static_cast<uint16_t>((arr[boff + 4] >> 3) & mask5); const auto t7 = static_cast<uint16_t>((arr[boff + 4] >> 3) & mask5);
poly[poff + 0] = field::zq_t(t0); poly[poff + 0] = field::zq_t(t0);
@@ -258,12 +248,10 @@ decode(std::span<const uint8_t, 32 * l> arr, std::span<field::zq_t, ntt::N> poly
const auto t0 = (static_cast<uint16_t>(arr[boff + 1] & mask3) << 8) | static_cast<uint16_t>(arr[boff + 0]); const auto t0 = (static_cast<uint16_t>(arr[boff + 1] & mask3) << 8) | static_cast<uint16_t>(arr[boff + 0]);
const auto t1 = (static_cast<uint16_t>(arr[boff + 2] & mask6) << 5) | static_cast<uint16_t>(arr[boff + 1] >> 3); const auto t1 = (static_cast<uint16_t>(arr[boff + 2] & mask6) << 5) | static_cast<uint16_t>(arr[boff + 1] >> 3);
const auto t2 = (static_cast<uint16_t>(arr[boff + 4] & mask1) << 10) | const auto t2 = (static_cast<uint16_t>(arr[boff + 4] & mask1) << 10) | (static_cast<uint16_t>(arr[boff + 3]) << 2) | static_cast<uint16_t>(arr[boff + 2] >> 6);
(static_cast<uint16_t>(arr[boff + 3]) << 2) | static_cast<uint16_t>(arr[boff + 2] >> 6);
const auto t3 = (static_cast<uint16_t>(arr[boff + 5] & mask4) << 7) | static_cast<uint16_t>(arr[boff + 4] >> 1); const auto t3 = (static_cast<uint16_t>(arr[boff + 5] & mask4) << 7) | static_cast<uint16_t>(arr[boff + 4] >> 1);
const auto t4 = (static_cast<uint16_t>(arr[boff + 6] & mask7) << 4) | static_cast<uint16_t>(arr[boff + 5] >> 4); const auto t4 = (static_cast<uint16_t>(arr[boff + 6] & mask7) << 4) | static_cast<uint16_t>(arr[boff + 5] >> 4);
const auto t5 = (static_cast<uint16_t>(arr[boff + 8] & mask2) << 9) | const auto t5 = (static_cast<uint16_t>(arr[boff + 8] & mask2) << 9) | (static_cast<uint16_t>(arr[boff + 7]) << 1) | static_cast<uint16_t>(arr[boff + 6] >> 7);
(static_cast<uint16_t>(arr[boff + 7]) << 1) | static_cast<uint16_t>(arr[boff + 6] >> 7);
const auto t6 = (static_cast<uint16_t>(arr[boff + 9] & mask5) << 6) | static_cast<uint16_t>(arr[boff + 8] >> 2); const auto t6 = (static_cast<uint16_t>(arr[boff + 9] & mask5) << 6) | static_cast<uint16_t>(arr[boff + 8] >> 2);
const auto t7 = (static_cast<uint16_t>(arr[boff + 10]) << 3) | static_cast<uint16_t>(arr[boff + 9] >> 5); const auto t7 = (static_cast<uint16_t>(arr[boff + 10]) << 3) | static_cast<uint16_t>(arr[boff + 9] >> 5);