From d73352f848b79224a94e531bb651897321064998 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Apr 2017 16:35:38 -0400 Subject: initial Crypto Will use Ed25519 because it's from DJB and well regarded and in common use now. --- Crypto.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Crypto.hs (limited to 'Crypto.hs') diff --git a/Crypto.hs b/Crypto.hs new file mode 100644 index 0000000..3d0529d --- /dev/null +++ b/Crypto.hs @@ -0,0 +1,24 @@ +module Crypto where + +import Val +import Hash +import Types + +import qualified Crypto.PubKey.Ed25519 as Ed25519 +import Data.ByteArray (convert) +import Crypto.Error + +dummySignature :: Signature +dummySignature = Unsigned + +-- | Sign any Hashable value. +sign :: Hashable v => Ed25519.SecretKey -> Ed25519.PublicKey -> v -> Signature +sign sk pk v = Ed25519 $ Val $ convert $ + Ed25519.sign sk pk $ val $ hashValue $ hash v + +-- | Verifiy a signature of any Hashable value. +verify :: Hashable v => Ed25519.PublicKey -> v -> Signature -> Bool +verify pk v (Ed25519 (Val s)) = case Ed25519.signature s of + CryptoPassed sig -> Ed25519.verify pk (val $ hashValue $ hash v) sig + CryptoFailed _ -> False +verify _ _ Unsigned = False -- cgit v1.2.3