This is a pure-Rust implementation of the Curve25519/X25519 elliptic curve. It's a constant-time algorithm, transliterated from the provided C as I worked through the superb explanatory text:
It's a pretty faithful mapping of the C code, with some minor amendments. Notably, I've re-ordered the out buffer to come last in the function signatures, so watch out with your function calls! To be more idiomatic, you could impl methods on a FieldElem, if desired.
Note that the code was handwritten (no LLMs were harmed in the making of).
Warning
It should go without saying, but please don't use this for real-world applications. The code here is purely for educative purposes.