diff options
author | Benjamin Barenblat <bbaren@google.com> | 2018-03-24 21:21:20 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2018-03-24 21:21:20 -0400 |
commit | 7aeeadd0647bfa649b9af859fe5dd7b5cc52afe9 (patch) | |
tree | 82802ca134fccaff7a6824dd7d516aeae1b749a2 /src/Foreign/Ptr | |
parent | 0ed87caa3481cbb6f8c2e809e5ec7df6f6245406 (diff) |
Implement HMAC
Diffstat (limited to 'src/Foreign/Ptr')
-rw-r--r-- | src/Foreign/Ptr/ConstantTimeEquals.hs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Foreign/Ptr/ConstantTimeEquals.hs b/src/Foreign/Ptr/ConstantTimeEquals.hs new file mode 100644 index 0000000..bb8d2d4 --- /dev/null +++ b/src/Foreign/Ptr/ConstantTimeEquals.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE ScopedTypeVariables #-} + +module Foreign.Ptr.ConstantTimeEquals where + +import Foreign (Ptr) +import Foreign.C.Types + +foreign import ccall "openssl/mem.h CRYPTO_memcmp" + cryptoMemcmp :: Ptr a -> Ptr a -> CSize -> IO CInt + +-- | Directly compares two buffers for equality. This operation takes an amount +-- of time dependent on the specified size but independent of either buffer's +-- contents. +constantTimeEquals :: Ptr a -> Ptr a -> Int -> IO Bool +constantTimeEquals a b size = + let size' = fromIntegral size :: CSize + in (== 0) <$> cryptoMemcmp a b size' |