aboutsummaryrefslogtreecommitdiff
path: root/src/Data/HMAC.hs
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-08-23 17:24:47 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-08-23 17:24:47 -0400
commitd1a85eb87934d348c9789aec59c751fa615ec363 (patch)
tree09c72e290df883c1e2d4c7ea2ccf0b1470668ca2 /src/Data/HMAC.hs
parent3be302655bc7e31805af4525d78beb6abfed9a5d (diff)
Clean up casts
Use unsigned char buffers more pervasively throughout the code. This removes most calls to `asCUCharBuf`, isolating `unsafeCoerce` further. By making some type signatures slightly more flexible, also eliminate most explicit integer conversions.
Diffstat (limited to 'src/Data/HMAC.hs')
-rw-r--r--src/Data/HMAC.hs14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/Data/HMAC.hs b/src/Data/HMAC.hs
index 8697c20..1850103 100644
--- a/src/Data/HMAC.hs
+++ b/src/Data/HMAC.hs
@@ -27,7 +27,7 @@ import BTLS.BoringSSL.Base
import BTLS.BoringSSL.HMAC
import BTLS.BoringSSL.Mem (cryptoMemcmp)
import BTLS.BoringSSLPatterns (initUpdateFinalize)
-import BTLS.Cast (asCUCharBuf)
+import BTLS.Buffer (unsafeUseAsCUStringLen)
import BTLS.Types (Algorithm(Algorithm), Digest(Digest), SecretKey(SecretKey))
type LazyByteString = ByteString.Lazy.ByteString
@@ -51,14 +51,8 @@ hmac :: Algorithm -> SecretKey -> LazyByteString -> HMAC
hmac (Algorithm md) (SecretKey key) =
HMAC
. unsafeLocalState
- . initUpdateFinalize mallocHMACCtx initialize update finalize
+ . initUpdateFinalize mallocHMACCtx initialize hmacUpdate hmacFinal
where
initialize ctx =
- ByteString.unsafeUseAsCStringLen key $ \(keyBytes, keySize) ->
- hmacInitEx ctx keyBytes (fromIntegral keySize) md noEngine
-
- -- initUpdateFinalize deals with buffers that are 'Ptr CChar'. However,
- -- BoringSSL's HMAC functions deal with buffers that are 'Ptr CUChar'. As
- -- in Data.Digest, we'll let Haskell reinterpret-cast the buffers.
- update ctx buf len = hmacUpdate ctx (asCUCharBuf buf) len
- finalize ctx hmacOut pOutSize = hmacFinal ctx (asCUCharBuf hmacOut) pOutSize
+ unsafeUseAsCUStringLen key $ \(keyBytes, keySize) ->
+ hmacInitEx ctx keyBytes keySize md noEngine