A Bun-powered zero-dependency library for cryptography, for self-educational purposes mostly.
finite fields
Finite Fields
- Prime Field defines a finite field of prime order.
- Binary Field defines a finite field of order 2 with Boolean values & Boolean algebra.
- Field Extension defines an extension of an existing field using an irreducible polynomial.
polynomials
Polynomials
- Polynomials defines a polynomial with coefficients in a finite field.
- Lagrange Interpolation constructs a polynomial based on point evaluations.
- Shamir's Secret Sharing splits a given secret into
$n$ shares such that with at least$k$ of them the secret can be reconstructed.
elliptic curves
Elliptic Curves
- Short Weierstrass defines an elliptic curve in Short Weierstrass form with affine points, along with curve conversions.
- Montgomery defines an elliptic curve in Montgomery form with affine points, along with curve conversions.
- Twisted Edwards defines an elliptic curve in Twisted Edwards form with affine points, along with curve conversions.
numbers
Numbers
- Miller-Rabin probabilistically & efficiently checks if a number is prime.
- Tonelli-Shanks finds the square root of a quadratic residue in a finite field.
- Legendre Symbol tells whether a number is quadratic residue or quadratic non-residue.
TODO
We prepare our test cases using SageMath, and then try to match the results obtained there using our implementations. To run all tests, do:
bun run test
bun t # aliasTip
If you do not have Sage installed, but still would like to play around with the Sage code, fret not! We have prepared scripts for the Sagemath docker image:
bun sage:pull # pulls the image
bun sage:cli # opens Sage cli
bun sage:notebook # opens Jupyter NotebookThe containers will have volumes attached to the tests/data and tests/sage folders, so that the Sage code can directly write to the test data there.
We use Bun as a builder, and dts-bundle-generator for types.
bun run build
bun b # aliasSee several examples:
Check the formatting and lint everything with the following commands:
bun format
bun lint
bun style # does bothThis would not have been possible without the amazing resources out there: