From a6f177352a31706ab73cb27af21d9fac2afc1c03 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 16 Nov 2016 16:53:43 +0900 Subject: [PATCH] Eq and Show for Point and Scalar. --- Crypto/ECC.hs | 28 ++++++++++++++++++++-------- Crypto/PubKey/ECC/P256.hs | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Crypto/ECC.hs b/Crypto/ECC.hs index eb8541e..24c20ea 100644 --- a/Crypto/ECC.hs +++ b/Crypto/ECC.hs @@ -68,6 +68,18 @@ class EllipticCurve curve where -- | Generate a new random keypair curveGenerateKeyPair :: MonadRandom randomly => randomly (KeyPair curve) +instance {-# OVERLAPPABLE #-} Show (Point a) where + show _ = undefined + +instance {-# OVERLAPPABLE #-} Eq (Point a) where + _ == _ = undefined + +instance {-# OVERLAPPABLE #-} Show (Scalar a) where + show _ = undefined + +instance {-# OVERLAPPABLE #-} Eq (Scalar a) where + _ == _ = undefined + class EllipticCurve curve => EllipticCurveDH curve where -- | Generate a Diffie hellman secret value. -- @@ -93,8 +105,8 @@ class EllipticCurve curve => EllipticCurveArith curve where data Curve_P256R1 = Curve_P256R1 instance EllipticCurve Curve_P256R1 where - newtype Point Curve_P256R1 = P256Point { unP256Point :: P256.Point } - newtype Scalar Curve_P256R1 = P256Scalar { unP256Scalar :: P256.Scalar } + newtype Point Curve_P256R1 = P256Point { unP256Point :: P256.Point } deriving (Eq,Show) + newtype Scalar Curve_P256R1 = P256Scalar { unP256Scalar :: P256.Scalar } deriving (Eq,Show) curveGetOrder _ = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 curveGetBasePoint = P256Point P256.pointBase curveOfScalar _ = Curve_P256R1 @@ -117,8 +129,8 @@ instance EllipticCurveDH Curve_P256R1 where data Curve_P384R1 = Curve_P384R1 instance EllipticCurve Curve_P384R1 where - newtype Point Curve_P384R1 = P384Point { unP384Point :: H.Point } - newtype Scalar Curve_P384R1 = P384Scalar { unP384Scalar :: H.PrivateNumber } + newtype Point Curve_P384R1 = P384Point { unP384Point :: H.Point } deriving (Eq,Show) + newtype Scalar Curve_P384R1 = P384Scalar { unP384Scalar :: H.PrivateNumber } deriving (Eq,Show) curveGetOrder _ = H.ecc_n $ H.common_curve $ H.getCurveByName H.SEC_p384r1 curveGetBasePoint = P384Point $ H.ecc_g $ H.common_curve $ H.getCurveByName H.SEC_p384r1 curveOfScalar _ = Curve_P384R1 @@ -141,8 +153,8 @@ instance EllipticCurveDH Curve_P384R1 where data Curve_P521R1 = Curve_P521R1 instance EllipticCurve Curve_P521R1 where - newtype Point Curve_P521R1 = P521Point { unP521Point :: H.Point } - newtype Scalar Curve_P521R1 = P521Scalar { unP521Scalar :: H.PrivateNumber } + newtype Point Curve_P521R1 = P521Point { unP521Point :: H.Point } deriving (Eq,Show) + newtype Scalar Curve_P521R1 = P521Scalar { unP521Scalar :: H.PrivateNumber } deriving (Eq,Show) curveGetOrder _ = H.ecc_n $ H.common_curve $ H.getCurveByName H.SEC_p521r1 curveGetBasePoint = P521Point $ H.ecc_g $ H.common_curve $ H.getCurveByName H.SEC_p521r1 curveOfScalar _ = Curve_P521R1 @@ -165,8 +177,8 @@ instance EllipticCurveDH Curve_P521R1 where data Curve_X25519 = Curve_X25519 instance EllipticCurve Curve_X25519 where - newtype Point Curve_X25519 = X25519Point X25519.PublicKey - newtype Scalar Curve_X25519 = X25519Scalar X25519.SecretKey + newtype Point Curve_X25519 = X25519Point X25519.PublicKey deriving (Eq,Show) + newtype Scalar Curve_X25519 = X25519Scalar X25519.SecretKey deriving (Eq,Show) curveGetOrder _ = undefined curveGetBasePoint = undefined curveOfScalar _ = Curve_X25519 diff --git a/Crypto/PubKey/ECC/P256.hs b/Crypto/PubKey/ECC/P256.hs index f7048f7..f8fa113 100644 --- a/Crypto/PubKey/ECC/P256.hs +++ b/Crypto/PubKey/ECC/P256.hs @@ -56,7 +56,7 @@ import qualified Crypto.Number.Serialize as S (os2ip, i2ospOf) -- | A P256 scalar newtype Scalar = Scalar ScrubbedBytes - deriving (Eq,ByteArrayAccess) + deriving (Show,Eq,ByteArrayAccess) -- | A P256 point newtype Point = Point Bytes