|
@@ -6,8 +6,8 @@ module Data.SMTP.Crypto.Algos.CP (
|
|
|
initCp,
|
|
|
update,
|
|
|
update',
|
|
|
- checkSeal,
|
|
|
- toSeal
|
|
|
+ checkSeal
|
|
|
+-- toSeal
|
|
|
) where
|
|
|
|
|
|
import Data.ByteString (ByteString)
|
|
@@ -21,33 +21,33 @@ import qualified Data.ByteString as BS
|
|
|
import Crypto.Error
|
|
|
import Data.SMTP.Crypto.Types.CP
|
|
|
|
|
|
-data Algo = Sha512Ed25519 deriving (Eq, Ord, Bounded, Enum)
|
|
|
+data State = Sha3_512Ed25519s (Hash.Context Hashs.SHA512)
|
|
|
|
|
|
-instance Show Algo where
|
|
|
- show Sha512Ed25519 = "SHA512-ED25519"
|
|
|
-
|
|
|
-data State = Sha512Ed25519s (Hash.Context Hashs.SHA512)
|
|
|
-
|
|
|
initCp :: Algo -> State
|
|
|
-initCp Sha512Ed25519 = Sha512Ed25519s Hash.hashInit
|
|
|
+initCp Sha3_512Ed25519 = Sha3_512Ed25519s Hash.hashInit
|
|
|
+
|
|
|
update :: State -> ByteString -> State
|
|
|
-update (Sha512Ed25519s s) dt = Sha512Ed25519s $ Hash.hashUpdate s dt
|
|
|
+update (Sha3_512Ed25519s s) dt = Sha3_512Ed25519s $ Hash.hashUpdate s dt
|
|
|
+
|
|
|
update' :: State -> LBS.ByteString -> State
|
|
|
-update' (Sha512Ed25519s s) dt = Sha512Ed25519s $ Hash.hashUpdates s $ LBS.toChunks dt
|
|
|
-checkSeal :: State -> Seal.Seal -> CP -> Bool
|
|
|
-checkSeal (Sha512Ed25519s s) (Seal.Seal _ seal _) (Sha512Ed25519Cp _ pk _) = let
|
|
|
+update' (Sha3_512Ed25519s s) dt = Sha3_512Ed25519s $ Hash.hashUpdates s $ LBS.toChunks dt
|
|
|
+
|
|
|
+checkSeal :: State -> Seal.Seal -> SCP -> Bool
|
|
|
+checkSeal _ _ SAll = True
|
|
|
+checkSeal (Sha3_512Ed25519s s) (Seal.Seal _ seal _) (SCPSha3_512Ed25519 _ pk) = let
|
|
|
dg = Hash.hashFinalize s
|
|
|
sig' = Ed25519.signature seal
|
|
|
in case sig' of
|
|
|
CryptoFailed _ -> False
|
|
|
CryptoPassed sig -> Ed25519.verify pk dg sig
|
|
|
-toSeal :: State -> CP -> Maybe Seal.Seal
|
|
|
-toSeal (Sha512Ed25519s s) (Sha512Ed25519Cp cpid pk (Just sk)) = let
|
|
|
- dg = Hash.hashFinalize s
|
|
|
- sig = ba2bs $ Ed25519.sign sk pk dg
|
|
|
- in Just $ Seal.Seal cpid sig Nothing
|
|
|
-toSeal (Sha512Ed25519s _) _ = Nothing
|
|
|
+
|
|
|
+-- toSeal :: State -> SCP -> Maybe Seal.Seal
|
|
|
+-- toSeal (Sha3_512Ed25519s s) (SCPSha3_512Ed25519 cpid pk (Just sk)) = let
|
|
|
+-- dg = Hash.hashFinalize s
|
|
|
+-- sig = ba2bs $ Ed25519.sign sk pk dg
|
|
|
+-- in Just $ Seal.Seal cpid sig Nothing
|
|
|
+-- toSeal (Sha3_512Ed25519s _) _ = Nothing
|
|
|
|
|
|
|
|
|
-ba2bs :: BA.ByteArrayAccess a => a -> ByteString
|
|
|
-ba2bs = BS.pack . BA.unpack
|
|
|
+-- ba2bs :: BA.ByteArrayAccess a => a -> ByteString
|
|
|
+-- ba2bs = BS.pack . BA.unpack
|