summaryrefslogtreecommitdiff
path: root/Data/OpenPGP/Util/Gen.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Data/OpenPGP/Util/Gen.hs')
-rw-r--r--Data/OpenPGP/Util/Gen.hs16
1 files changed, 13 insertions, 3 deletions
diff --git a/Data/OpenPGP/Util/Gen.hs b/Data/OpenPGP/Util/Gen.hs
index c5d0159..ca3c684 100644
--- a/Data/OpenPGP/Util/Gen.hs
+++ b/Data/OpenPGP/Util/Gen.hs
@@ -14,6 +14,8 @@ import qualified Crypto.PubKey.RSA as Vincent.RSA
14import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA 14import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA
15import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA 15import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA
16#if defined(VERSION_cryptonite) 16#if defined(VERSION_cryptonite)
17import qualified Crypto.PubKey.Ed25519 as Ed25519
18import Data.OpenPGP.Util.Ed25519
17import Control.Arrow (second) 19import Control.Arrow (second)
18import Data.Binary 20import Data.Binary
19#endif 21#endif
@@ -22,7 +24,7 @@ import Data.OpenPGP.Util.Base
22 24
23data GenerateKeyParams = GenRSA Int -- keysize 25data GenerateKeyParams = GenRSA Int -- keysize
24 | GenDSA (Maybe DSAParams) 26 | GenDSA (Maybe DSAParams)
25 27 | GenEd25519
26 deriving (Eq,Ord,Show) 28 deriving (Eq,Ord,Show)
27 29
28data DSAParams = DSAParams 30data DSAParams = DSAParams
@@ -32,8 +34,9 @@ data DSAParams = DSAParams
32 deriving (Eq,Ord,Show) 34 deriving (Eq,Ord,Show)
33 35
34genKeyAlg :: GenerateKeyParams -> KeyAlgorithm 36genKeyAlg :: GenerateKeyParams -> KeyAlgorithm
35genKeyAlg (GenRSA _) = RSA 37genKeyAlg (GenRSA _) = RSA
36genKeyAlg (GenDSA _) = DSA 38genKeyAlg (GenDSA _) = DSA
39genKeyAlg (GenEd25519 {}) = Ed25519
37 40
38-- | Generate a secret key pgp packet from system entropy. 41-- | Generate a secret key pgp packet from system entropy.
39generateKey :: GenerateKeyParams -> IO Packet 42generateKey :: GenerateKeyParams -> IO Packet
@@ -115,6 +118,13 @@ generateKey' (GenDSA mbparams) g =
115 vincent (DSAParams p g q) = Vincent.DSA.Params p g q 118 vincent (DSAParams p g q) = Vincent.DSA.Params p g q
116 (priv,g') = withDRG g $ Vincent.DSA.generatePrivate dsa_params 119 (priv,g') = withDRG g $ Vincent.DSA.generatePrivate dsa_params
117 in ( dsaFields (Vincent.DSA.PrivateKey dsa_params priv), g' ) 120 in ( dsaFields (Vincent.DSA.PrivateKey dsa_params priv), g' )
121generateKey' (GenEd25519 {}) g = withDRG g $ do
122 k <- Ed25519.generateSecretKey
123 return $ importSecretEd25519 k
124 -- file:///usr/share/doc/libghc-cryptonite-doc/html/Crypto-PubKey-Ed25519.html#v:generateSecretKey
125 -- generateSecretKey :: MonadRandom m => m SecretKey
126 -- n = public key used to verify signatures.
127 -- public_key_fields Ed25519 = ['c','l','x', 'y', 'n', 'f']
118 128
119#endif 129#endif
120 130