From 92c83aae833d979a9e39cfaee109ce06d94dbb34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20N=C3=A1jera?= Date: Tue, 6 Jul 2021 20:52:13 +0200 Subject: Implement monoid for ECPoint --- ecc.hs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ecc.hs') diff --git a/ecc.hs b/ecc.hs index 0bdbf02..5bc5d8a 100644 --- a/ecc.hs +++ b/ecc.hs @@ -104,6 +104,12 @@ binaryExpansion m value result | m == 0 = result scalarProduct :: (Eq a, Fractional a) => Integer -> ECPoint a -> ECPoint a scalarProduct m ec = binaryExpansion m ec Infinity +instance (Eq a, Fractional a) => Semigroup (ECPoint a) where + (<>) = add + +instance (Eq a, Fractional a) => Monoid (ECPoint a) where + mempty = Infinity + tre = FieldElement 3 :: FieldElement 31 cc = let a = ECPoint tre (-7) 5 7 @@ -133,6 +139,7 @@ aPoint = ECPoint 192 105 0 7 :: ECPoint (FieldElement 223) total = add aPoint $ add aPoint $ add aPoint $ add aPoint aPoint totalfold=foldr add Infinity $ replicate 5 aPoint +totalmconcat = mconcat $ replicate 5 aPoint type S256Field = FieldElement (2 ^ 256- 2^ 32 - 977) type S256Point = ECPoint S256Field -- cgit v1.2.3