[ANN] CryptoGroups.jl: A Versatile, Type-Safe Cryptographic Group Library

Hello, everyone :partying_face:

I’m thrilled to announce the release of CryptoGroups.jl, a package that brings a versatile and type-safe implementation of cryptographic groups to Julia. This library has been a long-term project, and it has been registered for four years already, but it was not accessible on its own and was mainly used as a dependency for CryptoSignatures.jl and ShuffleProofs.jl. Now, after significant refinements and experiences learned, I have arrived at a codebase I can document coherently, and I see its viability for new souls tinkering with academic and aspiring production environments with a lean and safe API.

At its core, CryptoGroups.jl offers a polymorphic implementation of cryptographic groups using type parameter values similar to how Mods.jl works. It leverages Julia’s type system to ensure strong type safety, allowing operations only between elements of the same group and validating values during deserialisation in the constructors. The package supports various group types, including modular prime groups and elliptic curves over prime and binary fields as specified in FIPS 186-4 (Weierstrass, Koblitz, and Pseudorandom curves).

Here’s a glimpse of what you can do with CryptoGroups.jl:

using CryptoGroups

# Create a modular prime group
G = @PGroup{p = 23, q = 11}
g = G(2)

# Create an elliptic curve group
E = @ECGroup{P_192}
h = E() # uses generator from specification

# Perform group operations
@assert g^3 * g^5 / g^2 == g^6
@assert h^(order(E) - 1) * h == one(E)

# Serialize and deserialize
@assert g == G(octet(g)) == G(value(g))

The package documentation provides examples of DSA, Key Encapsulation Mechanism, ElGamal CryptoSystem, and Knowledge proofs, showcasing the library’s versatility. An interesting experiment is the implementation of Reed-Solomon error correction using a polynomial binary extension field, further demonstrating the package’s versatility for field arithmetics.

While we prioritise clarity and type safety, it’s important to note that the current implementation is not optimised for performance and doesn’t implement constant-time arithmetic operations. There is enormous potential for implementing projective coordinates, Mersenne primes, and specific optimisations for binary curves and fields, which is exciting to tackle. Furthermore, the abstractions made internally are made so each of those things can be addressed separately. Still, it does feel like doing them puts work in a void, as the mainstream is now about Rust and post-quantum cryptography, which introduces unnecessary complexities. Hence, implementing optimisations depends on the potential use the Julia community and newcomers may have.

Despite these current limitations, CryptoGroups.jl offers excellent ergonomics and ease of use, making it a valuable tool for education, prototyping, and certain production scenarios where its strengths outweigh the performance limitations.

13 Likes