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 Point curve
rPoint Scalar curve
rScalar) <- forall curve (randomly :: * -> *) (proxy :: * -> *).
(EllipticCurve curve, MonadRandom randomly) =>
proxy curve -> randomly (KeyPair curve)
curveGenerateKeyPair proxy curve
proxy
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (\SharedSecret
s -> (Point curve
rPoint, SharedSecret
s)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall curve (proxy :: * -> *).
EllipticCurveDH curve =>
proxy curve
-> Scalar curve -> Point curve -> CryptoFailable SharedSecret
ecdh proxy curve
proxy Scalar curve
rScalar Point curve
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 = forall curve (proxy :: * -> *).
EllipticCurveDH curve =>
proxy curve
-> Scalar curve -> Point curve -> CryptoFailable SharedSecret
ecdh proxy curve
proxy Scalar curve
secret Point curve
point