From a31daa3545c0a8cb5f95e88d66cfcee55a7ee925 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sat, 1 Sep 2018 15:12:30 -0400 Subject: Enable error checking for HMAC computations --- src/BTLS/BoringSSLPatterns.hs | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'src/BTLS/BoringSSLPatterns.hs') diff --git a/src/BTLS/BoringSSLPatterns.hs b/src/BTLS/BoringSSLPatterns.hs index b7fe223..8d852a1 100644 --- a/src/BTLS/BoringSSLPatterns.hs +++ b/src/BTLS/BoringSSLPatterns.hs @@ -13,44 +13,15 @@ -- the License. module BTLS.BoringSSLPatterns - ( initUpdateFinalize - , onBufferOfMaxSize + ( onBufferOfMaxSize ) where import Data.ByteString (ByteString) -import qualified Data.ByteString.Lazy as ByteString.Lazy -import Foreign (ForeignPtr, Storable(peek), Ptr, alloca, allocaArray, withForeignPtr) +import Foreign (Storable(peek), Ptr, alloca, allocaArray) import Foreign.C.Types -import BTLS.BoringSSL.Digest (evpMaxMDSize) import BTLS.Buffer (packCUStringLen) -type LazyByteString = ByteString.Lazy.ByteString - --- | Encapsulates a common pattern of operation between hashing and HMAC --- computation. Both of these operations require an allocated context local to --- the operation. The context gets initialized once, updated repeatedly, and --- then finalized. Finally, we read the result out of a buffer produced by the --- finalizer. --- --- The updater must not mutate any argument other than the context. --- --- If all arguments are safe to use under 'unsafeLocalState', this whole --- function is safe to use under 'unsafeLocalState'. -initUpdateFinalize :: - IO (ForeignPtr ctx) - -> (Ptr ctx -> IO ()) - -> (Ptr ctx -> ByteString -> IO ()) - -> (Ptr ctx -> Ptr CUChar -> Ptr CUInt -> IO ()) - -> LazyByteString - -> IO ByteString -initUpdateFinalize mallocCtx initialize update finalize bytes = do - ctxFP <- mallocCtx - withForeignPtr ctxFP $ \ctx -> do - initialize ctx - mapM_ (update ctx) (ByteString.Lazy.toChunks bytes) - onBufferOfMaxSize evpMaxMDSize (finalize ctx) - -- | Allocates a buffer, runs a function 'f' to partially fill it, and packs the -- filled data into a 'ByteString'. 'f' must write the size of the filled data, -- in bytes and not including any trailing null, into its second argument. -- cgit v1.2.3