Skip to content

erhant/crypts

Repository files navigation

crypts

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

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.

Usage

TODO

Testing

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 # alias

Tip

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 Notebook

The 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.

Building

We use Bun as a builder, and dts-bundle-generator for types.

bun run build
bun b # alias

Examples

See several examples:

Styling

Check the formatting and lint everything with the following commands:

bun format
bun lint
bun style # does both

Resources

This would not have been possible without the amazing resources out there:

About

A zero-dependency library for cryptography, mostly self-educational.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published