diff options
author | Benjamin Barenblat <bbaren@google.com> | 2018-09-01 15:12:30 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2018-09-04 11:47:56 -0500 |
commit | a31daa3545c0a8cb5f95e88d66cfcee55a7ee925 (patch) | |
tree | 9c10af070163f12fe369c185e1b7681db492e5a1 /src/BTLS/BoringSSLPatterns.hs | |
parent | 92a90ad43381f6897a93503027d67ac0b1032f3e (diff) |
Enable error checking for HMAC computations
Diffstat (limited to 'src/BTLS/BoringSSLPatterns.hs')
-rw-r--r-- | src/BTLS/BoringSSLPatterns.hs | 33 |
1 files changed, 2 insertions, 31 deletions
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. |