From f84aa5d7ce7678c6d0785d5951834d5f9413e5f8 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 30 Nov 2016 14:48:49 +0900 Subject: [PATCH] documentation & relaxing types. --- Crypto/PubKey/Curve25519.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Crypto/PubKey/Curve25519.hs b/Crypto/PubKey/Curve25519.hs index 08b4a1c..9fef828 100644 --- a/Crypto/PubKey/Curve25519.hs +++ b/Crypto/PubKey/Curve25519.hs @@ -27,7 +27,6 @@ module Crypto.PubKey.Curve25519 ) where import Data.Bits -import Data.ByteString (ByteString) import Data.Word import Foreign.Ptr import Foreign.Storable @@ -36,7 +35,7 @@ import GHC.Ptr import Crypto.Error import Crypto.Internal.Compat import Crypto.Internal.Imports -import Crypto.Internal.ByteArray (ByteArrayAccess, ScrubbedBytes, Bytes, withByteArray) +import Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray, ScrubbedBytes, Bytes, withByteArray) import qualified Crypto.Internal.ByteArray as B import Crypto.Error (CryptoFailable(..)) import Crypto.Random @@ -120,6 +119,7 @@ foreign import ccall "cryptonite_curve25519_donna" -> Ptr Word8 -- ^ basepoint -> IO () +-- | Generate a secret key. generateSecretKey :: MonadRandom m => m SecretKey generateSecretKey = return $ unsafeDoIO $ do sb <- getRandomBytes 32 @@ -130,10 +130,12 @@ generateSecretKey = return $ unsafeDoIO $ do pokeByteOff inp 31 ((e31 .&. 0x7f) .|. 0x40) return $ SecretKey sb -toPublicKey :: ByteString -> PublicKey +-- | Create a public key. +toPublicKey :: ByteArrayAccess bs => bs -> PublicKey toPublicKey bs = pub where CryptoPassed pub = publicKey bs -fromPublicKey :: PublicKey -> ByteString +-- | Convert a public key. +fromPublicKey :: ByteArray bs => PublicKey -> bs fromPublicKey (PublicKey b) = B.convert b