sha256

Pure Haskell SHA-256, HMAC-SHA256 as specified by RFC's 6234 and 2104.
git clone git://git.ppad.tech/sha256.git
Log | Files | Refs | README | LICENSE

HashLarge.hs (956B)


      1 {-# LANGUAGE OverloadedStrings #-}
      2 
      3 module Main where
      4 
      5 import qualified Crypto.Hash.SHA256 as SHA256
      6 import qualified Data.ByteString.Lazy as BL
      7 import qualified Data.ByteString.Builder as BSB
      8 import qualified Data.ByteString.Base16 as B16
      9 import System.Environment
     10 
     11 main :: IO ()
     12 main = do
     13   args <- getArgs
     14   case args of
     15     mode:[] ->
     16       if   mode == "make"
     17       then make
     18       else hash
     19     _ -> error "incorrect args"
     20 
     21 hash :: IO ()
     22 hash = do
     23   input <- BL.readFile "ppad-sha256-large.dat"
     24   let digest = B16.encode $ SHA256.hash_lazy input
     25   print digest
     26 
     27 make :: IO ()
     28 make = BL.writeFile "ppad-sha256-large.dat" big_input where
     29   big_input :: BL.ByteString
     30   big_input = go (16777216 :: Int) mempty where
     31     go j acc
     32       | j == 0 = BSB.toLazyByteString acc
     33       | otherwise =
     34           let nacc = acc <> BSB.lazyByteString
     35                 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno"
     36           in  go (pred j) nacc
     37