mirror of https://github.com/voidlizard/hbs2
simple saltine tests
This commit is contained in:
parent
890f15cff6
commit
b44f83e6f7
|
@ -208,3 +208,50 @@ executable test-logger
|
||||||
, fast-logger
|
, fast-logger
|
||||||
|
|
||||||
|
|
||||||
|
executable test-saltine
|
||||||
|
import: shared-properties
|
||||||
|
import: common-deps
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
ghc-options:
|
||||||
|
-- -prof
|
||||||
|
-- -fprof-auto
|
||||||
|
|
||||||
|
other-modules:
|
||||||
|
|
||||||
|
-- other-extensions:
|
||||||
|
|
||||||
|
-- type: exitcode-stdio-1.0
|
||||||
|
hs-source-dirs: test
|
||||||
|
main-is: TestSaltine.hs
|
||||||
|
|
||||||
|
build-depends:
|
||||||
|
base, hbs2-core
|
||||||
|
, async
|
||||||
|
, attoparsec
|
||||||
|
, bytestring
|
||||||
|
, cache
|
||||||
|
, clock
|
||||||
|
, containers
|
||||||
|
, data-default
|
||||||
|
, data-textual
|
||||||
|
, directory
|
||||||
|
, hashable
|
||||||
|
, microlens-platform
|
||||||
|
, mtl
|
||||||
|
, mwc-random
|
||||||
|
, network
|
||||||
|
, network-ip
|
||||||
|
, prettyprinter
|
||||||
|
, random
|
||||||
|
, safe
|
||||||
|
, serialise
|
||||||
|
, stm
|
||||||
|
, streaming
|
||||||
|
, saltine
|
||||||
|
, text
|
||||||
|
, transformers
|
||||||
|
, uniplate
|
||||||
|
, vector
|
||||||
|
, fast-logger
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
import HBS2.Prelude
|
||||||
|
import HBS2.OrDie
|
||||||
|
import HBS2.Storage (calcChunks)
|
||||||
|
|
||||||
|
import Data.Traversable(forM)
|
||||||
|
import Data.Foldable(for_)
|
||||||
|
import System.TimeIt
|
||||||
|
import Crypto.Saltine (sodiumInit)
|
||||||
|
import Data.ByteString (ByteString)
|
||||||
|
import Data.ByteString qualified as BS
|
||||||
|
import Data.ByteString.Lazy qualified as LBS
|
||||||
|
import Crypto.Saltine.Core.SecretBox qualified as Symm
|
||||||
|
import Crypto.Saltine.Core.Box qualified as Asymm
|
||||||
|
import Crypto.Saltine.Core.Box (publicKey)
|
||||||
|
import Crypto.Saltine.Core.SecretBox (secretbox)
|
||||||
|
import System.Environment
|
||||||
|
import Safe
|
||||||
|
import Prettyprinter
|
||||||
|
import Data.Fixed
|
||||||
|
import System.Directory
|
||||||
|
|
||||||
|
defBlockSize = 256*1024
|
||||||
|
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
sodiumInit
|
||||||
|
|
||||||
|
f <- (headMay <$> getArgs) `orDie` "pass file to encrypt"
|
||||||
|
|
||||||
|
key <- Symm.newKey
|
||||||
|
nonce <- Symm.newNonce
|
||||||
|
|
||||||
|
kpair <- Asymm.newKeypair
|
||||||
|
nonce2 <- Asymm.newNonce
|
||||||
|
|
||||||
|
size <- getFileSize f
|
||||||
|
co <- LBS.readFile f
|
||||||
|
|
||||||
|
let chunks = calcChunks size defBlockSize
|
||||||
|
|
||||||
|
timeItNamed "read and encrypt" do
|
||||||
|
sizes <- forM chunks $ \(off,sz) -> do
|
||||||
|
let chu = LBS.take sz $ LBS.drop off co
|
||||||
|
let box = secretbox key nonce (LBS.toStrict chu)
|
||||||
|
pure (BS.length box)
|
||||||
|
|
||||||
|
let s = (realToFrac (sum sizes) - realToFrac size) / realToFrac size * 100 :: Fixed E6
|
||||||
|
print $ pretty (sum sizes) <> comma <+> pretty (show s)
|
||||||
|
putStrLn ""
|
||||||
|
|
||||||
|
putStrLn ""
|
||||||
|
|
||||||
|
|
||||||
|
timeItNamed "read and encrypt asymm" do
|
||||||
|
sizes <- forM chunks $ \(off,sz) -> do
|
||||||
|
let chu = LBS.take sz $ LBS.drop off co
|
||||||
|
box <- Asymm.boxSeal (publicKey kpair) (LBS.toStrict chu)
|
||||||
|
pure (BS.length box)
|
||||||
|
|
||||||
|
let s = (realToFrac (sum sizes) - realToFrac size) / realToFrac size * 100 :: Fixed E6
|
||||||
|
print $ pretty (sum sizes) <> comma <+> pretty (show s)
|
||||||
|
putStrLn ""
|
||||||
|
|
||||||
|
putStrLn ""
|
||||||
|
|
||||||
|
|
||||||
|
timeItNamed "just read" do
|
||||||
|
sizes <- forM chunks $ \(off,sz) -> do
|
||||||
|
let chu = LBS.take sz $ LBS.drop off co
|
||||||
|
pure (LBS.length chu)
|
||||||
|
|
||||||
|
let s = (realToFrac (sum sizes) - realToFrac size) / realToFrac size * 100 :: Fixed E6
|
||||||
|
print $ pretty (sum sizes) <> comma <+> pretty (show s)
|
||||||
|
putStrLn ""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue