Skip to content

fix(math): reduce Bézout coefficient modulo irreducible polynomial in gfExtendedEuclideanWithTrace (#1715) - #1811

Merged
csxark merged 1 commit into
csxark:mainfrom
nayanraj864-cmyk:fix/gf-extended-euclidean-reduction-1715
Aug 31, 2026
Merged

fix(math): reduce Bézout coefficient modulo irreducible polynomial in gfExtendedEuclideanWithTrace (#1715)#1811
csxark merged 1 commit into
csxark:mainfrom
nayanraj864-cmyk:fix/gf-extended-euclidean-reduction-1715

Conversation

@nayanraj864-cmyk

Copy link
Copy Markdown
Contributor

Pull Request

Description

Fixes issue #1715 by applying polynomial modulo reduction (gfDivide(s0, modulus).r) to the Bézout coefficient $s_0$ in gfExtendedEuclideanWithTrace. This guarantees that inverseHex outputs a canonical 2-digit uppercase 8-bit hex string in $\text{GF}(2^8)$ matching gfInverse(a) across all non-zero field elements.


Related Issue

Closes #1715


Scope

  • Cipher module (lib/cipher/**, lib/math/**)
  • Visualizer/route (app/**, components/**)
  • Worker/protocol (lib/workers/**, hooks/use*Worker.ts)
  • Documentation only (docs/**, *.md, MDX content)
  • Security fix (CSP, key handling, sanitization, dependency CVE)
  • Test-only (tests/**)
  • Config/chore (build, deps, CI)

Changes Made

  • Galois Field Math: Applied const finalS = gfDivide(s0, modulus).r in gfExtendedEuclideanWithTrace inside lib/math/galoisField.ts after the Euclidean loop completes.
  • Hex Formatting: Formatted finalS as a 2-character uppercase hex string (padStart(2, '0').toUpperCase()).
  • Unit Testing: Added unit tests in tests/math/galoisField.test.ts verifying gfExtendedEuclideanWithTrace matches gfInverse for all non-zero elements $a \in [1 \dots 255]$ across 0x11b, 0x11d, and 0x12d field polynomials.

Testing

  • Unit tests added/updated for every code path changed (not just the happy path).
  • npm test passes locally.
  • npm run typecheck passes locally.
  • npm run lint passes locally.
  • Coverage on any touched lib/math/** file stays at or above 80%.
  • E2E/a11y tests added if a route or interactive component changed.

Simulation vs. Live Data

  • I have read the Simulation vs. Live Data Policy: docs/simulation-vs-live-data-policy.md
  • This change does not describe, label, or imply that a simulated operation (reduced parameters, mocked peer, synthetic randomness) is a verified or real cryptographic operation, in code, UI copy, or this PR description.

Screenshots

N/A (Galois Field Polynomial Modulo Reduction & Trace Formatting)


Checklist

  • My code follows the project guidelines.
  • I have tested my changes.
  • I have updated the documentation if required.
  • My changes address the related issue.
  • This PR focuses on a single issue.

Applicable Checklist

  • New cipher/math utility -> Contribution Guidelines: docs/contribution-checklists.md

Architecture Review Checklist

  • Existing shared abstractions: lib/math/galoisField.ts
  • Existing persistence mechanism: Trace state generation
  • Existing operation state machine: Extended Euclidean algorithm loop
  • Existing authorization boundary: Galois field math library
  • Existing error model: N/A
  • Existing telemetry/audit mechanism: tests/math/galoisField.test.ts

Additional Notes

All Galois Field math unit tests (npx vitest run tests/math/galoisField.test.ts) passed cleanly.

… gfExtendedEuclideanWithTrace (csxark#1715)

- Apply polynomial modulo reduction (gfDivide(s0, modulus).r) after Extended Euclidean algorithm loop in lib/math/galoisField.ts
- Format inverseHex as 2 uppercase hex digits, guaranteeing canonical 8-bit element representation in GF(2^8)
- Add unit test coverage in tests/math/galoisField.test.ts asserting EEA inverseHex matches gfInverse for all non-zero elements [1..255] across field polynomials (0x11b, 0x11d, 0x12d)
@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@nayanraj864-cmyk is attempting to deploy a commit to the csxark's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Thank You for Your Contribution

Hello @nayanraj864-cmyk,

Thank you for submitting a Pull Request to CryptoViz. We appreciate the time and effort you've invested in contributing to the project.

Your Pull Request has been received successfully and will be reviewed by the maintainers as soon as possible.

📋 Pull Request Checklist

  • ✅ Linked the related issue
  • ✅ No merge conflicts
  • ✅ Synced with the latest main branch
  • ✅ Build passes successfully
  • ✅ All tests pass

Ensuring these requirements are met helps streamline the review process and enables maintainers to review your contribution more efficiently.

❤️ Support CryptoViz

If you find CryptoViz helpful, consider supporting the project by:

  • ⭐ Starring the repository
  • 🍴 Forking the repository
  • 👤 Following Ark on GitHub
  • 💼 Connecting on LinkedIn
  • 🌐 Visiting the Portfolio

Your support helps increase the project's visibility and encourages continued development. Thank you for being a part of the CryptoViz community!

Thank you once again for contributing to CryptoViz. We appreciate your support and look forward to reviewing your contribution.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 23 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c5635bb-6e42-40d8-aa1c-e5a2fffa5505

📥 Commits

Reviewing files that changed from the base of the PR and between 24f6111 and dee3c88.

📒 Files selected for processing (2)
  • lib/math/galoisField.ts
  • tests/math/galoisField.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@csxark csxark added ECSoC26 Elite Coders Summer of Code 2026 and removed needs review labels Aug 31, 2026
@csxark
csxark merged commit 0960a27 into csxark:main Aug 31, 2026
4 of 10 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Pull Request Merged

Hello @nayanraj864-cmyk,

Thank you for your contribution to CryptoViz. Your Pull Request has been reviewed and successfully merged into the project.

We sincerely appreciate the time and effort you invested in improving the project. Contributions like yours help make CryptoViz better for the entire community.

We look forward to your future contributions and hope to collaborate with you again.

❤️ Support CryptoViz

If you find CryptoViz helpful, consider supporting the project by:

  • ⭐ Starring the repository
  • 🍴 Forking the repository
  • 👤 Following Ark on GitHub
  • 💼 Connecting on LinkedIn
  • 🌐 Visiting the Portfolio

Your support helps increase the project's visibility and encourages continued development. Thank you for being a part of the CryptoViz community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ECSoC26-SPAM ECSoC26 Elite Coders Summer of Code 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CRYPTO/MATH] gfExtendedEuclideanWithTrace Emits Unreduced Polynomial in inverseHex

2 participants