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) <- 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
CryptoFailable (Point curve, SharedSecret)
-> randomly (CryptoFailable (Point curve, SharedSecret))
forall a. a -> randomly a
forall (m :: * -> *) a. Monad m => a -> m a
return (CryptoFailable (Point curve, SharedSecret)
-> randomly (CryptoFailable (Point curve, SharedSecret)))
-> CryptoFailable (Point curve, SharedSecret)
-> randomly (CryptoFailable (Point curve, SharedSecret))
forall a b. (a -> b) -> a -> b
$ (\SharedSecret
s -> (Point curve
rPoint, SharedSecret
s)) (SharedSecret -> (Point curve, SharedSecret))
-> CryptoFailable SharedSecret
-> CryptoFailable (Point curve, SharedSecret)
forall a b. (a -> b) -> CryptoFailable a -> CryptoFailable b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` 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
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 = 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