aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-08-02 17:41:48 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-08-02 17:41:48 -0400
commitfd9f2a18eeaa5361660caa4c23384ea38973b021 (patch)
treeb91bb69368664de23a1119ce625ba80aa1baccfd /src
parent786d272fdf723987e582da16e511f067abf671a5 (diff)
Eliminate Data.Digest.Internal
Move Data.Digest.Internal’s functions and types into more appropriate modules. There’s now a single BTLS hierarchy that contains all internal modules for the project.
Diffstat (limited to 'src')
-rw-r--r--src/BTLS/BoringSSLPatterns.hs (renamed from src/Data/Digest/Internal.hs)24
-rw-r--r--src/BTLS/Types.hs26
-rw-r--r--src/Codec/Crypto/HKDF.hs5
-rw-r--r--src/Data/Digest.hs3
-rw-r--r--src/Data/HMAC.hs5
5 files changed, 30 insertions, 33 deletions
diff --git a/src/Data/Digest/Internal.hs b/src/BTLS/BoringSSLPatterns.hs
index 88a0d9f..4b08663 100644
--- a/src/Data/Digest/Internal.hs
+++ b/src/BTLS/BoringSSLPatterns.hs
@@ -12,41 +12,21 @@
-- License for the specific language governing permissions and limitations under
-- the License.
-module Data.Digest.Internal
- ( Algorithm(..)
- , Digest(..)
- , initUpdateFinalize
+module BTLS.BoringSSLPatterns
+ ( initUpdateFinalize
) where
-import Data.Bits (Bits((.&.)), shiftR)
import Data.ByteString (ByteString)
import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Unsafe as ByteString
import qualified Data.ByteString.Lazy as ByteString.Lazy
-import Data.Char (intToDigit)
-import Data.Word (Word8)
import Foreign (ForeignPtr, Storable(peek), Ptr, alloca, allocaArray, withForeignPtr)
import Foreign.C.Types
-import BTLS.BoringSSL.Base (EVPMD)
import BTLS.BoringSSL.Digest (evpMaxMDSize)
type LazyByteString = ByteString.Lazy.ByteString
--- | A cryptographic hash function.
-newtype Algorithm = Algorithm (Ptr EVPMD)
-
--- | The result of a hash operation.
-newtype Digest = Digest ByteString
- deriving (Eq, Ord)
-
-instance Show Digest where
- show (Digest d) = ByteString.foldr showHexPadded [] d
- where
- showHexPadded b xs =
- hexit (b `shiftR` 4 .&. 0x0f) : hexit (b .&. 0x0f) : xs
- hexit = intToDigit . fromIntegral :: Word8 -> Char
-
-- | 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
diff --git a/src/BTLS/Types.hs b/src/BTLS/Types.hs
index dbd806a..06b5173 100644
--- a/src/BTLS/Types.hs
+++ b/src/BTLS/Types.hs
@@ -12,20 +12,36 @@
-- License for the specific language governing permissions and limitations under
-- the License.
-module BTLS.Types
- ( AssociatedData(AssociatedData)
- , Salt(Salt), noSalt
- , SecretKey(SecretKey)
- ) where
+module BTLS.Types where
+import Data.Bits (Bits((.&.)), shiftR)
import Data.ByteString (ByteString)
import qualified Data.ByteString as ByteString
+import Data.Char (intToDigit)
+import Data.Word (Word8)
+import Foreign (Ptr)
+
+import BTLS.BoringSSL.Base (EVPMD)
+
+-- | A cryptographic hash function.
+newtype Algorithm = Algorithm (Ptr EVPMD)
-- | Context or application-specific information. Equality comparisons on this
-- type are variable-time.
newtype AssociatedData = AssociatedData ByteString
deriving (Eq, Ord, Show)
+-- | The result of a hash operation.
+newtype Digest = Digest ByteString
+ deriving (Eq, Ord)
+
+instance Show Digest where
+ show (Digest d) = ByteString.foldr showHexPadded [] d
+ where
+ showHexPadded b xs =
+ hexit (b `shiftR` 4 .&. 0x0f) : hexit (b .&. 0x0f) : xs
+ hexit = intToDigit . fromIntegral :: Word8 -> Char
+
-- | A salt. Equality comparisons on this type are variable-time.
newtype Salt = Salt ByteString
deriving (Eq, Ord, Show)
diff --git a/src/Codec/Crypto/HKDF.hs b/src/Codec/Crypto/HKDF.hs
index 4547a52..2b1dc1f 100644
--- a/src/Codec/Crypto/HKDF.hs
+++ b/src/Codec/Crypto/HKDF.hs
@@ -26,8 +26,9 @@ import BTLS.BoringSSL.Digest (evpMaxMDSize)
import BTLS.BoringSSL.HKDF
import BTLS.Cast (asCUCharBuf)
import BTLS.Types
- (AssociatedData(AssociatedData), Salt(Salt), SecretKey(SecretKey), noSalt)
-import Data.Digest.Internal (Algorithm(Algorithm))
+ ( Algorithm(Algorithm), AssociatedData(AssociatedData), Salt(Salt)
+ , SecretKey(SecretKey), noSalt
+ )
-- | Computes an HKDF pseudorandom key (PRK) as specified by RFC 5869.
extract :: Algorithm -> Salt -> SecretKey -> SecretKey
diff --git a/src/Data/Digest.hs b/src/Data/Digest.hs
index 03026fb..0587d2b 100644
--- a/src/Data/Digest.hs
+++ b/src/Data/Digest.hs
@@ -26,8 +26,9 @@ import Foreign.Marshal.Unsafe (unsafeLocalState)
import BTLS.BoringSSL.Base
import BTLS.BoringSSL.Digest
+import BTLS.BoringSSLPatterns (initUpdateFinalize)
import BTLS.Cast (asCUCharBuf)
-import Data.Digest.Internal
+import BTLS.Types (Algorithm(Algorithm), Digest(Digest))
type LazyByteString = ByteString.Lazy.ByteString
diff --git a/src/Data/HMAC.hs b/src/Data/HMAC.hs
index b0387c6..8697c20 100644
--- a/src/Data/HMAC.hs
+++ b/src/Data/HMAC.hs
@@ -26,10 +26,9 @@ import Foreign.Marshal.Unsafe (unsafeLocalState)
import BTLS.BoringSSL.Base
import BTLS.BoringSSL.HMAC
import BTLS.BoringSSL.Mem (cryptoMemcmp)
+import BTLS.BoringSSLPatterns (initUpdateFinalize)
import BTLS.Cast (asCUCharBuf)
-import BTLS.Types (SecretKey(SecretKey))
-import Data.Digest.Internal
- (Algorithm(Algorithm), Digest(Digest), initUpdateFinalize)
+import BTLS.Types (Algorithm(Algorithm), Digest(Digest), SecretKey(SecretKey))
type LazyByteString = ByteString.Lazy.ByteString