[doc] Add missing documentation call
This commit is contained in:
parent
7bd3a8f892
commit
7928198923
@ -17,6 +17,7 @@ module Crypto.Data.Padding
|
|||||||
import Data.ByteArray (ByteArray, Bytes)
|
import Data.ByteArray (ByteArray, Bytes)
|
||||||
import qualified Data.ByteArray as B
|
import qualified Data.ByteArray as B
|
||||||
|
|
||||||
|
-- | Format of padding
|
||||||
data Format =
|
data Format =
|
||||||
PKCS5 -- ^ PKCS5: PKCS7 with hardcoded size of 8
|
PKCS5 -- ^ PKCS5: PKCS7 with hardcoded size of 8
|
||||||
| PKCS7 Int -- ^ PKCS7 with padding size between 1 and 255
|
| PKCS7 Int -- ^ PKCS7 with padding size between 1 and 255
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import Crypto.Error
|
|||||||
newtype State = State ScrubbedBytes
|
newtype State = State ScrubbedBytes
|
||||||
deriving (ByteArrayAccess)
|
deriving (ByteArrayAccess)
|
||||||
|
|
||||||
|
-- | Poly1305 State. use State instead of Ctx
|
||||||
type Ctx = State
|
type Ctx = State
|
||||||
{-# DEPRECATED Ctx "use Poly1305 State instead" #-}
|
{-# DEPRECATED Ctx "use Poly1305 State instead" #-}
|
||||||
|
|
||||||
|
|||||||
@ -116,7 +116,7 @@ gmpTestPrimeMillerRabin (I# tries) !n = GmpSupported $
|
|||||||
gmpTestPrimeMillerRabin _ _ = GmpUnsupported
|
gmpTestPrimeMillerRabin _ _ = GmpUnsupported
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
-- | Return the size in bytes of a integer
|
-- | Return the size in bytes of an integer
|
||||||
gmpSizeInBytes :: Integer -> GmpSupported Int
|
gmpSizeInBytes :: Integer -> GmpSupported Int
|
||||||
#if MIN_VERSION_integer_gmp(0,5,1)
|
#if MIN_VERSION_integer_gmp(0,5,1)
|
||||||
gmpSizeInBytes n = GmpSupported (I# (word2Int# (sizeInBaseInteger n 256#)))
|
gmpSizeInBytes n = GmpSupported (I# (word2Int# (sizeInBaseInteger n 256#)))
|
||||||
@ -124,6 +124,7 @@ gmpSizeInBytes n = GmpSupported (I# (word2Int# (sizeInBaseInteger n 256#)))
|
|||||||
gmpSizeInBytes _ = GmpUnsupported
|
gmpSizeInBytes _ = GmpUnsupported
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
-- | Return the size in bits of an integer
|
||||||
gmpSizeInBits :: Integer -> GmpSupported Int
|
gmpSizeInBits :: Integer -> GmpSupported Int
|
||||||
#if MIN_VERSION_integer_gmp(0,5,1)
|
#if MIN_VERSION_integer_gmp(0,5,1)
|
||||||
gmpSizeInBits n = GmpSupported (I# (word2Int# (sizeInBaseInteger n 2#)))
|
gmpSizeInBits n = GmpSupported (I# (word2Int# (sizeInBaseInteger n 2#)))
|
||||||
|
|||||||
@ -78,6 +78,7 @@ data P256X
|
|||||||
-- Point methods
|
-- Point methods
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- | Get the base point for the P256 Curve
|
||||||
pointBase :: Point
|
pointBase :: Point
|
||||||
pointBase =
|
pointBase =
|
||||||
case scalarFromInteger 1 of
|
case scalarFromInteger 1 of
|
||||||
@ -127,6 +128,7 @@ pointIsValid p = unsafeDoIO $ withPoint p $ \px py -> do
|
|||||||
r <- ccryptonite_p256_is_valid_point px py
|
r <- ccryptonite_p256_is_valid_point px py
|
||||||
return (r /= 0)
|
return (r /= 0)
|
||||||
|
|
||||||
|
-- | Convert a point to (x,y) Integers
|
||||||
pointToIntegers :: Point -> (Integer, Integer)
|
pointToIntegers :: Point -> (Integer, Integer)
|
||||||
pointToIntegers p = unsafeDoIO $ withPoint p $ \px py ->
|
pointToIntegers p = unsafeDoIO $ withPoint p $ \px py ->
|
||||||
allocTemp 32 (serialize (castPtr px) (castPtr py))
|
allocTemp 32 (serialize (castPtr px) (castPtr py))
|
||||||
@ -138,6 +140,7 @@ pointToIntegers p = unsafeDoIO $ withPoint p $ \px py ->
|
|||||||
y <- os2ip temp scalarSize
|
y <- os2ip temp scalarSize
|
||||||
return (x,y)
|
return (x,y)
|
||||||
|
|
||||||
|
-- | Convert from (x,y) Integers to a point
|
||||||
pointFromIntegers :: (Integer, Integer) -> Point
|
pointFromIntegers :: (Integer, Integer) -> Point
|
||||||
pointFromIntegers (x,y) = withNewPoint $ \dx dy ->
|
pointFromIntegers (x,y) = withNewPoint $ \dx dy ->
|
||||||
allocTemp scalarSize (\temp -> fill temp (castPtr dx) x >> fill temp (castPtr dy) y)
|
allocTemp scalarSize (\temp -> fill temp (castPtr dx) x >> fill temp (castPtr dy) y)
|
||||||
@ -154,11 +157,13 @@ pointFromIntegers (x,y) = withNewPoint $ \dx dy ->
|
|||||||
-- then fill dest with the P256 scalar from temp
|
-- then fill dest with the P256 scalar from temp
|
||||||
ccryptonite_p256_from_bin temp dest
|
ccryptonite_p256_from_bin temp dest
|
||||||
|
|
||||||
|
-- | Convert a point to a binary representation
|
||||||
pointToBinary :: ByteArray ba => Point -> ba
|
pointToBinary :: ByteArray ba => Point -> ba
|
||||||
pointToBinary p = B.unsafeCreate pointSize $ \dst -> withPoint p $ \px py -> do
|
pointToBinary p = B.unsafeCreate pointSize $ \dst -> withPoint p $ \px py -> do
|
||||||
ccryptonite_p256_to_bin (castPtr px) dst
|
ccryptonite_p256_to_bin (castPtr px) dst
|
||||||
ccryptonite_p256_to_bin (castPtr py) (dst `plusPtr` 32)
|
ccryptonite_p256_to_bin (castPtr py) (dst `plusPtr` 32)
|
||||||
|
|
||||||
|
-- | Convert from binary to a point
|
||||||
pointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point
|
pointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point
|
||||||
pointFromBinary ba
|
pointFromBinary ba
|
||||||
| B.length ba /= pointSize = CryptoFailed $ CryptoError_PublicKeySizeInvalid
|
| B.length ba /= pointSize = CryptoFailed $ CryptoError_PublicKeySizeInvalid
|
||||||
@ -184,6 +189,7 @@ scalarGenerate = unwrap . scalarFromBinary . witness <$> getRandomBytes 32
|
|||||||
scalarZero :: Scalar
|
scalarZero :: Scalar
|
||||||
scalarZero = withNewScalarFreeze $ \d -> ccryptonite_p256_init d
|
scalarZero = withNewScalarFreeze $ \d -> ccryptonite_p256_init d
|
||||||
|
|
||||||
|
-- | Check if the scalar is 0
|
||||||
scalarIsZero :: Scalar -> Bool
|
scalarIsZero :: Scalar -> Bool
|
||||||
scalarIsZero s = unsafeDoIO $ withScalar s $ \d -> do
|
scalarIsZero s = unsafeDoIO $ withScalar s $ \d -> do
|
||||||
result <- ccryptonite_p256_is_zero d
|
result <- ccryptonite_p256_is_zero d
|
||||||
@ -250,10 +256,12 @@ scalarToBinary s = B.unsafeCreate scalarSize $ \b -> withScalar s $ \p ->
|
|||||||
ccryptonite_p256_to_bin p b
|
ccryptonite_p256_to_bin p b
|
||||||
{-# NOINLINE scalarToBinary #-}
|
{-# NOINLINE scalarToBinary #-}
|
||||||
|
|
||||||
|
-- | Convert from an Integer to a P256 Scalar
|
||||||
scalarFromInteger :: Integer -> CryptoFailable Scalar
|
scalarFromInteger :: Integer -> CryptoFailable Scalar
|
||||||
scalarFromInteger i =
|
scalarFromInteger i =
|
||||||
maybe (CryptoFailed CryptoError_SecretKeySizeInvalid) scalarFromBinary (S.i2ospOf 32 i :: Maybe Bytes)
|
maybe (CryptoFailed CryptoError_SecretKeySizeInvalid) scalarFromBinary (S.i2ospOf 32 i :: Maybe Bytes)
|
||||||
|
|
||||||
|
-- | Convert from a P256 Scalar to an Integer
|
||||||
scalarToInteger :: Scalar -> Integer
|
scalarToInteger :: Scalar -> Integer
|
||||||
scalarToInteger s = S.os2ip (scalarToBinary s :: Bytes)
|
scalarToInteger s = S.os2ip (scalarToBinary s :: Bytes)
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import Crypto.Number.Generate (generateBetween)
|
|||||||
import Crypto.PubKey.ECC.Types
|
import Crypto.PubKey.ECC.Types
|
||||||
import Crypto.Random
|
import Crypto.Random
|
||||||
|
|
||||||
|
-- | Generate a valid scalar for a specific Curve
|
||||||
scalarGenerate :: MonadRandom randomly => Curve -> randomly PrivateNumber
|
scalarGenerate :: MonadRandom randomly => Curve -> randomly PrivateNumber
|
||||||
scalarGenerate curve = generateBetween 1 (n - 1)
|
scalarGenerate curve = generateBetween 1 (n - 1)
|
||||||
where
|
where
|
||||||
|
|||||||
@ -40,6 +40,7 @@ import qualified Crypto.Internal.ByteArray as B
|
|||||||
-- a ASN1 wrapped description the algorithm plus the content
|
-- a ASN1 wrapped description the algorithm plus the content
|
||||||
-- of the digest.
|
-- of the digest.
|
||||||
class HashAlgorithm hashAlg => HashAlgorithmASN1 hashAlg where
|
class HashAlgorithm hashAlg => HashAlgorithmASN1 hashAlg where
|
||||||
|
-- | Convert a Digest into an ASN1 wrapped descriptive ByteArray
|
||||||
hashDigestASN1 :: ByteArray out => Digest hashAlg -> out
|
hashDigestASN1 :: ByteArray out => Digest hashAlg -> out
|
||||||
|
|
||||||
-- http://uk.emc.com/emc-plus/rsa-labs/pkcs/files/h11300-wp-pkcs-1v2-2-rsa-cryptography-standard.pdf
|
-- http://uk.emc.com/emc-plus/rsa-labs/pkcs/files/h11300-wp-pkcs-1v2-2-rsa-cryptography-standard.pdf
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user