packages feed

threefish 0.2 → 0.2.1

raw patch · 4 files changed

+37/−22 lines, 4 filesdep ~bytestring

Dependency ranges changed: bytestring

Files

Crypto/Threefish/Authenticated.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE OverloadedStrings #-} -- | Authenticated encryption using Skein for PRNG, KDF, stream cipher and MAC. module Crypto.Threefish.Authenticated (-    DecryptFailure (..), Encrypted, Plaintext, Block256, Nonce256,-    encrypt, decrypt, encrypt', decrypt', generateNonce, toBlock, fromBlock+    DecryptFailure (..), Encrypted, Plaintext, Block256, Nonce256, Key256,+    encrypt, decrypt, encrypt', decrypt', encryptBytes, decryptBytes,+    generateNonce, toBlock, fromBlock   ) where import Crypto.Threefish import Crypto.Threefish.Threefish256 (Block256(..))@@ -93,10 +94,16 @@ --   to the master key, with the key identifiers "crypt" and "mac" --   respectively, zero padded at the end until 32 bytes. encrypt :: Serialize a => Key256 -> a -> Encrypted a-encrypt k x = unsafePerformIO $ do+encrypt k x =  unsafePerformIO $ do   nonce <- generateNonce   return $! encrypt' k nonce (runPutLazy (put x)) +-- | Encrypt-then-MAC a lazy ByteString.+encryptBytes :: Key256 -> BSL.ByteString -> BSL.ByteString+encryptBytes k bs = unsafePerformIO $ do+  nonce <- generateNonce+  return $! runPutLazy $! put (encrypt' k nonce bs)+ -- | Decrypt and decode a message. Will fail if there is a MAC mismatch or if --   the message can't be decoded into the given data type. decrypt :: Serialize a => Key256 -> Encrypted a -> Either DecryptFailure a@@ -105,3 +112,11 @@   case runGetLazy get plaintext of     Right x  -> return x     Left err -> Left (NoDecode err)++-- | Verify and decrypt a lazy ByteString.+decryptBytes :: Key256 -> BSL.ByteString -> Either DecryptFailure Plaintext+decryptBytes k bs = do+  enc <- case runGetLazy get bs of+           Right x  -> return x+           Left err -> Left (NoDecode err)+  decrypt' k enc
Crypto/Threefish/Skein/StreamCipher.hs view
@@ -36,10 +36,10 @@   where     go n = unsafeInterleaveIO $ do       bs <- withForeignPtr c $ \ctx -> do-        allocaBytes 256 $ \ptr -> do-          skein256_output ctx n (n+8) ptr-          BS.packCStringLen (castPtr ptr, 256)-      bss <- go (n+8)+        allocaBytes 1024 $ \ptr -> do+          skein256_output ctx n (n+32) ptr+          BS.packCStringLen (castPtr ptr, 1024)+      bss <- go (n+32)       return $ bs : bss  keystream256 :: Key256 -> Nonce256 -> [BS.ByteString]@@ -51,7 +51,7 @@     BSL.fromChunks $ go (keystream256 k n) plaintext   where     go (ks:kss) msg = unsafePerformIO . unsafeInterleaveIO $ do-      case BSL.splitAt 256 msg of+      case BSL.splitAt 1024 msg of         (chunk, rest)           | BSL.null chunk ->             return []
Crypto/Threefish/Threefish256.hs view
@@ -17,19 +17,19 @@ import Foreign.ForeignPtr import System.IO.Unsafe -foreign import ccall "encrypt256" c_encrypt256 :: Ptr Word64-                                               -> Word64-                                               -> Word64-                                               -> Ptr Word64-                                               -> Ptr Word64-                                               -> IO ()+foreign import ccall unsafe "encrypt256" c_encrypt256 :: Ptr Word64+                                                      -> Word64+                                                      -> Word64+                                                      -> Ptr Word64+                                                      -> Ptr Word64+                                                      -> IO () -foreign import ccall "decrypt256" c_decrypt256 :: Ptr Word64-                                               -> Word64-                                               -> Word64-                                               -> Ptr Word64-                                               -> Ptr Word64-                                               -> IO ()+foreign import ccall unsafe "decrypt256" c_decrypt256 :: Ptr Word64+                                                      -> Word64+                                                      -> Word64+                                                      -> Ptr Word64+                                                      -> Ptr Word64+                                                      -> IO ()  newtype Block256 = Block256 BS.ByteString deriving Eq type Key256 = Block256
threefish.cabal view
@@ -1,5 +1,5 @@ name:                threefish-version:             0.2+version:             0.2.1 synopsis:            The Threefish block cipher and the Skein hash function for Haskell. description:         Implements 256 and 512 bit variants of Threefish and Skein. Skein is usable as a "normal" hash function as well as in Skein-MAC, as a cryptographically secure PRNG, as a stream cipher and as a key derivation function, all implemented according to the specifications of the Skein 1.3 paper. homepage:            http://github.com/valderman/threefish@@ -37,7 +37,7 @@     FunctionalDependencies   build-depends:     base >=4.6 && <5,-    bytestring >=0.10.2.0,+    bytestring >=0.10,     cereal >=0.3,     array >=0.4,     crypto-api >=0.12,