Update of /project/crypticl/cvsroot/crypticl/src In directory clnet:/tmp/cvs-serv8087
Added Files: sha256.lisp Log Message: Starting SHA-256.
--- /project/crypticl/cvsroot/crypticl/src/sha256.lisp 2007/01/06 12:58:08 NONE +++ /project/crypticl/cvsroot/crypticl/src/sha256.lisp 2007/01/06 12:58:08 1.1 ;;;;-*-lisp-*- ;;;; The Crypticl cryptographic library. ;;;; ;;;; Description: The SHA-256 hash algorithm ;;;; Author: Taale Skogan ;;;; Distribution: See the accompanying file LICENSE.
;;; Based on the reference [1] ;;; ;;; [1] FIPS 180-2 "Secure Hash Standard"
(in-package crypticl)
;;; SHA-256 Constants ;;; SHA-256 uses a sequence of sixty-four constant 32-bit words (defvar *sha256-constants* (make-array 64 :element-type '(unsigned-byte 32) :initial-contents '(#x428a2f98 #x71374491 #xb5c0fbcf #xe9b5dba5 #x3956c25b #x59f111f1 #x923f82a4 #xab1c5ed5 #xd807aa98 #x12835b01 #x243185be #x550c7dc3 #x72be5d74 #x80deb1fe #x9bdc06a7 #xc19bf174 #xe49b69c1 #xefbe4786 #x0fc19dc6 #x240ca1cc #x2de92c6f #x4a7484aa #x5cb0a9dc #x76f988da #x983e5152 #xa831c66d #xb00327c8 #xbf597fc7 #xc6e00bf3 #xd5a79147 #x06ca6351 #x14292967 #x27b70a85 #x2e1b2138 #x4d2c6dfc #x53380d13 #x650a7354 #x766a0abb #x81c2c92e #x92722c85 #xa2bfe8a1 #xa81a664b #xc24b8b70 #xc76c51a3 #xd192e819 #xd6990624 #xf40e3585 #x106aa070 #x19a4c116 #x1e376c08 #x2748774c #x34b0bcb5 #x391c0cb3 #x4ed8aa4a #x5b9cca4f #x682e6ff3 #x748f82ee #x78a5636f #x84c87814 #x8cc70208 #x90befffa #xa4506ceb #xbef9a3f7 #xc67178f2)))
(defmacro initial-sha256-hash-value (a b c d e f g h) "Initializes the state of the hash algorithm" `(setf ,a #x6a09e667 ,b #xbb67ae85 ,c #x3c6ef372 ,d #xa54ff53a ,e #x510e527f ,f #x9b05688c ,g #x1f83d9ab ,h #x5be0cd19))
;;; SHA-256 uses six logical functions, where each function operates on 32-bit ;;; words, which are represented as x, y, and z. The result of each function ;;; is a new 32-bit word. (defun sigma-0 (x) "ROTR 7(x) xor ROTR 18(x) xor SHR 3(x)" (logxor (right-rot-32 x 7) (right-rot-32 x 18) (ash x -3)))
(defun sigma-1 (x) "ROTR 17(x) xor ROTR 19(x) xor SHR 10(x)" (logxor (right-rot-32 x 17) (right-rot-32 x 17) (ash x -10)))
;;;(defun sha256-message-schedule (m) ;;; "Expand input array m with 512 bits = 16 32 bits words to array of 64 ;;;32 bits words" ;;; (let ((w (make-array 64 :element-type '(unsigned-byte 32)))) ;;; (dotimes (i 16 t) ;;; (setf (aref w i) (aref m i) ) ) ;;; (dotimes (i 48 t) ;;; (setf (aref w (+ i 16)) ;;; (left-rot-32 ( (aref w (- i 2)) (aref w (+ i 8)) ;;; (aref w (+ i 2)) (aref w (+ i ))) 1) )) ;;; w))