diff options
Diffstat (limited to 'Data/OpenPGP/Util/Gen.hs')
-rw-r--r-- | Data/OpenPGP/Util/Gen.hs | 16 |
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 | |||
14 | import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA | 14 | import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA |
15 | import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA | 15 | import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA |
16 | #if defined(VERSION_cryptonite) | 16 | #if defined(VERSION_cryptonite) |
17 | import qualified Crypto.PubKey.Ed25519 as Ed25519 | ||
18 | import Data.OpenPGP.Util.Ed25519 | ||
17 | import Control.Arrow (second) | 19 | import Control.Arrow (second) |
18 | import Data.Binary | 20 | import Data.Binary |
19 | #endif | 21 | #endif |
@@ -22,7 +24,7 @@ import Data.OpenPGP.Util.Base | |||
22 | 24 | ||
23 | data GenerateKeyParams = GenRSA Int -- keysize | 25 | data 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 | ||
28 | data DSAParams = DSAParams | 30 | data DSAParams = DSAParams |
@@ -32,8 +34,9 @@ data DSAParams = DSAParams | |||
32 | deriving (Eq,Ord,Show) | 34 | deriving (Eq,Ord,Show) |
33 | 35 | ||
34 | genKeyAlg :: GenerateKeyParams -> KeyAlgorithm | 36 | genKeyAlg :: GenerateKeyParams -> KeyAlgorithm |
35 | genKeyAlg (GenRSA _) = RSA | 37 | genKeyAlg (GenRSA _) = RSA |
36 | genKeyAlg (GenDSA _) = DSA | 38 | genKeyAlg (GenDSA _) = DSA |
39 | genKeyAlg (GenEd25519 {}) = Ed25519 | ||
37 | 40 | ||
38 | -- | Generate a secret key pgp packet from system entropy. | 41 | -- | Generate a secret key pgp packet from system entropy. |
39 | generateKey :: GenerateKeyParams -> IO Packet | 42 | generateKey :: 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' ) |
121 | generateKey' (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 | ||