From 395f75c6b7f66d313b4d44be4ed1317f9d7c7042 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 15 Dec 2013 22:06:29 -0500 Subject: Adapted to new ecc solutoin for OpenPGP-Haskell --- Data/OpenPGP/Util/Verify.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Data/OpenPGP/Util/Verify.hs') diff --git a/Data/OpenPGP/Util/Verify.hs b/Data/OpenPGP/Util/Verify.hs index 2367570..b42e664 100644 --- a/Data/OpenPGP/Util/Verify.hs +++ b/Data/OpenPGP/Util/Verify.hs @@ -1,5 +1,7 @@ +{-# LANGUAGE OverloadedStrings #-} module Data.OpenPGP.Util.Verify where +import Debug.Trace import qualified Data.OpenPGP as OpenPGP import Data.Maybe import Data.Binary (encode) @@ -9,6 +11,8 @@ import qualified Data.ByteString.Lazy as LZ import qualified Crypto.PubKey.DSA as Vincent.DSA import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA +import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA +-- import Math.NumberTheory.Moduli import Data.OpenPGP.Util.Base @@ -19,6 +23,14 @@ dsaKey k = Vincent.DSA.PublicKey (keyParam 'y' k) +{- +applyCurve :: Vincent.ECDSA.CurveCommon -> Integer -> Integer +applyCurve curve x = x*x*x + x*a + b + where + a = Vincent.ECDSA.ecc_a curve + b = Vincent.ECDSA.ecc_b curve +-} + -- | Verify a message signature verify :: OpenPGP.Message -- ^ Keys that may have made the signature @@ -35,17 +47,28 @@ verifyOne keys sig over = fmap (const sig) $ maybeKey >>= verification >>= guard where verification = case OpenPGP.key_algorithm sig of OpenPGP.DSA -> dsaVerify + OpenPGP.ECDSA -> ecdsaVerify alg | alg `elem` [OpenPGP.RSA,OpenPGP.RSA_S] -> rsaVerify | otherwise -> const Nothing dsaVerify k = let k' = dsaKey k in Just $ Vincent.DSA.verify (dsaTruncate k' . bhash) k' dsaSig over + ecdsaVerify k = let k' = ecdsaKey k + r = Just $ Vincent.ECDSA.verify bhash k' ecdsaSig over + in r -- trace ("ecdsaVerify: "++show r) r rsaVerify k = Just $ Vincent.RSA.verify desc (rsaKey k) over rsaSig [rsaSig] = map (toStrictBS . LZ.drop 2 . encode) (OpenPGP.signature sig) dsaSig = let [OpenPGP.MPI r, OpenPGP.MPI s] = OpenPGP.signature sig in Vincent.DSA.Signature r s + ecdsaSig = let [OpenPGP.MPI r, OpenPGP.MPI s] = OpenPGP.signature sig in + Vincent.ECDSA.Signature r s dsaTruncate (Vincent.DSA.PublicKey (Vincent.DSA.Params _ _ q) _) = BS.take (integerBytesize q) + {- + ecdsaTruncate (Vincent.ECDSA.PublicKey _ (Vincent.ECDSA.Point x y)) = BS.take (integerBytesize x + + integerBytesize y ) + -} bhash = hashBySymbol hash_algo . toLazyBS desc = hashAlgoDesc hash_algo hash_algo = OpenPGP.hash_algorithm sig maybeKey = OpenPGP.signature_issuer sig >>= find_key keys + -- in trace ("maybeKey="++show (fmap OpenPGP.key_algorithm r)) r -- cgit v1.2.3