Skip to content

Commit bccf625

Browse files
fix: resolve 6 CI failures — fe_inv addition chain, MSVC cipher_interface, gitleaks, ASan suppressions
- Fix fe_inv constant-time addition chain: 2 squarings (z^8) not 3 (z^16) per NaCl ref10 - Parenthesize std::min/std::numeric_limits in cipher_interface.hpp for MSVC - Replace gitleaks-action@v2 (requires org license) with free gitleaks CLI binary - Remove invalid LSan suppression path from ASAN_OPTIONS (LSan format != ASan format)
1 parent b4ef335 commit bccf625

3 files changed

Lines changed: 27 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
- name: Test
7777
run: ctest --test-dir build-asan --output-on-failure
7878
env:
79-
ASAN_OPTIONS: detect_leaks=1:halt_on_error=1:suppressions=${{ github.workspace }}/.lsan_suppressions.txt
79+
ASAN_OPTIONS: detect_leaks=1:halt_on_error=1
8080
LSAN_OPTIONS: suppressions=${{ github.workspace }}/.lsan_suppressions.txt
8181
UBSAN_OPTIONS: halt_on_error=1:print_stacktrace=1
8282

@@ -441,9 +441,13 @@ jobs:
441441
with:
442442
fetch-depth: 0
443443

444-
- uses: gitleaks/gitleaks-action@v2
445-
env:
446-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
444+
- name: Install gitleaks
445+
run: |
446+
curl -sSfL https://github.com/gitleaks/gitleaks/releases/download/v8.24.3/gitleaks_8.24.3_linux_x64.tar.gz \
447+
| sudo tar xz -C /usr/local/bin gitleaks
448+
449+
- name: Run gitleaks
450+
run: gitleaks detect --source . --verbose --redact
447451

448452
# ---------------------------------------------------------------------------
449453
# Gap T-16: Python SAST (bandit) — security scanning for Python bindings

include/signet/crypto/cipher_interface.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ inline void fill_random_bytes(uint8_t* buf, size_t size) {
123123
written += static_cast<size_t>(ret);
124124
}
125125
#elif defined(_WIN32)
126-
if (size > static_cast<size_t>(std::numeric_limits<ULONG>::max())) {
126+
if (size > static_cast<size_t>((std::numeric_limits<ULONG>::max)())) {
127127
throw std::runtime_error("csprng_fill: size exceeds ULONG max");
128128
}
129129
NTSTATUS status = BCryptGenRandom(NULL, buf, static_cast<ULONG>(size),
@@ -397,11 +397,11 @@ class AesGcmCipher final : public ICipher {
397397

398398
/// Construct from a key vector (must be 32 bytes for AES-256).
399399
explicit AesGcmCipher(const std::vector<uint8_t>& key)
400-
: key_{} { std::memcpy(key_.data(), key.data(), std::min(key.size(), key_.size())); }
400+
: key_{} { std::memcpy(key_.data(), key.data(), (std::min)(key.size(), key_.size())); }
401401

402402
/// Construct from a raw key pointer and length.
403403
explicit AesGcmCipher(const uint8_t* key, size_t key_len)
404-
: key_{} { std::memcpy(key_.data(), key, std::min(key_len, key_.size())); }
404+
: key_{} { std::memcpy(key_.data(), key, (std::min)(key_len, key_.size())); }
405405

406406
/// Register a callback invoked when the key approaches its invocation limit.
407407
/// NIST SP 800-38D §8.2 requires key rotation before 2^32 random-IV GCM
@@ -517,11 +517,11 @@ class AesCtrCipher final : public ICipher {
517517
public:
518518
/// Construct from a key vector (must be 32 bytes for AES-256).
519519
explicit AesCtrCipher(const std::vector<uint8_t>& key)
520-
: key_{} { std::memcpy(key_.data(), key.data(), std::min(key.size(), key_.size())); }
520+
: key_{} { std::memcpy(key_.data(), key.data(), (std::min)(key.size(), key_.size())); }
521521

522522
/// Construct from a raw key pointer and length.
523523
explicit AesCtrCipher(const uint8_t* key, size_t key_len)
524-
: key_{} { std::memcpy(key_.data(), key, std::min(key_len, key_.size())); }
524+
: key_{} { std::memcpy(key_.data(), key, (std::min)(key_len, key_.size())); }
525525

526526
[[nodiscard]] expected<std::vector<uint8_t>> encrypt(
527527
const uint8_t* data, size_t size,

include/signet/crypto/post_quantum.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,14 @@ inline void fe_cswap(Fe& a, Fe& b, uint64_t swap) {
516516
/// Constant-time addition chain — no data-dependent branching (CWE-208).
517517
/// Uses the standard Itoh-Tsujii-style chain for GF(2^255-19) inversion.
518518
inline Fe fe_inv(const Fe& z) {
519-
// z^1 already have
519+
// Constant-time addition chain for z^(p-2) mod p, p = 2^255 - 19
520+
// Follows NaCl ref10 / SUPERCOP — branch-free (CWE-208 compliant)
520521
Fe t0 = fe_sq(z); // z^2
521-
Fe t1 = fe_sq(fe_sq(fe_sq(t0))); // z^16
522-
t1 = fe_mul(t1, z); // z^17 (unused name kept for symmetry)
523-
t0 = fe_mul(t1, t0); // z^19
524-
Fe t2 = fe_sq(t0); // z^38
525-
t2 = fe_mul(t2, t1); // z^(2^5-1)
522+
Fe t1 = fe_sq(fe_sq(t0)); // z^8
523+
t1 = fe_mul(t1, z); // z^9
524+
t0 = fe_mul(t0, t1); // z^11
525+
Fe t2 = fe_sq(t0); // z^22
526+
t2 = fe_mul(t2, t1); // z^(2^5-1) = z^31
526527
// z^(2^10-1)
527528
Fe a = t2; for (int i = 0; i < 5; ++i) a = fe_sq(a);
528529
a = fe_mul(a, t2);
@@ -668,13 +669,13 @@ inline void fe_cswap(Fe& a, Fe& b, uint64_t swap) {
668669
}
669670

670671
inline Fe fe_inv(const Fe& z) {
671-
// Same addition chain, but using 10-limb operations
672-
Fe t0 = fe_sq(z);
673-
Fe t1 = fe_sq(fe_sq(fe_sq(t0)));
674-
t1 = fe_mul(t1, z);
675-
t0 = fe_mul(t1, t0);
676-
Fe t2 = fe_sq(t0);
677-
t2 = fe_mul(t2, t1);
672+
// Same addition chain (ref10), but using 10-limb operations
673+
Fe t0 = fe_sq(z); // z^2
674+
Fe t1 = fe_sq(fe_sq(t0)); // z^8
675+
t1 = fe_mul(t1, z); // z^9
676+
t0 = fe_mul(t0, t1); // z^11
677+
Fe t2 = fe_sq(t0); // z^22
678+
t2 = fe_mul(t2, t1); // z^31 = z^(2^5-1)
678679
Fe a = t2;
679680
for (int i=0;i<5;i++) a=fe_sq(a);
680681
a=fe_mul(a,t2);

0 commit comments

Comments
 (0)