diff --git a/Crypto/Hash/Internal/Kekkak.hs b/Crypto/Hash/Internal/Kekkak.hs index bcc24ba..16830af 100644 --- a/Crypto/Hash/Internal/Kekkak.hs +++ b/Crypto/Hash/Internal/Kekkak.hs @@ -17,6 +17,7 @@ module Crypto.Hash.Internal.Kekkak , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -83,6 +84,9 @@ foreign import ccall unsafe "cryptonite_kekkak.h cryptonite_kekkak_init" foreign import ccall "cryptonite_kekkak.h cryptonite_kekkak_update" c_kekkak_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_kekkak.h cryptonite_kekkak_update" + c_kekkak_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_kekkak.h cryptonite_kekkak_finalize" c_kekkak_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -98,6 +102,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_kekkak_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_kekkak_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = diff --git a/Crypto/Hash/Internal/MD2.hs b/Crypto/Hash/Internal/MD2.hs index d7d9aa4..301d532 100644 --- a/Crypto/Hash/Internal/MD2.hs +++ b/Crypto/Hash/Internal/MD2.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.MD2 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_md2.h cryptonite_md2_init" foreign import ccall "cryptonite_md2.h cryptonite_md2_update" c_md2_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_md2.h cryptonite_md2_update" + c_md2_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_md2.h cryptonite_md2_finalize" c_md2_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_md2_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_md2_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_md2_finalize ptr) diff --git a/Crypto/Hash/Internal/MD4.hs b/Crypto/Hash/Internal/MD4.hs index a2b8ecd..db1f889 100644 --- a/Crypto/Hash/Internal/MD4.hs +++ b/Crypto/Hash/Internal/MD4.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.MD4 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_md4.h cryptonite_md4_init" foreign import ccall "cryptonite_md4.h cryptonite_md4_update" c_md4_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_md4.h cryptonite_md4_update" + c_md4_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_md4.h cryptonite_md4_finalize" c_md4_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_md4_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_md4_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_md4_finalize ptr) diff --git a/Crypto/Hash/Internal/MD5.hs b/Crypto/Hash/Internal/MD5.hs index 4039a98..26be51d 100644 --- a/Crypto/Hash/Internal/MD5.hs +++ b/Crypto/Hash/Internal/MD5.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.MD5 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_md5.h cryptonite_md5_init" foreign import ccall "cryptonite_md5.h cryptonite_md5_update" c_md5_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_md5.h cryptonite_md5_update" + c_md5_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_md5.h cryptonite_md5_finalize" c_md5_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_md5_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_md5_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_md5_finalize ptr) diff --git a/Crypto/Hash/Internal/RIPEMD160.hs b/Crypto/Hash/Internal/RIPEMD160.hs index ad3e64b..8b6f112 100644 --- a/Crypto/Hash/Internal/RIPEMD160.hs +++ b/Crypto/Hash/Internal/RIPEMD160.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.RIPEMD160 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_ripemd.h cryptonite_ripemd160_init" foreign import ccall "cryptonite_ripemd.h cryptonite_ripemd160_update" c_ripemd160_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_ripemd.h cryptonite_ripemd160_update" + c_ripemd160_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_ripemd.h cryptonite_ripemd160_finalize" c_ripemd160_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_ripemd160_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_ripemd160_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_ripemd160_finalize ptr) diff --git a/Crypto/Hash/Internal/SHA1.hs b/Crypto/Hash/Internal/SHA1.hs index 87e2bc6..575facb 100644 --- a/Crypto/Hash/Internal/SHA1.hs +++ b/Crypto/Hash/Internal/SHA1.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.SHA1 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_sha1.h cryptonite_sha1_init" foreign import ccall "cryptonite_sha1.h cryptonite_sha1_update" c_sha1_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_sha1.h cryptonite_sha1_update" + c_sha1_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_sha1.h cryptonite_sha1_finalize" c_sha1_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_sha1_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_sha1_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_sha1_finalize ptr) diff --git a/Crypto/Hash/Internal/SHA224.hs b/Crypto/Hash/Internal/SHA224.hs index 9f5fe20..086241a 100644 --- a/Crypto/Hash/Internal/SHA224.hs +++ b/Crypto/Hash/Internal/SHA224.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.SHA224 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_sha256.h cryptonite_sha224_init" foreign import ccall "cryptonite_sha256.h cryptonite_sha224_update" c_sha224_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_sha256.h cryptonite_sha224_update" + c_sha224_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_sha256.h cryptonite_sha224_finalize" c_sha224_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_sha224_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_sha224_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_sha224_finalize ptr) diff --git a/Crypto/Hash/Internal/SHA256.hs b/Crypto/Hash/Internal/SHA256.hs index e418bb1..728376a 100644 --- a/Crypto/Hash/Internal/SHA256.hs +++ b/Crypto/Hash/Internal/SHA256.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.SHA256 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_sha256.h cryptonite_sha256_init" foreign import ccall "cryptonite_sha256.h cryptonite_sha256_update" c_sha256_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_sha256.h cryptonite_sha256_update" + c_sha256_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_sha256.h cryptonite_sha256_finalize" c_sha256_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_sha256_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_sha256_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_sha256_finalize ptr) diff --git a/Crypto/Hash/Internal/SHA3.hs b/Crypto/Hash/Internal/SHA3.hs index 8f5ee6b..ca6c93c 100644 --- a/Crypto/Hash/Internal/SHA3.hs +++ b/Crypto/Hash/Internal/SHA3.hs @@ -17,6 +17,7 @@ module Crypto.Hash.Internal.SHA3 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -83,6 +84,9 @@ foreign import ccall unsafe "cryptonite_sha3.h cryptonite_sha3_init" foreign import ccall "cryptonite_sha3.h cryptonite_sha3_update" c_sha3_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_sha3.h cryptonite_sha3_update" + c_sha3_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_sha3.h cryptonite_sha3_finalize" c_sha3_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -98,6 +102,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_sha3_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_sha3_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = diff --git a/Crypto/Hash/Internal/SHA384.hs b/Crypto/Hash/Internal/SHA384.hs index ff65663..9d934e2 100644 --- a/Crypto/Hash/Internal/SHA384.hs +++ b/Crypto/Hash/Internal/SHA384.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.SHA384 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_sha512.h cryptonite_sha384_init" foreign import ccall "cryptonite_sha512.h cryptonite_sha384_update" c_sha384_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_sha512.h cryptonite_sha384_update" + c_sha384_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_sha512.h cryptonite_sha384_finalize" c_sha384_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_sha384_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_sha384_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_sha384_finalize ptr) diff --git a/Crypto/Hash/Internal/SHA512.hs b/Crypto/Hash/Internal/SHA512.hs index 793d4b3..dfe4a8d 100644 --- a/Crypto/Hash/Internal/SHA512.hs +++ b/Crypto/Hash/Internal/SHA512.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.SHA512 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxNew @@ -82,6 +83,9 @@ foreign import ccall unsafe "cryptonite_sha512.h cryptonite_sha512_init" foreign import ccall "cryptonite_sha512.h cryptonite_sha512_update" c_sha512_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_sha512.h cryptonite_sha512_update" + c_sha512_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_sha512.h cryptonite_sha512_finalize" c_sha512_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -97,6 +101,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_sha512_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_sha512_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_sha512_finalize ptr) diff --git a/Crypto/Hash/Internal/Skein256.hs b/Crypto/Hash/Internal/Skein256.hs index 4eff565..1f29c7f 100644 --- a/Crypto/Hash/Internal/Skein256.hs +++ b/Crypto/Hash/Internal/Skein256.hs @@ -17,6 +17,7 @@ module Crypto.Hash.Internal.Skein256 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -83,6 +84,9 @@ foreign import ccall unsafe "cryptonite_skein256.h cryptonite_skein256_init" foreign import ccall "cryptonite_skein256.h cryptonite_skein256_update" c_skein256_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_skein256.h cryptonite_skein256_update" + c_skein256_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_skein256.h cryptonite_skein256_finalize" c_skein256_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -98,6 +102,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_skein256_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_skein256_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = diff --git a/Crypto/Hash/Internal/Skein512.hs b/Crypto/Hash/Internal/Skein512.hs index e3ecdda..67b3ad6 100644 --- a/Crypto/Hash/Internal/Skein512.hs +++ b/Crypto/Hash/Internal/Skein512.hs @@ -17,6 +17,7 @@ module Crypto.Hash.Internal.Skein512 , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -83,6 +84,9 @@ foreign import ccall unsafe "cryptonite_skein512.h cryptonite_skein512_init" foreign import ccall "cryptonite_skein512.h cryptonite_skein512_update" c_skein512_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_skein512.h cryptonite_skein512_update" + c_skein512_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_skein512.h cryptonite_skein512_finalize" c_skein512_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -98,6 +102,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_skein512_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_skein512_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = diff --git a/Crypto/Hash/Internal/Tiger.hs b/Crypto/Hash/Internal/Tiger.hs index 4fa5f55..b8d6cef 100644 --- a/Crypto/Hash/Internal/Tiger.hs +++ b/Crypto/Hash/Internal/Tiger.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.Tiger , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_tiger.h cryptonite_tiger_init" foreign import ccall "cryptonite_tiger.h cryptonite_tiger_update" c_tiger_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_tiger.h cryptonite_tiger_update" + c_tiger_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_tiger.h cryptonite_tiger_finalize" c_tiger_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_tiger_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_tiger_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_tiger_finalize ptr) diff --git a/Crypto/Hash/Internal/Whirlpool.hs b/Crypto/Hash/Internal/Whirlpool.hs index e4ee4bf..8c15b50 100644 --- a/Crypto/Hash/Internal/Whirlpool.hs +++ b/Crypto/Hash/Internal/Whirlpool.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.Whirlpool , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_whirlpool.h cryptonite_whirlpool_init" foreign import ccall "cryptonite_whirlpool.h cryptonite_whirlpool_update" c_whirlpool_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_whirlpool.h cryptonite_whirlpool_update" + c_whirlpool_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_whirlpool.h cryptonite_whirlpool_finalize" c_whirlpool_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_whirlpool_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_whirlpool_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_whirlpool_finalize ptr) diff --git a/gen/template/hash-internal-len.hs b/gen/template/hash-internal-len.hs index ca7f7f5..abc7e64 100644 --- a/gen/template/hash-internal-len.hs +++ b/gen/template/hash-internal-len.hs @@ -17,6 +17,7 @@ module Crypto.Hash.Internal.%%MODULENAME%% , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -83,6 +84,9 @@ foreign import ccall unsafe "cryptonite_%%HEADER_FILE%% cryptonite_%%HASHNAME%%_ foreign import ccall "cryptonite_%%HEADER_FILE%% cryptonite_%%HASHNAME%%_update" c_%%HASHNAME%%_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_%%HEADER_FILE%% cryptonite_%%HASHNAME%%_update" + c_%%HASHNAME%%_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_%%HEADER_FILE%% cryptonite_%%HASHNAME%%_finalize" c_%%HASHNAME%%_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -98,6 +102,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_%%HASHNAME%%_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_%%HASHNAME%%_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = diff --git a/gen/template/hash-internal.hs b/gen/template/hash-internal.hs index 81fece7..7ba6e70 100644 --- a/gen/template/hash-internal.hs +++ b/gen/template/hash-internal.hs @@ -18,6 +18,7 @@ module Crypto.Hash.Internal.%%MODULENAME%% , internalInit , internalInitAt , internalUpdate + , internalUpdateUnsafe , internalFinalize -- * Context copy and creation , withCtxCopy @@ -81,6 +82,9 @@ foreign import ccall unsafe "cryptonite_%%HEADER_FILE%% cryptonite_%%HASHNAME%%_ foreign import ccall "cryptonite_%%HEADER_FILE%% cryptonite_%%HASHNAME%%_update" c_%%HASHNAME%%_update :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () +foreign import ccall unsafe "cryptonite_%%HEADER_FILE%% cryptonite_%%HASHNAME%%_update" + c_%%HASHNAME%%_update_unsafe :: Ptr Ctx -> Ptr Word8 -> Word32 -> IO () + foreign import ccall unsafe "cryptonite_%%HEADER_FILE%% cryptonite_%%HASHNAME%%_finalize" c_%%HASHNAME%%_finalize :: Ptr Ctx -> Ptr Word8 -> IO () @@ -96,6 +100,14 @@ internalUpdate :: Ptr Ctx -> ByteString -> IO () internalUpdate ptr d = unsafeUseAsCStringLen d (\(cs, len) -> c_%%HASHNAME%%_update ptr (castPtr cs) (fromIntegral len)) +-- | Update a context in place using an unsafe foreign function call. +-- +-- It is faster than `internalUpdate`, but will block the haskell runtime. +-- This shouldn't be used if the input data is large. +internalUpdateUnsafe :: Ptr Ctx -> ByteString -> IO () +internalUpdateUnsafe ptr d = + unsafeUseAsCStringLen d (\(cs, len) -> c_%%HASHNAME%%_update_unsafe ptr (castPtr cs) (fromIntegral len)) + -- | Finalize a context in place internalFinalize :: Ptr Ctx -> IO ByteString internalFinalize ptr = create digestSize (c_%%HASHNAME%%_finalize ptr)