Merge pull request #217 from haskell-crypto/hash-use-block

Hash: use Block instead of UArray to reduce memory usage
This commit is contained in:
Vincent Hanquez 2018-02-05 14:34:04 +00:00 committed by GitHub
commit 41d610fb18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 20 deletions

View File

@ -10,13 +10,15 @@ compiler: ghc-8.4 ghc-8.4-alpha2
option: testdeps extradep=QuickCheck-2.11.3 extradep=ansi-terminal-0.8.0.1 extradep=async-2.1.1.1 extradep=call-stack-0.1.0 extradep=clock-0.7.2 extradep=optparse-applicative-0.14.0.0 extradep=random-1.1 extradep=tagged-0.8.5 extradep=unbounded-delays-0.1.1.0 extradep=tasty-1.0.0.1 extradep=tasty-hunit-0.10.0.1 extradep=tasty-kat-0.0.3 extradep=tasty-quickcheck-0.9.2 extradep=ansi-wl-pprint-0.6.8.2 extradep=colour-2.3.4 extradep=tf-random-0.5 extradep=transformers-compat-0.5.1.4 extradep=primitive-0.6.3.0 allow-newer option: testdeps extradep=QuickCheck-2.11.3 extradep=ansi-terminal-0.8.0.1 extradep=async-2.1.1.1 extradep=call-stack-0.1.0 extradep=clock-0.7.2 extradep=optparse-applicative-0.14.0.0 extradep=random-1.1 extradep=tagged-0.8.5 extradep=unbounded-delays-0.1.1.0 extradep=tasty-1.0.0.1 extradep=tasty-hunit-0.10.0.1 extradep=tasty-kat-0.0.3 extradep=tasty-quickcheck-0.9.2 extradep=ansi-wl-pprint-0.6.8.2 extradep=colour-2.3.4 extradep=tf-random-0.5 extradep=transformers-compat-0.5.1.4 extradep=primitive-0.6.3.0 allow-newer
option: gaugedeps extradep=gauge-0.2.1 option: gaugedeps extradep=gauge-0.2.1
option: basementmin extradep=basement-0.0.6 extradep=foundation-0.0.19 extradep=memory-0.14.14
# builds # builds
build: ghc-7.8 nohaddock extradep=basement-0.0.6 extradep=foundation-0.0.19 extradep=memory-0.14.14 gaugedeps build: ghc-7.8 basementmin gaugedeps nohaddock
build: ghc-8.2 gaugedeps build: ghc-8.2 basementmin gaugedeps
build: ghc-7.10 extradep=basement-0.0.6 extradep=foundation-0.0.19 extradep=memory-0.14.14 gaugedeps build: ghc-7.10 basementmin gaugedeps
build: ghc-8.0 gaugedeps build: ghc-8.0 basementmin gaugedeps
build: ghc-8.0 os=osx gaugedeps build: ghc-8.0 basementmin gaugedeps os=osx
build: ghc-8.4 extradep=basement-0.0.6 extradep=memory-0.14.14 extradep=foundation-0.0.19 testdeps gaugedeps extradep=vector-0.12.0.1 build: ghc-8.4 basementmin testdeps gaugedeps extradep=vector-0.12.0.1
# packages # packages
package: '.' package: '.'

View File

