From 02680b1ed3b37c0cc16e04e51e613d53ff9dbab8 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Fri, 15 Nov 2019 16:27:28 -0500 Subject: cv25519: Fixed missing algorithm preferences. --- Data/OpenPGP/Util/Cv25519.hs | 8 ++++++-- Data/OpenPGP/Util/Gen.hs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Data/OpenPGP/Util/Cv25519.hs b/Data/OpenPGP/Util/Cv25519.hs index d5ac641..abf1ba6 100644 --- a/Data/OpenPGP/Util/Cv25519.hs +++ b/Data/OpenPGP/Util/Cv25519.hs @@ -230,13 +230,17 @@ decryptMessage ecdhkey asym encdta = do (_,_, Message ps) <- either (const Nothing) Just $ decodeOrFail b1 return ps -importSecretCv25519 :: Cv25519.SecretKey -> [(Char,MPI)] -importSecretCv25519 k = +encodeAlgorithms :: OpenPGP.HashAlgorithm -> OpenPGP.SymmetricAlgorithm -> Integer +encodeAlgorithms hsh sym = fromIntegral $ 0x03010000 .|. (fromEnum hsh `shiftR` 8) .|. fromEnum sym + +importSecretCv25519 :: OpenPGP.HashAlgorithm -> OpenPGP.SymmetricAlgorithm -> Cv25519.SecretKey -> [(Char,MPI)] +importSecretCv25519 hsh sym k = [ ('c', MPI oid_cv25519) , ('l', MPI 128) , ('n', MPI pub) , ('f', MPI 0x40) , ('d', MPI sec) + , ('e', MPI $ encodeAlgorithms hsh sym) ] where pub = getBigNum $ BA.convert $ Cv25519.toPublic k diff --git a/Data/OpenPGP/Util/Gen.hs b/Data/OpenPGP/Util/Gen.hs index babd12d..713e909 100644 --- a/Data/OpenPGP/Util/Gen.hs +++ b/Data/OpenPGP/Util/Gen.hs @@ -127,7 +127,7 @@ generateKey' (GenEd25519 {}) g = withDRG g $ do return $ importSecretEd25519 k generateKey' (GenCv25519 {}) g = withDRG g $ do k <- Cv25519.generateSecretKey - return $ importSecretCv25519 k + return $ importSecretCv25519 SHA512 AES128 k #endif -- cgit v1.2.3