Permalink
Browse files

builtin compilation for sha2,sha3 + switching to lazy bytestrings

implementation taken from plutus/language-plutus-core/src/Data/ByteString/Lazy/Hash.hs
  • Loading branch information...
jmchapman committed Jan 11, 2019
1 parent 37ef904 commit fca94462ed3045d3e7d3a138a9192531b22d6f6e
Showing with 7 additions and 4 deletions.
  1. +6 −3 Builtin/Constant/Type.lagda
  2. +1 −1 Declarative/Main.lagda
@@ -45,7 +45,10 @@ postulate
# What builtin operations should be compiled to if we compile to Haskell

\begin{code}
{-# FOREIGN GHC import qualified Data.ByteString as BS #-}
{-# FOREIGN GHC {-# LANGUAGE TypeApplications #-} #-}
{-# FOREIGN GHC import qualified Data.ByteString.Lazy as BS #-}
{-# FOREIGN GHC import qualified Data.ByteArray as B #-}
{-# FOREIGN GHC import Crypto.Hash (SHA256, SHA3_256, hashlazy) #-}
{-# COMPILE GHC ByteString = type BS.ByteString #-}
{-# COMPILE GHC length = toInteger . BS.length #-}

@@ -68,8 +71,8 @@ postulate
{-# COMPILE GHC append = BS.append #-}
{-# COMPILE GHC take = BS.take . fromIntegral #-}
{-# COMPILE GHC drop = BS.drop . fromIntegral #-}
-- TODO: sha2-256
-- TODO: sha3-256
{-# COMPILE GHC SHA2-256 = BS.fromStrict . B.convert . hashlazy @SHA256 #-}
{-# COMPILE GHC SHA3-256 = BS.fromStrict . B.convert . hashlazy @SHA3_256 #-}
-- TODO: verifySig
-- TODO: resizeByteString
-- no binding needed for equalsByteString
@@ -40,7 +40,7 @@ postulate

printByteString : ByteString -> String

{-# FOREIGN GHC import qualified Data.ByteString.Char8 as BS #-}
{-# FOREIGN GHC import qualified Data.ByteString.Lazy.Char8 as BS #-}
{-# COMPILE GHC str1 = BS.pack "Hello, " #-}
{-# COMPILE GHC str2 = BS.pack "world" #-}
{-# COMPILE GHC printByteString = T.pack . BS.unpack #-}

0 comments on commit fca9446

Please sign in to comment.