diff options
author | Benjamin Barenblat <bbaren@google.com> | 2018-08-02 17:26:23 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@google.com> | 2018-08-02 17:26:23 -0400 |
commit | 786d272fdf723987e582da16e511f067abf671a5 (patch) | |
tree | 2ffb65b72a5b6c44fdc85cf937f13331dbc49e4c | |
parent | 44a6b5738f73b5281c3630c507aeece75e6ee952 (diff) |
Move BTLS.ConstantTimeEquals into the BTLS.BoringSSL hierarchy
It’s a direct wrapper around a BoringSSL function, so it really belongs
there.
-rw-r--r-- | btls.cabal | 2 | ||||
-rw-r--r-- | src/BTLS/BoringSSL/Mem.chs (renamed from src/BTLS/ConstantTimeEquals.chs) | 6 | ||||
-rw-r--r-- | src/Data/HMAC.hs | 4 |
3 files changed, 6 insertions, 6 deletions
@@ -74,8 +74,8 @@ library , BTLS.BoringSSL.Digest , BTLS.BoringSSL.HKDF , BTLS.BoringSSL.HMAC + , BTLS.BoringSSL.Mem , BTLS.Cast - , BTLS.ConstantTimeEquals , BTLS.CreateWithFinalizer , BTLS.Result , BTLS.Types diff --git a/src/BTLS/ConstantTimeEquals.chs b/src/BTLS/BoringSSL/Mem.chs index 77b1af0..969cf91 100644 --- a/src/BTLS/ConstantTimeEquals.chs +++ b/src/BTLS/BoringSSL/Mem.chs @@ -12,7 +12,7 @@ -- License for the specific language governing permissions and limitations under -- the License. -module BTLS.ConstantTimeEquals where +module BTLS.BoringSSL.Mem where import Foreign (Ptr) import Foreign.C.Types @@ -24,7 +24,7 @@ import BTLS.Cast (asVoidPtr) -- | 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 = +cryptoMemcmp :: Ptr a -> Ptr a -> Int -> IO Bool +cryptoMemcmp a b size = let size' = fromIntegral size :: CULong in (== 0) <$> {#call CRYPTO_memcmp as ^#} (asVoidPtr a) (asVoidPtr b) size' diff --git a/src/Data/HMAC.hs b/src/Data/HMAC.hs index a6b72fe..b0387c6 100644 --- a/src/Data/HMAC.hs +++ b/src/Data/HMAC.hs @@ -25,8 +25,8 @@ import Foreign.Marshal.Unsafe (unsafeLocalState) import BTLS.BoringSSL.Base import BTLS.BoringSSL.HMAC +import BTLS.BoringSSL.Mem (cryptoMemcmp) import BTLS.Cast (asCUCharBuf) -import BTLS.ConstantTimeEquals (constantTimeEquals) import BTLS.Types (SecretKey(SecretKey)) import Data.Digest.Internal (Algorithm(Algorithm), Digest(Digest), initUpdateFinalize) @@ -42,7 +42,7 @@ instance Eq HMAC where unsafeLocalState $ ByteString.unsafeUseAsCStringLen a $ \(a', size) -> ByteString.unsafeUseAsCStringLen b $ \(b', _) -> - constantTimeEquals a' b' size + cryptoMemcmp a' b' size instance Show HMAC where show (HMAC m) = show (Digest m) |