From b1639dda870f22a78136b26295f98585e503fa98 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Fri, 31 Aug 2018 17:14:38 -0400 Subject: Marshal `ByteString` input arguments to `fun`s --- src/Codec/Crypto/HKDF.hs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src/Codec') diff --git a/src/Codec/Crypto/HKDF.hs b/src/Codec/Crypto/HKDF.hs index 724ab04..a8c8fa9 100644 --- a/src/Codec/Crypto/HKDF.hs +++ b/src/Codec/Crypto/HKDF.hs @@ -23,7 +23,7 @@ import Foreign.Marshal.Unsafe (unsafeLocalState) import BTLS.BoringSSL.Digest (evpMaxMDSize) import BTLS.BoringSSL.HKDF import BTLS.BoringSSLPatterns (onBufferOfMaxSize) -import BTLS.Buffer (packCUStringLen, unsafeUseAsCUStringLen) +import BTLS.Buffer (packCUStringLen) import BTLS.Types ( Algorithm(Algorithm), AssociatedData(AssociatedData), Salt(Salt) , SecretKey(SecretKey), noSalt @@ -39,11 +39,7 @@ extract (Algorithm md) (Salt salt) (SecretKey secret) = SecretKey $ unsafeLocalState $ onBufferOfMaxSize evpMaxMDSize $ \pOutKey pOutLen -> do - -- @HKDF_extract@ won't mutate @secret@ or @salt@, so the sharing inherent - -- in 'unsafeUseAsCUStringLen' is fine. - unsafeUseAsCUStringLen secret $ \(pSecret, secretLen) -> - unsafeUseAsCUStringLen salt $ \(pSalt, saltLen) -> - hkdfExtract pOutKey pOutLen md pSecret secretLen pSalt saltLen + hkdfExtract pOutKey pOutLen md secret salt -- | Computes HKDF output key material (OKM) as specified by RFC 5869. expand :: Algorithm -> AssociatedData -> Int -> SecretKey -> SecretKey @@ -51,9 +47,5 @@ expand (Algorithm md) (AssociatedData info) outLen (SecretKey secret) = SecretKey $ unsafeLocalState $ allocaArray outLen $ \pOutKey -> do - -- @HKDF_expand@ won't mutate @secret@ or @info@, so the sharing inherent - -- in 'unsafeUseAsCUStringLen' is fine. - unsafeUseAsCUStringLen secret $ \(pSecret, secretLen) -> - unsafeUseAsCUStringLen info $ \(pInfo, infoLen) -> - hkdfExpand pOutKey (fromIntegral outLen) md pSecret secretLen pInfo infoLen + hkdfExpand pOutKey (fromIntegral outLen) md secret info packCUStringLen (pOutKey, outLen) -- cgit v1.2.3