cl-ecc: A prototype implementation of ECC in Common Lisp
Recently I’ve been reading through these excellent books in my spare time:
- Understanding Cryptography by Christof Paar
- Practical Common Lisp by Peter Seibel (also available as a free eBook)
To ramp-up on both subjects with one shot I wrote an implementation of Elliptic Curve Crypto in Lisp. So far, it does EC versions of Diffie-Hellman, ElGamal and DSA. Some rudimentary testing was performed using the NIST-P192 curve and its corresponding ECDSA test vectors.
The package is available at GitHub in the krkhan/cl-ecc repository. Here’s a quick snippet of what the code looks like:
(defconstant *p17-curve* (make-instance 'Curve :a 2 :b 2 :p 17 :g (make-instance 'Point :x 5 :y 1) :n 19)) |
And an ECDSA with this curve:
(def-positive-test test-ecdsa () (let* ((c *p17-curve*) (bob-priv 3) (bob-pub (ecdh-gen-pub c bob-priv)) (msghash 8) (k 7) (sig (ecdsa-gen-sig c msghash bob-priv k))) (assert (sig-equalp sig (make-instance 'ECDSASig :r 0 :s 12))) (ecdsa-verify-sig c msghash sig bob-pub))) |
As a disclaimer — even though I know no one would be stupid enough to do so — please do not use this code in a production environment. It was written for recreational purposes by a hobbyist who is bad with cryptography and even worse with Lisp. On the other hand, if you have any suggestions/patches, feel free to create an issue/pull-request on GitHub.
Tags: cl-ecc, Code, Common Lisp, Cryptography, ECC, Elliptic Curve Cryptography, Git, Lisp, Security