@ -1,4 +1,4 @@
# ~*~ auto-generated by haskell-ci with config : 808ff5e84bd5804eaf848c1b7027d5fc386efd9edcf8d234090190900b1293df ~*~ # ~*~ auto-generated by haskell-ci with config : 5bc659023c72919bd64a856cc98a6b681c8180a770cee29b5b1e33698264f127 ~*~
# Use new container infrastructure to enable caching # Use new container infrastructure to enable caching
sudo: false sudo: false
@ -54,7 +54,7 @@ script:
export HADDOCK_OPTs="--no-haddock" export HADDOCK_OPTs="--no-haddock"
;; ;;
ghc-8.2) ghc-8.2)
echo "{ resolver: lts-10.4, packages: [ '.' ], extra-deps: [ gauge-0.2.1 ], flags: {} }" > stack.yaml echo "{ resolver: lts-10.4, packages: [ '.' ], extra-deps: [ basement-0.0.6, foundation-0.0.19, memory-0.14.14, gauge-0.2.1 ], flags: {} }" > stack.yaml
export HADDOCK_OPTs="--haddock --no-haddock-deps" export HADDOCK_OPTs="--haddock --no-haddock-deps"
;; ;;
ghc-7.10) ghc-7.10)
@ -62,15 +62,15 @@ script:
export HADDOCK_OPTs="--haddock --no-haddock-deps" export HADDOCK_OPTs="--haddock --no-haddock-deps"
;; ;;
ghc-8.0) ghc-8.0)
echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ gauge-0.2.1 ], flags: {} }" > stack.yaml echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.6, foundation-0.0.19, memory-0.14.14, gauge-0.2.1 ], flags: {} }" > stack.yaml
export HADDOCK_OPTs="--haddock --no-haddock-deps" export HADDOCK_OPTs="--haddock --no-haddock-deps"
;; ;;
ghc-8.0) ghc-8.0)
echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ gauge-0.2.1 ], flags: {} }" > stack.yaml echo "{ resolver: lts-9.21, packages: [ '.' ], extra-deps: [ basement-0.0.6, foundation-0.0.19, memory-0.14.14, gauge-0.2.1 ], flags: {} }" > stack.yaml
export HADDOCK_OPTs="--haddock --no-haddock-deps" export HADDOCK_OPTs="--haddock --no-haddock-deps"
;; ;;
ghc-8.4) ghc-8.4)
echo "{ setup-info: { ghc: { \"linux32-nopie\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-i386-deb8-linux.tar.xz\", sha256: \"be1a3b5de9f671199533d22f2810d9b62c6392b32b39833cd384a094566703c6\" } }, \"windows32\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-i386-unknown-mingw32.tar.xz\", sha256: \"3f4b9291ad35d89ca7b3561312a4329545aedceb5c4c8c5c4cf01550037376a1\" } }, \"linux64\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-deb8-linux.tar.xz\", sha256: \"55b54bce14661c19288c3413b8fab95d2b7fae407986323c7f0b6a732bec6a38\" } }, \"linux64-tinfo\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-deb8-linux.tar.xz\", sha256: \"55b54bce14661c19288c3413b8fab95d2b7fae407986323c7f0b6a732bec6a38\" } }, \"linux64-tinfo6\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-fedora27-linux.tar.xz\", sha256: \"47c7e4350c9560f984bde75b243aa10c91e37494152d87d20f84fcee857338ef\" } }, \"linux64-tinfo-nopie\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-fedora27-linux.tar.xz\", sha256: \"47c7e4350c9560f984bde75b243aa10c91e37494152d87d20f84fcee857338ef\" } }, \"linux64-nopie\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-deb8-linux.tar.xz\", sha256: \"55b54bce14661c19288c3413b8fab95d2b7fae407986323c7f0b6a732bec6a38\" } }, \"windows64\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-unknown-mingw32.tar.xz\", sha256: \"93dd7f80e3c645b79a91f3023046144ec88927961a3443019034e2893de43752\" } }, \"macosx\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-apple-darwin.tar.xz\", sha256: \"b3119b255ab3d1a09fcf9919bddbbe2cd77f9175de14e4b23f20b40abe5edea1\" } } } }, resolver: ghc-8.4.0.20180118, compiler: ghc-8.4.0.20180118, compiler-check: match-exact, packages: [ '.' ], extra-deps: [ basement-0.0.6, memory-0.14.14, foundation-0.0.19, vector-0.12.0.1, QuickCheck-2.11.3, ansi-terminal-0.8.0.1, async-2.1.1.1, call-stack-0.1.0, clock-0.7.2, optparse-applicative-0.14.0.0, random-1.1, tagged-0.8.5, unbounded-delays-0.1.1.0, tasty-1.0.0.1, tasty-hunit-0.10.0.1, tasty-kat-0.0.3, tasty-quickcheck-0.9.2, ansi-wl-pprint-0.6.8.2, colour-2.3.4, tf-random-0.5, transformers-compat-0.5.1.4, primitive-0.6.3.0, gauge-0.2.1 ], flags: {}, allow-newer: true }" > stack.yaml echo "{ setup-info: { ghc: { \"linux32-nopie\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-i386-deb8-linux.tar.xz\", sha256: \"be1a3b5de9f671199533d22f2810d9b62c6392b32b39833cd384a094566703c6\" } }, \"windows32\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-i386-unknown-mingw32.tar.xz\", sha256: \"3f4b9291ad35d89ca7b3561312a4329545aedceb5c4c8c5c4cf01550037376a1\" } }, \"linux64\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-deb8-linux.tar.xz\", sha256: \"55b54bce14661c19288c3413b8fab95d2b7fae407986323c7f0b6a732bec6a38\" } }, \"linux64-tinfo\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-deb8-linux.tar.xz\", sha256: \"55b54bce14661c19288c3413b8fab95d2b7fae407986323c7f0b6a732bec6a38\" } }, \"linux64-tinfo6\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-fedora27-linux.tar.xz\", sha256: \"47c7e4350c9560f984bde75b243aa10c91e37494152d87d20f84fcee857338ef\" } }, \"linux64-tinfo-nopie\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-fedora27-linux.tar.xz\", sha256: \"47c7e4350c9560f984bde75b243aa10c91e37494152d87d20f84fcee857338ef\" } }, \"linux64-nopie\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-deb8-linux.tar.xz\", sha256: \"55b54bce14661c19288c3413b8fab95d2b7fae407986323c7f0b6a732bec6a38\" } }, \"windows64\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-unknown-mingw32.tar.xz\", sha256: \"93dd7f80e3c645b79a91f3023046144ec88927961a3443019034e2893de43752\" } }, \"macosx\": { \"8.4.0.20180118\": { url: \"https://downloads.haskell.org/~ghc/8.4.1-alpha2/ghc-8.4.0.20180118-x86_64-apple-darwin.tar.xz\", sha256: \"b3119b255ab3d1a09fcf9919bddbbe2cd77f9175de14e4b23f20b40abe5edea1\" } } } }, resolver: ghc-8.4.0.20180118, compiler: ghc-8.4.0.20180118, compiler-check: match-exact, packages: [ '.' ], extra-deps: [ vector-0.12.0.1, basement-0.0.6, foundation-0.0.19, memory-0.14.14, QuickCheck-2.11.3, ansi-terminal-0.8.0.1, async-2.1.1.1, call-stack-0.1.0, clock-0.7.2, optparse-applicative-0.14.0.0, random-1.1, tagged-0.8.5, unbounded-delays-0.1.1.0, tasty-1.0.0.1, tasty-hunit-0.10.0.1, tasty-kat-0.0.3, tasty-quickcheck-0.9.2, ansi-wl-pprint-0.6.8.2, colour-2.3.4, tf-random-0.5, transformers-compat-0.5.1.4, primitive-0.6.3.0, gauge-0.2.1 ], flags: {}, allow-newer: true }" > stack.yaml
export HADDOCK_OPTs="--haddock --no-haddock-deps" export HADDOCK_OPTs="--haddock --no-haddock-deps"
;; ;;
esac esac

