[crypticl-cvs] CVS update: crypticl/src/crypticl-package.lisp crypticl/src/diffie-hellman.lisp crypticl/src/dsa.lisp crypticl/src/keygenerator.lisp

Taale Skogan tskogan at common-lisp.net
Sun Nov 7 20:23:36 UTC 2004


Update of /project/crypticl/cvsroot/crypticl/src
In directory common-lisp.net:/tmp/cvs-serv19395/src

Modified Files:
	crypticl-package.lisp diffie-hellman.lisp dsa.lisp 
	keygenerator.lisp 
Log Message:
Adding to USERGUIDE. code cleanup.

Date: Sun Nov  7 21:23:33 2004
Author: tskogan

Index: crypticl/src/crypticl-package.lisp
diff -u crypticl/src/crypticl-package.lisp:1.3 crypticl/src/crypticl-package.lisp:1.4
--- crypticl/src/crypticl-package.lisp:1.3	Sun Nov  7 13:04:17 2004
+++ crypticl/src/crypticl-package.lisp	Sun Nov  7 21:23:33 2004
@@ -54,7 +54,7 @@
    decrypt
    print-external-symbols))
 
-
+;;(proclaim '(optimize (speed 2) (safety 1) (space 1) (debug 3)))
 (in-package crypticl)
 
 (defun load-package (&optional (path "") (fast-load nil))  


Index: crypticl/src/diffie-hellman.lisp
diff -u crypticl/src/diffie-hellman.lisp:1.3 crypticl/src/diffie-hellman.lisp:1.4
--- crypticl/src/diffie-hellman.lisp:1.3	Sun Nov  7 13:04:17 2004
+++ crypticl/src/diffie-hellman.lisp	Sun Nov  7 21:23:33 2004
@@ -51,6 +51,9 @@
     :p p
     :algorithm "Diffie-Hellman"))
 
+(defmethod copy ((obj Diffie-HellmanKey))
+  (make-Diffie-HellmanKey (g obj) (p obj)))
+
 (defun Diffie-Hellman-generate-key (bitsize)
   (let ((p (random-bignum-max-odd bitsize)))
     
@@ -78,23 +81,29 @@
 
 
 (defun test-dh ()
-  (let (y1
-	y2
-	s1
-	s2
+  (let (half-secret-1
+	half-secret-2
+	;; secret-1 and secret-2 should be equal in the end
+	secret-1 
+	secret-2
 	dh1
 	dh2
-	k1)
+	key-1
+	key-1-copy)
+    
     (setf dh1 (make-Diffie-Hellman))
     (setf dh2 (make-Diffie-Hellman))
-    (setf k1 (generate-key "Diffie-Hellman" 64))
-    (init-Diffie-Hellman dh1 k1)
-    (init-Diffie-Hellman dh2 k1)
-    (setf y1 (generate-random-Diffie-Hellman dh1))
-    (setf y2 (generate-random-Diffie-Hellman dh2))
-    (setf s1 (get-secret-Diffie-Hellman dh1 y2))
-    (setf s2 (get-secret-Diffie-Hellman dh2 y1))
-    (list s1 s2)))
+    (setf key-1 (generate-key 'Diffie-Hellman 64))
+    ;; Make a copy of the key. We need a copy because the init function
+    ;; stores state in the key object.
+    (setf key-1-copy (copy key-1))
+    (init-Diffie-Hellman dh1 key-1)
+    (init-Diffie-Hellman dh2 key-1-copy)
+    (setf half-secret-1 (generate-random-Diffie-Hellman dh1))
+    (setf half-secret-2 (generate-random-Diffie-Hellman dh2))
+    (setf secret-1 (get-secret-Diffie-Hellman dh1 half-secret-2))
+    (setf secret-2 (get-secret-Diffie-Hellman dh2 half-secret-1))
+    (list secret-1 secret-2)))
     
 
 (register-constructor 'Diffie-Hellman #'make-Diffie-Hellman)


Index: crypticl/src/dsa.lisp
diff -u crypticl/src/dsa.lisp:1.3 crypticl/src/dsa.lisp:1.4
--- crypticl/src/dsa.lisp:1.3	Sun Nov  7 13:04:17 2004
+++ crypticl/src/dsa.lisp	Sun Nov  7 21:23:33 2004
@@ -50,11 +50,11 @@
 
 
 (defun make-DSA (&key q pq-list generatep defaultp)
-  "Constructor for the DSA class. Note that this function is overloaded. Only one of the key word arguments should be used at a time.The default is to create an empty instance that can be initialized with the apropriate keys for signing or verifying. The typical usage will be to use init-verify with an authenticated copy of someone's public key to verify a document they have signed.
+  "Constructor for the DSA class. Note that this function is overloaded. Only one of the key word arguments should be used at a time. The default is to create an empty instance that can be initialized with the apropriate keys for signing or verifying. The typical usage will be to use init-verify with an authenticated copy of someone's public key to verify a document they have signed.
  
 -q: Will generate p and the rest of the key.
 -pq-list: A list containing primes q and p, where q|p-1. Will generate the rest of the key. Usefull for testing known primes given in the Digital Signature Standard documentation for example.
--generatep: A boolean. Will genrate a new key pair."
+-generatep: A boolean. Will generate a new key pair."
   (let (p g x
 	(L 1024))			;Modulus length
     (cond
@@ -273,7 +273,8 @@
     :public (make-DSAPublicKey p q g y)
     :private (make-DSAPrivateKey p q g x y)))
 
-(defun dsa-generate-keys ()
+(defun dsa-generate-keys (bitsize)
+  (declare (ignore bitsize))
   "Return a DSAKeyPair"
   (format t "~&Generating DSA keys, this may take some time...")
   (let ((alg (make-DSA :defaultp t)))


Index: crypticl/src/keygenerator.lisp
diff -u crypticl/src/keygenerator.lisp:1.3 crypticl/src/keygenerator.lisp:1.4
--- crypticl/src/keygenerator.lisp:1.3	Sun Nov  7 13:04:17 2004
+++ crypticl/src/keygenerator.lisp	Sun Nov  7 21:23:33 2004
@@ -2,7 +2,7 @@
 ;;;; The Crypticl cryptographic library.
 ;;;;
 ;;;; Description: Interface for key generation. 
-;;;; Author: Tåle Skogan <tasko at frisurf.no>
+;;;; Author: Tåle Skogan <tasko at frisurf.no>
 ;;;; Distribution:  See the accompanying file LICENSE.
 
 ;;TO DO
@@ -76,7 +76,7 @@
 	  (symbol (setf keytype value)))))))
   
 
-(defparameter *key-from-encoding-table* (make-hash-table))
+(defparameter *key-from-encoding-table* (make-hash-table :test #'equalp))
 
 (defun register-key-from-encoding (algorithm key-generator)
   "The key generator function must accept one argument, an encoding. The encoding can be used to recreate a key."
@@ -95,7 +95,7 @@
 
 
 
-(defparameter *key-generator-table* (make-hash-table))
+(defparameter *key-generator-table* (make-hash-table :test #'equalp))
 
 (defun register-key-generator (algorithm key-generator)
   "The key generator function must accept one argument, a bitsize. The bitsize may be ignored (e.g. DSA)." 





More information about the Crypticl-cvs mailing list