Update of /project/crypticl/cvsroot/crypticl/src In directory clnet:/tmp/cvs-serv3774
Modified Files: test.lisp sha256.lisp sha.lisp rsa.lisp md5.lisp common.lisp Log Message: Be consistent and always use SHA-1, not SHA1.
--- /project/crypticl/cvsroot/crypticl/src/test.lisp 2007/01/17 22:00:52 1.6 +++ /project/crypticl/cvsroot/crypticl/src/test.lisp 2007/01/20 15:37:51 1.7 @@ -18,7 +18,7 @@
;; Simulate the author signing the code and creating a code certificate. ;; The certificate is represented by (signer,r,s, codehash) where r and s - ;; is the algorithm specific signature part, in this case DSA with SHA1. + ;; is the algorithm specific signature part, in this case DSA with SHA-1. (setf codehash (with-open-file (str path :direction :input) (sha1-on-octet-stream str))) @@ -48,7 +48,7 @@
(defun run-tests() - (test-SHA1) + (test-SHA-1) (test-MD5) (test-AES) (test-RSA) --- /project/crypticl/cvsroot/crypticl/src/sha256.lisp 2007/01/18 21:50:35 1.8 +++ /project/crypticl/cvsroot/crypticl/src/sha256.lisp 2007/01/20 15:37:51 1.9 @@ -270,7 +270,7 @@ (h obj) (32-add (h obj) hh))))
-;;; TODO identical to SHA1 method i sha.lisp so reuse +;;; TODO identical to SHA-1 method i sha.lisp so reuse (defmethod fill-vector ((obj SHA-256) return-vector octet-vector start) "Return the next 512 bits for hashing.
--- /project/crypticl/cvsroot/crypticl/src/sha.lisp 2007/01/18 21:50:35 1.9 +++ /project/crypticl/cvsroot/crypticl/src/sha.lisp 2007/01/20 15:37:51 1.10 @@ -199,7 +199,7 @@ ;;;;;;; ;;; CLOS
-(defclass SHA1 (Hash) +(defclass SHA-1 (Hash) ((octet-count :accessor octet-count ;octets processed so far :initform 0) (leftover-octets :accessor leftover-octets ;unprocessed octets @@ -215,7 +215,7 @@ (e :accessor e)))
-(defmethod fill-vector ((obj SHA1) return-vector octet-vector start) +(defmethod fill-vector ((obj SHA-1) return-vector octet-vector start) "Return a 16 * 32 bit vector filled with leftover octets from previous rounds and octets from the input vector. We know that we have at least 64 bytes" (let ((offset 0) ;offset in the tmp vevtor v. (used 0) ;Num octets used from input vector. @@ -253,7 +253,7 @@ (+ start used)))
-(defmethod store-state ((obj SHA1) octet-vector offset end octet-count) +(defmethod store-state ((obj SHA-1) octet-vector offset end octet-count) "Store state between calls to update." (let ((leftover-offset (leftover-count obj)) (octets-left (- end offset))) @@ -268,7 +268,7 @@ (setf (leftover-count obj) (+ leftover-offset octets-left))))
-(defmethod sha1-add-octet-vector ((obj SHA1) octet-vector start end) +(defmethod sha1-add-octet-vector ((obj SHA-1) octet-vector start end) (let ((vec (make-array 16 :element-type '(unsigned-byte 32))) (input-size (- end start)) (offset start)) @@ -293,7 +293,7 @@ (e obj) (32-add (e obj) ee))))
-(defmethod sha1-final ((obj SHA1)) +(defmethod sha1-final ((obj SHA-1)) (let ((vec (make-array 16 :element-type '(unsigned-byte 32))) (buffer-filler (make-buffer-filler @@ -310,7 +310,7 @@ (reset obj))))
-(defmethod reset ((obj SHA1)) +(defmethod reset ((obj SHA-1)) (initialize-sha1-state (a obj) (b obj) (c obj) (d obj) (e obj)) (setf (octet-count obj) 0 (leftover-count obj) 0)) @@ -319,15 +319,15 @@ ;;;;;;;; ;;; CLOS API
-(defun make-SHA1 () - "Constructor for the SHA1 class" - (let ((obj (make-instance 'SHA1 :algorithm "SHA1"))) +(defun make-SHA-1 () + "Constructor for the SHA-1 class" + (let ((obj (make-instance 'SHA-1 :algorithm "SHA-1"))) (initialize-sha1-state (a obj) (b obj) (c obj) (d obj) (e obj)) obj))
-(defmethod hash ((obj SHA1) &optional data (start 0) (end (length data))) - "Return SHA1 hash. Note that calling hash on an empty object or a second time on the same object makes no sense. The value returned in both cases is the initial state of the SHA-1 algorithm." +(defmethod hash ((obj SHA-1) &optional data (start 0) (end (length data))) + "Return SHA-1 hash. Note that calling hash on an empty object or a second time on the same object makes no sense. The value returned in both cases is the initial state of the SHA-1 algorithm." (when (and (fresh obj) (not data)) (return-from hash nil)) (when data @@ -339,9 +339,9 @@ (sha1-final obj))
-(defmethod update ((obj SHA1) (octet-vector vector) +(defmethod update ((obj SHA-1) (octet-vector vector) &optional (start 0) (end (length octet-vector))) - "Add octets to SHA1 hash object. Get hash value by calling hash." + "Add octets to SHA-1 hash object. Get hash value by calling hash." (sha1-add-octet-vector obj octet-vector start end) (setf (fresh obj) nil))
@@ -349,10 +349,10 @@ ;;;;;;;; ;;; Low level API
-(defmethod hash-stream ((obj SHA1) (s stream)) +(defmethod hash-stream ((obj SHA-1) (s stream)) (sha1-on-octet-stream s))
-(defmethod hash-string ((obj SHA1) (str string)) +(defmethod hash-string ((obj SHA-1) (str string)) (sha1-on-string str))
(defun sha1-on-string (string) @@ -377,7 +377,7 @@ ;;;;;;;; ;;; Test suite
-(defun test-SHA1 (&key test-long) +(defun test-SHA-1 (&key test-long) "Test vector 1 and 2 are taken from reference FIPS 180-2." (let ((test-list (list @@ -396,7 +396,7 @@ (sha1-on-octet-vector in)) ex)() "sha1 test for input string ~A~%" in)
- (let ((obj (make-SHA1))) + (let ((obj (make-SHA-1))) ;; Test hash only. (assert (string= (octet-vector-to-hex-string (hash obj in)) ex) () @@ -416,4 +416,4 @@ (format t "Done testing long vector.~%"))))
-(register-constructor 'SHA1 #'make-SHA1) \ No newline at end of file +(register-constructor 'SHA-1 #'make-SHA-1) \ No newline at end of file --- /project/crypticl/cvsroot/crypticl/src/rsa.lisp 2007/01/18 21:50:37 1.7 +++ /project/crypticl/cvsroot/crypticl/src/rsa.lisp 2007/01/20 15:37:51 1.8 @@ -270,27 +270,27 @@
;;;;;;;;;;;; -;;; Signatures SHA1withRSA +;;; Signatures SHA-1withRSA
-(defclass SHA1withRSA (Signature) +(defclass SHA-1withRSA (Signature) ((key :accessor key :initarg :key)) - (:documentation "A class for digital signatures using RSA and SHA1.")) + (:documentation "A class for digital signatures using RSA and SHA-1."))
-(defun make-SHA1withRSA () +(defun make-SHA-1withRSA () "Constructor. 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. " - (make-instance 'SHA1withRSA)) + (make-instance 'SHA-1withRSA))
-(defmethod init-sign ((obj SHA1withRSA) (private-key RSAPrivateKey)) +(defmethod init-sign ((obj SHA-1withRSA) (private-key RSAPrivateKey)) "Initialize for signing." (setf (key obj) private-key))
-(defmethod init-verify ((obj SHA1withRSA) (public-key RSAPublicKey)) +(defmethod init-verify ((obj SHA-1withRSA) (public-key RSAPublicKey)) "Initialize instance for verifying. " (setf (key obj) public-key))
-(defmethod sign ((obj SHA1withRSA) message &key message-hash) +(defmethod sign ((obj SHA-1withRSA) message &key message-hash) "Sign a message and return the signature (s). Input is either the message as byte array message or a hash of the message, message-hash. Use nil for the message to choose the message-hash variant." (let* ((key (key obj)) (cipher (new-instance (algorithm key)))) @@ -302,7 +302,7 @@ (sha1-on-string message)) (t (sha1-on-octet-vector message))))))))
-(defmethod verify ((obj SHA1withRSA) signature message &key message-hash) +(defmethod verify ((obj SHA-1withRSA) signature message &key message-hash) "Verify a DSA signature s for a message. Input is either the message as byte array message or a hash of the message, message-hash. Use nil for the message to choose the message-hash variant." (let* ((sig (first signature)) (key (key obj)) @@ -507,7 +507,7 @@
(register-constructor 'RSA #'make-RSA) -(register-constructor 'SHA1withRSA #'make-SHA1withRSA) +(register-constructor 'SHA-1withRSA #'make-SHA-1withRSA) (register-key-generator 'RSA #'rsa-generate-keys) (register-key-from-encoding 'RSAPublicKey #'make-RSAPublicKey-from-encoding) (register-key-from-encoding 'RSAPrivateKey #'make-RSAPrivateKey-from-encoding) --- /project/crypticl/cvsroot/crypticl/src/md5.lisp 2007/01/18 21:50:37 1.6 +++ /project/crypticl/cvsroot/crypticl/src/md5.lisp 2007/01/20 15:37:51 1.7 @@ -144,7 +144,7 @@ if there is more data. It returns nil if all data including padding and data length has been returned.
-This is almost identical to the SHA1 function sha1-make-buffer-filler, except for the order (big-endian vs little-endian) the octets are stored in. +This is almost identical to the SHA-1 function sha1-make-buffer-filler, except for the order (big-endian vs little-endian) the octets are stored in.
The buffer-filler is a state-machine with four states. :done, :data, :length and :zeropad. The initial state is :data. When there is no more data, #x80 is returned and the new state is either :write-length (if current word is 13 and current byte is 3) else :zeropad. If we enter :write-length we write the length in the last two 32 bit words and enter :done. In state :zeropad we write zeros until we reach word 13 and byte 3 and then enter :write-length. When we reach the :done state, the next call will return nil." (let ((state :data) --- /project/crypticl/cvsroot/crypticl/src/common.lisp 2007/01/18 21:37:02 1.8 +++ /project/crypticl/cvsroot/crypticl/src/common.lisp 2007/01/20 15:37:51 1.9 @@ -79,12 +79,12 @@ :report "Try another algorithm." :interactive (lambda () (format t "~&New algorithm: ") - ;;(format t "(use 'SHA1 or SHA1, not "SHA1"): ") + ;;(format t "(use 'SHA-1 or SHA-1, not "SHA-1"): ") (list (read))) (typecase value - (cons (setf algorithm (second value))) ;input 'SHA1 - (string (setf algorithm value)) ;input "SHA1" - (symbol (setf algorithm value))))))) ;input SHA1 + (cons (setf algorithm (second value))) ;input 'SHA-1 + (string (setf algorithm value)) ;input "SHA-1" + (symbol (setf algorithm value))))))) ;input SHA-1
(defun load-algorithm (&optional (path "des.lisp"))