module Crypto.PubKey.ECIES (
deriveEncrypt,
deriveDecrypt,
) where
import Crypto.ECC
import Crypto.Error
import Crypto.Random
deriveEncrypt
:: (MonadRandom randomly, EllipticCurveDH curve)
=> proxy curve
-> Point curve
-> randomly (CryptoFailable (Point curve, SharedSecret))
deriveEncrypt :: forall (randomly :: * -> *) curve (proxy :: * -> *).
(MonadRandom randomly, EllipticCurveDH curve) =>
proxy curve
-> Point curve
-> randomly (CryptoFailable (Point curve, SharedSecret))
deriveEncrypt proxy curve
proxy Point curve
pub = do
(KeyPair rPoint rScalar) <- proxy curve -> randomly (KeyPair curve)
forall curve (randomly :: * -> *) (proxy :: * -> *).
(EllipticCurve curve, MonadRandom randomly) =>
proxy curve -> randomly (KeyPair curve)
forall (randomly :: * -> *) (proxy :: * -> *).
MonadRandom randomly =>
proxy curve -> randomly (KeyPair curve)
curveGenerateKeyPair proxy curve
proxy
return $ (\SharedSecret
s -> (Point curve
rPoint, SharedSecret
s)) `fmap` ecdh proxy rScalar pub
deriveDecrypt
:: EllipticCurveDH curve
=> proxy curve
-> Point curve
-> Scalar curve
-> CryptoFailable SharedSecret
deriveDecrypt :: forall curve (proxy :: * -> *).
EllipticCurveDH curve =>
proxy curve
-> Point curve -> Scalar curve -> CryptoFailable SharedSecret
deriveDecrypt proxy curve
proxy Point curve
point Scalar curve
secret = proxy curve
-> Scalar curve -> Point curve -> CryptoFailable SharedSecret
forall curve (proxy :: * -> *).
EllipticCurveDH curve =>
proxy curve
-> Scalar curve -> Point curve -> CryptoFailable SharedSecret
forall (proxy :: * -> *).
proxy curve
-> Scalar curve -> Point curve -> CryptoFailable SharedSecret
ecdh proxy curve
proxy Scalar curve
secret Point curve
point