summaryrefslogtreecommitdiff
path: root/Data/OpenPGP/Util/Verify.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-12-15 22:06:29 -0500
committerjoe <joe@jerkface.net>2013-12-15 22:06:29 -0500
commit395f75c6b7f66d313b4d44be4ed1317f9d7c7042 (patch)
treef66e931fb49cca89a0faa5bcc6a66c52418505a0 /Data/OpenPGP/Util/Verify.hs
parent8dd042382eb2a676bac6cd266268ef4d3ed2b390 (diff)
Adapted to new ecc solutoin for OpenPGP-Haskell
Diffstat (limited to 'Data/OpenPGP/Util/Verify.hs')
-rw-r--r--Data/OpenPGP/Util/Verify.hs23
1 files changed, 23 insertions, 0 deletions
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 @@
1{-# LANGUAGE OverloadedStrings #-}
1module Data.OpenPGP.Util.Verify where 2module Data.OpenPGP.Util.Verify where
2 3
4import Debug.Trace
3import qualified Data.OpenPGP as OpenPGP 5import qualified Data.OpenPGP as OpenPGP
4import Data.Maybe 6import Data.Maybe
5import Data.Binary (encode) 7import Data.Binary (encode)
@@ -9,6 +11,8 @@ import qualified Data.ByteString.Lazy as LZ
9 11
10import qualified Crypto.PubKey.DSA as Vincent.DSA 12import qualified Crypto.PubKey.DSA as Vincent.DSA
11import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA 13import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA
14import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA
15-- import Math.NumberTheory.Moduli
12 16
13import Data.OpenPGP.Util.Base 17import Data.OpenPGP.Util.Base
14 18
@@ -19,6 +23,14 @@ dsaKey k = Vincent.DSA.PublicKey
19 (keyParam 'y' k) 23 (keyParam 'y' k)
20 24
21 25
26{-
27applyCurve :: Vincent.ECDSA.CurveCommon -> Integer -> Integer
28applyCurve curve x = x*x*x + x*a + b
29 where
30 a = Vincent.ECDSA.ecc_a curve
31 b = Vincent.ECDSA.ecc_b curve
32-}
33
22-- | Verify a message signature 34-- | Verify a message signature
23verify :: 35verify ::
24 OpenPGP.Message -- ^ Keys that may have made the signature 36 OpenPGP.Message -- ^ Keys that may have made the signature
@@ -35,17 +47,28 @@ verifyOne keys sig over = fmap (const sig) $ maybeKey >>= verification >>= guard
35 where 47 where
36 verification = case OpenPGP.key_algorithm sig of 48 verification = case OpenPGP.key_algorithm sig of
37 OpenPGP.DSA -> dsaVerify 49 OpenPGP.DSA -> dsaVerify
50 OpenPGP.ECDSA -> ecdsaVerify
38 alg | alg `elem` [OpenPGP.RSA,OpenPGP.RSA_S] -> rsaVerify 51 alg | alg `elem` [OpenPGP.RSA,OpenPGP.RSA_S] -> rsaVerify
39 | otherwise -> const Nothing 52 | otherwise -> const Nothing
40 dsaVerify k = let k' = dsaKey k in 53 dsaVerify k = let k' = dsaKey k in
41 Just $ Vincent.DSA.verify (dsaTruncate k' . bhash) k' dsaSig over 54 Just $ Vincent.DSA.verify (dsaTruncate k' . bhash) k' dsaSig over
55 ecdsaVerify k = let k' = ecdsaKey k
56 r = Just $ Vincent.ECDSA.verify bhash k' ecdsaSig over
57 in r -- trace ("ecdsaVerify: "++show r) r
42 rsaVerify k = Just $ Vincent.RSA.verify desc (rsaKey k) over rsaSig 58 rsaVerify k = Just $ Vincent.RSA.verify desc (rsaKey k) over rsaSig
43 [rsaSig] = map (toStrictBS . LZ.drop 2 . encode) (OpenPGP.signature sig) 59 [rsaSig] = map (toStrictBS . LZ.drop 2 . encode) (OpenPGP.signature sig)
44 dsaSig = let [OpenPGP.MPI r, OpenPGP.MPI s] = OpenPGP.signature sig in 60 dsaSig = let [OpenPGP.MPI r, OpenPGP.MPI s] = OpenPGP.signature sig in
45 Vincent.DSA.Signature r s 61 Vincent.DSA.Signature r s
62 ecdsaSig = let [OpenPGP.MPI r, OpenPGP.MPI s] = OpenPGP.signature sig in
63 Vincent.ECDSA.Signature r s
46 dsaTruncate (Vincent.DSA.PublicKey (Vincent.DSA.Params _ _ q) _) = BS.take (integerBytesize q) 64 dsaTruncate (Vincent.DSA.PublicKey (Vincent.DSA.Params _ _ q) _) = BS.take (integerBytesize q)
65 {-
66 ecdsaTruncate (Vincent.ECDSA.PublicKey _ (Vincent.ECDSA.Point x y)) = BS.take (integerBytesize x
67 + integerBytesize y )
68 -}
47 bhash = hashBySymbol hash_algo . toLazyBS 69 bhash = hashBySymbol hash_algo . toLazyBS
48 desc = hashAlgoDesc hash_algo 70 desc = hashAlgoDesc hash_algo
49 hash_algo = OpenPGP.hash_algorithm sig 71 hash_algo = OpenPGP.hash_algorithm sig
50 maybeKey = OpenPGP.signature_issuer sig >>= find_key keys 72 maybeKey = OpenPGP.signature_issuer sig >>= find_key keys
73 -- in trace ("maybeKey="++show (fmap OpenPGP.key_algorithm r)) r
51 74