summaryrefslogtreecommitdiff
path: root/Data/OpenPGP/Util
diff options
context:
space:
mode:
Diffstat (limited to 'Data/OpenPGP/Util')
-rw-r--r--Data/OpenPGP/Util/Gen.hs1
-rw-r--r--Data/OpenPGP/Util/Sign.hs29
2 files changed, 26 insertions, 4 deletions
diff --git a/Data/OpenPGP/Util/Gen.hs b/Data/OpenPGP/Util/Gen.hs
index c33ef1e..babd12d 100644
--- a/Data/OpenPGP/Util/Gen.hs
+++ b/Data/OpenPGP/Util/Gen.hs
@@ -40,6 +40,7 @@ genKeyAlg :: GenerateKeyParams -> KeyAlgorithm
40genKeyAlg (GenRSA _) = RSA 40genKeyAlg (GenRSA _) = RSA
41genKeyAlg (GenDSA _) = DSA 41genKeyAlg (GenDSA _) = DSA
42genKeyAlg (GenEd25519 {}) = Ed25519 42genKeyAlg (GenEd25519 {}) = Ed25519
43genKeyAlg (GenCv25519 {}) = ECC
43 44
44-- | Generate a secret key pgp packet from system entropy. 45-- | Generate a secret key pgp packet from system entropy.
45generateKey :: GenerateKeyParams -> IO Packet 46generateKey :: GenerateKeyParams -> IO Packet
diff --git a/Data/OpenPGP/Util/Sign.hs b/Data/OpenPGP/Util/Sign.hs
index 085d545..c586b60 100644
--- a/Data/OpenPGP/Util/Sign.hs
+++ b/Data/OpenPGP/Util/Sign.hs
@@ -17,17 +17,22 @@ import Data.Time.Clock.POSIX
17#endif 17#endif
18import Control.Exception as Exception (IOException(..),catch) 18import Control.Exception as Exception (IOException(..),catch)
19 19
20import Data.OpenPGP.Util.Ed25519
21import Data.OpenPGP.Util.Fingerprint (fingerprint)
22import Data.OpenPGP.Util.Gen
23
24import qualified Crypto.Random as Vincent 20import qualified Crypto.Random as Vincent
25import qualified Crypto.PubKey.DSA as Vincent.DSA 21import qualified Crypto.PubKey.DSA as Vincent.DSA
26import qualified Crypto.PubKey.RSA as Vincent.RSA 22import qualified Crypto.PubKey.RSA as Vincent.RSA
27import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA 23import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA
28import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA 24import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA
25import qualified Crypto.PubKey.Curve25519 as Cv25519
29 26
27import qualified Data.ByteArray as BA
28import Crypto.XEd25519 as Xed25519
29import Data.OpenPGP.Util.Ed25519
30import Data.OpenPGP.Util.Cv25519
31import Data.OpenPGP.Util.Fingerprint (fingerprint)
32import Data.OpenPGP.Util.Gen
30import Data.OpenPGP.Util.Base 33import Data.OpenPGP.Util.Base
34import Data.OpenPGP.Internal
35
31 36
32privateECDSAkey :: OpenPGP.Packet -> Vincent.ECDSA.PrivateKey 37privateECDSAkey :: OpenPGP.Packet -> Vincent.ECDSA.PrivateKey
33privateECDSAkey k = Vincent.ECDSA.PrivateKey curve d 38privateECDSAkey k = Vincent.ECDSA.PrivateKey curve d
@@ -52,6 +57,19 @@ privateRSAkey k =
52 q = keyParam 'q' k 57 q = keyParam 'q' k
53 pubkey = rsaKey k 58 pubkey = rsaKey k
54 59
60xed25519Sign :: Vincent.MonadRandom m =>
61 Cv25519.SecretKey
62 -> OpenPGP.HashAlgorithm
63 -> BS.ByteString
64 -> m [Integer]
65xed25519Sign cv25519key hsh dta = do
66 let hashbs = hashBySymbol hsh $ LZ.fromChunks [dta]
67 (sec,pub) = Xed25519.toSigningKeyPair cv25519key
68 nonce <- Vincent.getRandomBytes 32
69 let sig = Xed25519.sign hashbs nonce sec pub
70 (rbs,sbs) = BS.splitAt 32 $ BA.convert sig
71 return [ getBigNum rbs, getBigNum sbs ]
72
55-- | Make a signature 73-- | Make a signature
56-- 74--
57-- In order to set more options on a signature, pass in a signature packet. 75-- In order to set more options on a signature, pass in a signature packet.
@@ -71,6 +89,9 @@ unsafeSign keys over hsh keyid timestamp g = (over {OpenPGP.signatures_over = [s
71 OpenPGP.DSA -> ([dsaR, dsaS], dsaG) 89 OpenPGP.DSA -> ([dsaR, dsaS], dsaG)
72 OpenPGP.ECDSA -> ([ecdsaR,ecdsaS],ecdsaG) 90 OpenPGP.ECDSA -> ([ecdsaR,ecdsaS],ecdsaG)
73 OpenPGP.Ed25519 -> (ed25519Sign k hsh dta, g) 91 OpenPGP.Ed25519 -> (ed25519Sign k hsh dta, g)
92 OpenPGP.ECC | oid_cv25519 == keyParam 'c' k
93 , Just cvk <- privateCv25519Key k
94 -> Vincent.withDRG g $ xed25519Sign cvk hsh dta
74 kalgo | kalgo `elem` [OpenPGP.RSA,OpenPGP.RSA_S] -> ([toNum rsaFinal], g) 95 kalgo | kalgo `elem` [OpenPGP.RSA,OpenPGP.RSA_S] -> ([toNum rsaFinal], g)
75 | otherwise -> 96 | otherwise ->
76 error ("Unsupported key algorithm " ++ show kalgo ++ " in sign") 97 error ("Unsupported key algorithm " ++ show kalgo ++ " in sign")