-- | Extension stage of XSHA1. -- -- In SHA-1, it follows padding. XSHA1 doesn't pad, just zeros. module Data.Digest.XSHA1.Extend where import Data.Bits import qualified Data.Vector as V import Data.Vector (Vector,snoc,(!)) import Numeric.Taint.Word32 extend :: Vector N -> Vector N -- ^ Take a 16 DWORD list, and extend it to 80 DWORDS based on itself. extend xs = ex 0 xs where ex 64 xs = xs ex n xs = ex (n+1) (xs `snoc` step xs n) step xs = shift . compress . sample xs where sample :: Vector N -> Int -> [N] sample xs i = fmap ((xs !) . (+i)) [0,2,8,13] compress xs = N 0x1f .&. foldl1 xor xs shift :: N -> N shift x = lshift (N 1) x