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