Permalink
Browse files

Polished ECC functions and made public

  • Loading branch information...
1 parent 9e99d82 commit b0a5d344941e705f3f98eff24df18446102ef59b @eadmund committed Jun 14, 2012
Showing with 33 additions and 14 deletions.
  1. +1 −0 ironclad.asd
  2. +11 −0 src/package.lisp
  3. +21 −14 src/public-key/ecc.lisp
View
@@ -118,6 +118,7 @@
:depends-on ("package")
:components
((:file "public-key")
+ (:file "ecc" :depends-on ("public-key"))
(:file "dsa" :depends-on ("public-key"))
(:file "rsa" :depends-on ("public-key"))))
(:module "prng"
View
@@ -45,6 +45,17 @@
#:sign-message #:verify-signature
#:encrypt-message #:decrypt-message
+ ;; elliptic curve primitives
+ #:ecc-point
+ #:ecc-curve
+ #:ecc-prime-curve
+ #:ecc-point-expt
+ #:ecc=
+ #:x
+ #:y
+ #:affine-point
+ #:homogeneous-point
+
;; signatures
#:make-dsa-signature
View
@@ -1,4 +1,4 @@
-;;;; ecc.lisp -- implementation of elliptical curve primitives
+;;;; ecc.lisp -- implementation of elliptic curve primitives
(in-package :crypto)
@@ -14,10 +14,14 @@
;;;; homogeneous or affine points in any function, but to always emit
;;;; homogeneous points. It is the user's responsibility to convert
;;;; back to affine if he wishes.
+;;;;
+;;;; Some sources refer to elliptic-curve addition and multiplication;
+;;;; others refer to multiplication and exponentiation. I follow RFC
+;;;; 6090 and use the latter terminology.
-(defclass elliptic-curve () ())
+(defclass ecc-elliptic-curve () ())
-(defclass prime-curve (elliptic-curve)
+(defclass ecc-prime-curve (ecc-elliptic-curve)
((prime :accessor prime
:initarg :prime)
(a :accessor ecc-a
@@ -66,8 +70,7 @@
(setf (x ap) (mod (* (x hp) inverse) prime)
(y ap) (mod (* (y hp) inverse) prime))))
-
-(defmethod initialize-instance :after ((curve prime-curve) &rest rest)
+(defmethod initialize-instance :after ((curve ecc-prime-curve) &rest rest)
(declare (ignore rest))
(with-slots (generator) curve
(setf generator
@@ -88,7 +91,7 @@
(defvar *p192*
(make-instance
- 'prime-curve
+ 'ecc-prime-curve
:prime #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF
:ecc-a -3
:ecc-b #x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1
@@ -99,7 +102,7 @@
(defvar *p224*
(make-instance
- 'prime-curve
+ 'ecc-prime-curve
:prime #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001
:ecc-a -3
:ecc-b #xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4
@@ -109,7 +112,7 @@
(defvar *p256*
(make-instance
- 'prime-curve
+ 'ecc-prime-curve
:prime #xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF
:ecc-a -3
:ecc-b #x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B
@@ -120,7 +123,7 @@
(defparameter *p384*
(make-instance
- 'prime-curve
+ 'ecc-prime-curve
:prime #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF
:ecc-a -3
:ecc-b #xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef
@@ -133,7 +136,7 @@
(defvar *p521*
(make-instance
- 'prime-curve
+ 'ecc-prime-curve
:prime #x1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
:ecc-a -3
:ecc-b #x051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd
@@ -149,9 +152,13 @@
(prime curve)))
(defun ecc= (x y)
- (or (and (eq x 'inf) (eq y 'inf))
- (and (= (first x) (first y))
- (= (second x) (second y)))))
+ (or (and (ecc-infinity-p x) (ecc-infinity-p y))
+ ;; only affine points can be compared to one another; a single
+ ;; point has multiple homogeneous representations
+ (let ((xx (change-class x 'affine-point))
+ (yy (change-class y 'affine-point)))
+ (and (= (x xx) (x yy))
+ (= (y xx) (y yy))))))
(defmethod ecc-invert-point ((p affine-point))
(if (eq p 'inf)
@@ -180,7 +187,7 @@
(zerop (z p))))
(defmethod ecc-point* ((p homogeneous-point) (q homogeneous-point))
- ;; yes, this is somewhat ugly: elliptical-curve point multiplication is
+ ;; yes, this is somewhat ugly: elliptic-curve point multiplication is
(assert (eq (curve p) (curve q)))
(let* ((curve (curve p))
(prime (prime curve))

0 comments on commit b0a5d34

Please sign in to comment.