View File

@ -42,8 +42,8 @@ module Crypto.Hash
) where ) where
import Basement.Types.OffsetSize (CountOf (..)) import Basement.Types.OffsetSize (CountOf (..))
import Basement.UArray (UArray, new, unsafeFreeze) import Basement.Block (Block, unsafeFreeze)
import Basement.UArray.Mutable (copyFromPtr) import Basement.Block.Mutable (copyFromPtr, new)
import Control.Monad import Control.Monad
import Crypto.Internal.Compat (unsafeDoIO) import Crypto.Internal.Compat (unsafeDoIO)
import Crypto.Hash.Types import Crypto.Hash.Types
@ -115,10 +115,10 @@ digestFromByteString = from undefined
| B.length bs == (hashDigestSize alg) = Just $ Digest $ unsafeDoIO $ copyBytes bs | B.length bs == (hashDigestSize alg) = Just $ Digest $ unsafeDoIO $ copyBytes bs
| otherwise = Nothing | otherwise = Nothing
copyBytes :: ba -> IO (UArray Word8) copyBytes :: ba -> IO (Block Word8)
copyBytes ba = do copyBytes ba = do
muArray <- new count muArray <- new count
B.withByteArray ba $ \ptr -> copyFromPtr ptr count muArray B.withByteArray ba $ \ptr -> copyFromPtr ptr muArray 0 count
unsafeFreeze muArray unsafeFreeze muArray
where where
count = CountOf (B.length ba) count = CountOf (B.length ba)

View File

@ -20,7 +20,7 @@ import Crypto.Internal.Imports
import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes) import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes)
import qualified Crypto.Internal.ByteArray as B import qualified Crypto.Internal.ByteArray as B
import Foreign.Ptr (Ptr) import Foreign.Ptr (Ptr)
import Basement.UArray (UArray) import Basement.Block (Block)
import Basement.NormalForm (deepseq) import Basement.NormalForm (deepseq)
import GHC.TypeLits (Nat) import GHC.TypeLits (Nat)
@ -70,7 +70,7 @@ newtype Context a = Context Bytes
-- --
-- Creating a digest from a bytearray is also possible with function -- Creating a digest from a bytearray is also possible with function
-- 'Crypto.Hash.digestFromByteString'. -- 'Crypto.Hash.digestFromByteString'.
newtype Digest a = Digest (UArray Word8) newtype Digest a = Digest (Block Word8)
deriving (Eq,Ord,ByteArrayAccess) deriving (Eq,Ord,ByteArrayAccess)
instance NFData (Digest a) where instance NFData (Digest a) where

View File

@ -227,8 +227,8 @@ Library
Crypto.Internal.Nat Crypto.Internal.Nat
Build-depends: base >= 4.6 && < 5 Build-depends: base >= 4.6 && < 5
, bytestring , bytestring
, memory >= 0.14.10 , memory >= 0.14.14
, basement , basement >= 0.0.6
, ghc-prim , ghc-prim
ghc-options: -Wall -fwarn-tabs -optc-O3 -fno-warn-unused-imports ghc-options: -Wall -fwarn-tabs -optc-O3 -fno-warn-unused-imports
if os(linux) if os(linux)