diff --git a/Crypto/Hash/IO.hs b/Crypto/Hash/IO.hs index f9f5b8e..25570e5 100644 --- a/Crypto/Hash/IO.hs +++ b/Crypto/Hash/IO.hs @@ -9,8 +9,7 @@ -- {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Crypto.Hash.IO - ( - HashAlgorithm + ( HashAlgorithm(..) , MutableContext , hashMutableInit , hashMutableInitWith diff --git a/Crypto/Hash/Types.hs b/Crypto/Hash/Types.hs index c093123..7c5b132 100644 --- a/Crypto/Hash/Types.hs +++ b/Crypto/Hash/Types.hs @@ -12,8 +12,7 @@ module Crypto.Hash.Types ( HashAlgorithm(..) , Context(..) , Digest(..) - ) - where + ) where import Crypto.Internal.ByteArray (ByteArrayAccess, Bytes) import qualified Crypto.Internal.ByteArray as B @@ -22,23 +21,23 @@ import Foreign.Ptr (Ptr) -- | Class representing hashing algorithms. -- --- The hash algorithm is built over 3 primitives: --- --- * init : create a new hashing context --- --- * updates : update the hashing context with some strict bytestrings --- and return the new context --- --- * finalize : finalize the context into a digest --- +-- The interface presented here is update in place +-- and lowlevel. the Hash module takes care of +-- hidding the mutable interface properly. class HashAlgorithm a where + -- | Get the block size of a hash algorithm hashBlockSize :: a -> Int + -- | Get the digest size of a hash algorithm hashDigestSize :: a -> Int + -- | Get the size of the context used for a hash algorithm hashInternalContextSize :: a -> Int --hashAlgorithmFromProxy :: Proxy a -> a + -- | Initialize a context pointer to the initial state of a hash algorithm hashInternalInit :: Ptr (Context a) -> IO () + -- | Update the context with some raw data hashInternalUpdate :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () + -- | Finalize the context and set the digest raw memory to the right value hashInternalFinalize :: Ptr (Context a) -> Ptr (Digest a) -> IO () {- diff --git a/Crypto/Internal/ByteArray.hs b/Crypto/Internal/ByteArray.hs index cb571a1..3a23152 100644 --- a/Crypto/Internal/ByteArray.hs +++ b/Crypto/Internal/ByteArray.hs @@ -7,10 +7,13 @@ -- -- Simple and efficient byte array types -- +{-# OPTIONS_HADDOCK hide #-} module Crypto.Internal.ByteArray - ( module X + ( module Data.ByteArray + , module Data.ByteArray.Mapping + , module Data.ByteArray.Encoding ) where -import Data.ByteArray as X -import Data.ByteArray.Mapping as X -import Data.ByteArray.Encoding as X +import Data.ByteArray +import Data.ByteArray.Mapping +import Data.ByteArray.Encoding diff --git a/Crypto/Number/F2m.hs b/Crypto/Number/F2m.hs index 8c68d11..274b8df 100644 --- a/Crypto/Number/F2m.hs +++ b/Crypto/Number/F2m.hs @@ -10,7 +10,8 @@ -- attacks. The 'm' parameter is implicitly derived from the irreducible -- polynomial where applicable. module Crypto.Number.F2m - ( addF2m + ( BinaryPolynomial + , addF2m , mulF2m , squareF2m , modF2m diff --git a/Crypto/PubKey/DSA.hs b/Crypto/PubKey/DSA.hs index 812adea..768e574 100644 --- a/Crypto/PubKey/DSA.hs +++ b/Crypto/PubKey/DSA.hs @@ -12,6 +12,8 @@ module Crypto.PubKey.DSA , Signature(..) , PublicKey(..) , PrivateKey(..) + , PublicNumber + , PrivateNumber -- * generation , generatePrivate , calculatePublic diff --git a/Crypto/PubKey/ECC/P256.hs b/Crypto/PubKey/ECC/P256.hs index 2dc1e8d..1b05d3c 100644 --- a/Crypto/PubKey/ECC/P256.hs +++ b/Crypto/PubKey/ECC/P256.hs @@ -17,6 +17,21 @@ module Crypto.PubKey.ECC.P256 ( Scalar , Point + -- * point arithmetic + , pointAdd + , pointMul + , pointsMulVarTime + , pointIsValid + , toPoint + -- * scalar arithmetic + , scalarZero + , scalarAdd + , scalarSub + , scalarInv + , scalarInvVarTime + , scalarCmp + , scalarFromBinary + , scalarToBinary ) where import Data.Word @@ -92,6 +107,7 @@ pointIsValid p = unsafeDoIO $ withPoint p $ \px py -> do -- Scalar methods ------------------------------------------------------------------------ +-- | The scalar representing 0 scalarZero :: Scalar scalarZero = withNewScalarFreeze $ \d -> ccryptonite_p256_init d @@ -128,12 +144,14 @@ scalarInvVarTime a = withNewScalarFreeze $ \b -> withScalar a $ \pa -> ccryptonite_p256_modinv_vartime ccryptonite_SECP256r1_n pa b +-- | Compare 2 Scalar scalarCmp :: Scalar -> Scalar -> Ordering scalarCmp a b = unsafeDoIO $ withScalar a $ \pa -> withScalar b $ \pb -> do v <- ccryptonite_p256_cmp pa pb return $ compare v 0 +-- | convert a scalar from binary scalarFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Scalar scalarFromBinary ba | B.length ba /= scalarSize = CryptoFailed $ CryptoError_SecretKeySizeInvalid @@ -141,6 +159,7 @@ scalarFromBinary ba CryptoPassed $ withNewScalarFreeze $ \p -> B.withByteArray ba $ \b -> ccryptonite_p256_from_bin b p +-- | convert a scalar to binary scalarToBinary :: ByteArray ba => Scalar -> ba scalarToBinary s = B.allocAndFreeze scalarSize $ \b -> withScalar s $ \p -> ccryptonite_p256_to_bin p b