A literate program in GWEB, written to teach
myself elliptic curves and their cryptography. A single .gw source yields both
the Go package elliptic and a typeset document (PDF, in Korean).
The trip has two destinations. One is Schoof's algorithm, which counts the points on a curve; the other is elliptic curve cryptography (ECDSA), which puts such curves to work. Along the way we pass through finite fields, polynomials and fast multiplication by NTT, division polynomials, and three attacks on the discrete logarithm.
Chapter (.gw) |
Contents |
|---|---|
fp.gw |
Arithmetic in the finite field uint64 ( |
poly.gw |
Polynomials in |
curve.gw |
The group law on big.Int (with MetaPost figures) |
divpoly.gw |
Division polynomials |
schoof.gw |
Counting points with the characteristic equation of Frobenius |
dlp.gw |
Shanks, Pollard |
ecdsa.gw |
Signing and verification on secp256k1 |
The lower layers (finite fields, polynomials) live or die by speed, so they use
uint64 and stay off the heap. The upper layers (curves, cryptography) must
handle 256-bit numbers, so they use big.Int. Schoof bridges the two worlds,
solving a problem about a large curve with fast arithmetic in a small field.
That is what cut the time for a 60-bit curve from days, in an older
big.Int-only implementation, to seconds.
make # tangle + typeset the document (PDF)
make tangle # elliptic.gw -> elliptic.go, elliptic_test.go
make test # go test ./...
make doc # elliptic.pdf (luatex, for the Korean text; figures in MetaPost)
make twill # elliptic-twill.pdf, a book-style edition with mini-indexes on each page, via gtwill
make clean # remove generated files (the .gw sources stay)Typesetting the document requires gweave/gtangle, luatex, and the
luamplib package, which draws the MetaPost figures during the TeX run. The GWEB
macros (kotexgweb.tex, gwebmac.tex) are found automatically in the installed
texmf tree.