From b8b59be5a565706d739c9f87acbaa7fa59fce74a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Ch=C3=A9ron?= Date: Fri, 10 Nov 2017 13:11:06 +0100 Subject: [PATCH] Normalize result of ECC.pointNegate --- Crypto/ECC/Simple/Prim.hs | 2 +- Crypto/PubKey/ECC/Prim.hs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Crypto/ECC/Simple/Prim.hs b/Crypto/ECC/Simple/Prim.hs index 4a36b05..fcb0a3c 100644 --- a/Crypto/ECC/Simple/Prim.hs +++ b/Crypto/ECC/Simple/Prim.hs @@ -49,7 +49,7 @@ pointNegate :: Curve curve => Point curve -> Point curve pointNegate PointO = PointO pointNegate point@(Point x y) = case curveType point of - CurvePrime {} -> Point x (-y) + CurvePrime (CurvePrimeParam p) -> Point x (p - y) CurveBinary {} -> Point x (x `addF2m` y) -- | Elliptic Curve point addition. diff --git a/Crypto/PubKey/ECC/Prim.hs b/Crypto/PubKey/ECC/Prim.hs index a4c10b5..d87672b 100644 --- a/Crypto/PubKey/ECC/Prim.hs +++ b/Crypto/PubKey/ECC/Prim.hs @@ -31,9 +31,9 @@ scalarGenerate curve = generateBetween 1 (n - 1) -- | Elliptic Curve point negation: -- @pointNegate c p@ returns point @q@ such that @pointAdd c p q == PointO@. pointNegate :: Curve -> Point -> Point -pointNegate _ PointO = PointO -pointNegate CurveFP{} (Point x y) = Point x (-y) -pointNegate CurveF2m{} (Point x y) = Point x (x `addF2m` y) +pointNegate _ PointO = PointO +pointNegate (CurveFP c) (Point x y) = Point x (ecc_p c - y) +pointNegate CurveF2m{} (Point x y) = Point x (x `addF2m` y) -- | Elliptic Curve point addition. --