diff options
Diffstat (limited to 'Data/OpenPGP/Util')
-rw-r--r-- | Data/OpenPGP/Util/Gen.hs | 1 | ||||
-rw-r--r-- | Data/OpenPGP/Util/Sign.hs | 29 |
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 | |||
40 | genKeyAlg (GenRSA _) = RSA | 40 | genKeyAlg (GenRSA _) = RSA |
41 | genKeyAlg (GenDSA _) = DSA | 41 | genKeyAlg (GenDSA _) = DSA |
42 | genKeyAlg (GenEd25519 {}) = Ed25519 | 42 | genKeyAlg (GenEd25519 {}) = Ed25519 |
43 | genKeyAlg (GenCv25519 {}) = ECC | ||
43 | 44 | ||
44 | -- | Generate a secret key pgp packet from system entropy. | 45 | -- | Generate a secret key pgp packet from system entropy. |
45 | generateKey :: GenerateKeyParams -> IO Packet | 46 | generateKey :: 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 |
18 | import Control.Exception as Exception (IOException(..),catch) | 18 | import Control.Exception as Exception (IOException(..),catch) |
19 | 19 | ||
20 | import Data.OpenPGP.Util.Ed25519 | ||
21 | import Data.OpenPGP.Util.Fingerprint (fingerprint) | ||
22 | import Data.OpenPGP.Util.Gen | ||
23 | |||
24 | import qualified Crypto.Random as Vincent | 20 | import qualified Crypto.Random as Vincent |
25 | import qualified Crypto.PubKey.DSA as Vincent.DSA | 21 | import qualified Crypto.PubKey.DSA as Vincent.DSA |
26 | import qualified Crypto.PubKey.RSA as Vincent.RSA | 22 | import qualified Crypto.PubKey.RSA as Vincent.RSA |
27 | import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA | 23 | import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA |
28 | import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA | 24 | import qualified Crypto.PubKey.ECC.ECDSA as Vincent.ECDSA |
25 | import qualified Crypto.PubKey.Curve25519 as Cv25519 | ||
29 | 26 | ||
27 | import qualified Data.ByteArray as BA | ||
28 | import Crypto.XEd25519 as Xed25519 | ||
29 | import Data.OpenPGP.Util.Ed25519 | ||
30 | import Data.OpenPGP.Util.Cv25519 | ||
31 | import Data.OpenPGP.Util.Fingerprint (fingerprint) | ||
32 | import Data.OpenPGP.Util.Gen | ||
30 | import Data.OpenPGP.Util.Base | 33 | import Data.OpenPGP.Util.Base |
34 | import Data.OpenPGP.Internal | ||
35 | |||
31 | 36 | ||
32 | privateECDSAkey :: OpenPGP.Packet -> Vincent.ECDSA.PrivateKey | 37 | privateECDSAkey :: OpenPGP.Packet -> Vincent.ECDSA.PrivateKey |
33 | privateECDSAkey k = Vincent.ECDSA.PrivateKey curve d | 38 | privateECDSAkey 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 | ||
60 | xed25519Sign :: Vincent.MonadRandom m => | ||
61 | Cv25519.SecretKey | ||
62 | -> OpenPGP.HashAlgorithm | ||
63 | -> BS.ByteString | ||
64 | -> m [Integer] | ||
65 | xed25519Sign 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") |