more fixing up description and comments

This commit is contained in:
Vincent Hanquez 2015-05-20 06:22:00 +01:00
parent 92343f856a
commit 881d167cb5
6 changed files with 41 additions and 18 deletions

View File

@ -9,8 +9,7 @@
--
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Crypto.Hash.IO
(
HashAlgorithm
( HashAlgorithm(..)
, MutableContext
, hashMutableInit
, hashMutableInitWith

View File

@ -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 ()
{-

View File

@ -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

View File

@ -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

View File

@ -12,6 +12,8 @@ module Crypto.PubKey.DSA
, Signature(..)
, PublicKey(..)
, PrivateKey(..)
, PublicNumber
, PrivateNumber
-- * generation
, generatePrivate
, calculatePublic

View File

@ -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