pairing 0.4.1 → 0.4.2
raw patch · 10 files changed
+77/−80 lines, 10 filesdep ~galois-field
Dependency ranges changed: galois-field
Files
- ChangeLog.md +11/−7
- bench/BenchPairing.hs +14/−14
- pairing.cabal +12/−11
- src/Pairing/Fq.hs +23/−28
- src/Pairing/Fr.hs +0/−3
- src/Pairing/Group.hs +5/−5
- src/Pairing/Pairing.hs +2/−2
- tests/TestFields.hs +5/−5
- tests/TestGroups.hs +3/−3
- tests/TestPairing.hs +2/−2
ChangeLog.md view
@@ -1,9 +1,13 @@-# Changelog for pairing+# Change log for pairing +## 0.4.2++* Fix overlapping instances of `Ord`.+ ## 0.4.1 -* Add mclwasm compatible serialisation-* Add efficient storage representation of an elliptic curve point over prime fields+* Add mclwasm compatible serialisation.+* Add efficient storage representation of an elliptic curve point over prime fields. ## 0.4 @@ -15,13 +19,13 @@ ## 0.3 -- Square root calculation on Fq2-- Both square roots returned on Fq-- Point serialisation for G1, G2 and GT+- Square root calculation on Fq2.+- Both square roots returned on Fq.+- Point serialisation for G1, G2 and GT. ## 0.2 -* Adds Shallue van de Woestijne encoding for curve hashing.+* Add Shallue van de Woestijne encoding for curve hashing. ## 0.1
bench/BenchPairing.hs view
@@ -29,37 +29,37 @@ testFr_2 = 18361718052247311177607809961708721447660708684581683997732416822928487385039 testFq2_1 :: Fq.Fq2-testFq2_1 = fromList+testFq2_1 = toField [ 19908898611787582971615951530393785823319364696376311494770162270472288380562 , 2444690988583914246674870181013910409542697083717824402984851238236041783759 ] testFq2_2 :: Fq.Fq2-testFq2_2 = fromList+testFq2_2 = toField [ 176307305890807650390915550856467756101144733976249050387177647283239486934 , 9913547941088878400547309488585076816688958962210000330808066250849942240036 ] testFq6_1 :: Fq.Fq6-testFq6_1 = fromList- [ fromList+testFq6_1 = toField+ [ toField [ 8727269669017421992537561450387212506711577304101544328736696625792447584819 , 14548604791762199086915107662335514800873255588931510951007415299299859294564 ]- , fromList+ , toField [ 12226353852518517213098257637254082040554292743096797524265221809863992104040 , 12690801089710533803594523982915673248220237967492611523932652691226365708512 ]- , fromList+ , toField [ 18336930404004840796680535059992401039831316705513753839479258873269709495858 , 21634580953983557175729336703450663797341055784728343534694506874757389871868 ] ] testFq6_2 :: Fq.Fq6-testFq6_2 = fromList- [ fromList+testFq6_2 = toField+ [ toField [ 21427158918811764040959407626476119248515601360702754918240300689672054041331 , 12750457256357562507331331307761996193149796736574153338180573114576232473092 ]- , fromList+ , toField [ 19307896751125425658868292427117755307914453765471505616446813557567103424424 , 11511704315039881938763578963465960361806962511008317843374696569679546862720 ]- , fromList+ , toField [ 16856354813335682789816416666746807604324955216244680818919639213184967817815 , 10563739714379631354612735346769824530666877338817980746884577737330686430079 ] ]@@ -108,22 +108,22 @@ test_g2_1 :: Group.G2 test_g2_1 = Point.Point- (fromList+ (toField [ 7883069657575422103991939149663123175414599384626279795595310520790051448551 , 8346649071297262948544714173736482699128410021416543801035997871711276407441 ] )- (fromList+ (toField [ 3343323372806643151863786479815504460125163176086666838570580800830972412274 , 16795962876692295166012804782785252840345796645199573986777498170046508450267 ] ) test_g2_2 :: Group.G2 test_g2_2 = Point.Point- (fromList+ (toField [ 3243608945627071355385114622932133122087974401138668305336804137033580208808 , 2403320200938270623472619242963887735471304641554649101656774729615146397552 ] )- (fromList+ (toField [ 7590136428571280465598215063146990078553196689176860926896020586846726844869 , 8036135660414384292776446470327730948618639044617118659780848199544099832559 ] )
pairing.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: 80d5b7b460cd15c793b86c61d342bfb609e71fb776fcd8c1d7532aaf6e978334+-- hash: 8756cf9d25050b2735941c749a9fa41f381c79117dae3353b4453d7d1318c65e name: pairing-version: 0.4.1+version: 0.4.2 synopsis: Bilinear pairings description: Optimal Ate pairing over Barreto-Naehrig curves category: Cryptography@@ -15,10 +17,9 @@ license: MIT license-file: LICENSE build-type: Simple-cabal-version: >= 1.10 extra-source-files:- ChangeLog.md README.md+ ChangeLog.md source-repository head type: git@@ -44,7 +45,7 @@ Paths_pairing hs-source-dirs: src- default-extensions: LambdaCase RecordWildCards OverloadedStrings NoImplicitPrelude FlexibleInstances FlexibleContexts ScopedTypeVariables RankNTypes BangPatterns DataKinds DeriveAnyClass DeriveFunctor DeriveGeneric GeneralizedNewtypeDeriving MultiParamTypeClasses TypeApplications+ default-extensions: LambdaCase RecordWildCards OverloadedStrings NoImplicitPrelude FlexibleInstances FlexibleContexts ScopedTypeVariables RankNTypes BangPatterns DataKinds DeriveAnyClass DeriveFunctor DeriveGeneric GeneralizedNewtypeDeriving MultiParamTypeClasses PatternSynonyms TypeApplications ghc-options: -fwarn-tabs -fwarn-incomplete-patterns -fwarn-incomplete-record-updates -fwarn-redundant-constraints -fwarn-implicit-prelude -fwarn-overflowed-literals -fwarn-orphans -fwarn-identities -fwarn-dodgy-exports -fwarn-dodgy-imports -fwarn-duplicate-exports -fwarn-overlapping-patterns -fwarn-missing-fields -fwarn-missing-methods -fwarn-missing-signatures -fwarn-noncanonical-monad-instances -fwarn-unused-pattern-binds -fwarn-unused-type-patterns -fwarn-unrecognised-pragmas -fwarn-wrong-do-bind -fno-warn-name-shadowing -fno-warn-unused-binds -fno-warn-unused-matches -fno-warn-unused-do-bind -Wmissing-export-lists build-depends: MonadRandom@@ -54,7 +55,7 @@ , binary , bytestring , errors- , galois-field >=0.2+ , galois-field ==0.4.0 , integer-logarithms , memory , protolude >=0.2@@ -88,7 +89,7 @@ hs-source-dirs: src tests- default-extensions: LambdaCase RecordWildCards OverloadedStrings NoImplicitPrelude FlexibleInstances FlexibleContexts ScopedTypeVariables RankNTypes DataKinds DeriveAnyClass DeriveFunctor DeriveGeneric MultiParamTypeClasses TypeApplications TypeSynonymInstances+ default-extensions: LambdaCase RecordWildCards OverloadedStrings NoImplicitPrelude FlexibleInstances FlexibleContexts ScopedTypeVariables RankNTypes DataKinds DeriveAnyClass DeriveFunctor DeriveGeneric MultiParamTypeClasses PatternSynonyms TypeApplications TypeSynonymInstances build-depends: MonadRandom , QuickCheck@@ -97,7 +98,7 @@ , binary , bytestring , errors- , galois-field >=0.2+ , galois-field ==0.4.0 , hexstring , integer-logarithms , memory@@ -119,7 +120,7 @@ hs-source-dirs: src bench- default-extensions: NoImplicitPrelude OverloadedStrings FlexibleInstances FlexibleContexts ScopedTypeVariables RankNTypes DataKinds DeriveAnyClass DeriveFunctor DeriveGeneric MultiParamTypeClasses TypeApplications+ default-extensions: NoImplicitPrelude OverloadedStrings FlexibleInstances FlexibleContexts ScopedTypeVariables RankNTypes DataKinds DeriveAnyClass DeriveFunctor DeriveGeneric MultiParamTypeClasses PatternSynonyms TypeApplications build-depends: MonadRandom , QuickCheck@@ -129,7 +130,7 @@ , bytestring , criterion , errors- , galois-field >=0.2+ , galois-field ==0.4.0 , integer-logarithms , memory , protolude >=0.2
src/Pairing/Fq.hs view
@@ -32,7 +32,8 @@ import Protolude import Data.ByteString as B (splitAt, length)-import ExtensionField (ExtensionField, IrreducibleMonic(..), fromField, fromList, t, x)+import ExtensionField (ExtensionField, IrreducibleMonic(..), fromField, toField,+ pattern X, pattern X2, pattern X3, pattern Y) import GaloisField (GaloisField(..)) import Math.NumberTheory.Moduli.Class (powMod) import PrimeField (PrimeField, toInt)@@ -52,7 +53,7 @@ -- | Quadratic irreducible monic polynomial @f(u) = u^2 + 1@ data PolynomialU instance IrreducibleMonic Fq PolynomialU where- split _ = x^2 + 1+ split _ = X2 + 1 -- | Quadratic extension field of @Fq@ defined as @Fq2 = Fq[u]/<f(u)>@ type Fq2 = ExtensionField Fq PolynomialU@@ -60,7 +61,7 @@ -- | Cubic irreducible monic polynomial @g(v) = v^3 - (9 + u)@ data PolynomialV instance IrreducibleMonic Fq2 PolynomialV where- split _ = x^3 - (9 + t x)+ split _ = X3 - (9 + Y X) -- | Cubic extension field of @Fq2@ defined as @Fq6 = Fq2[v]/<g(v)>@ type Fq6 = ExtensionField Fq2 PolynomialV@@ -68,7 +69,7 @@ -- | Quadratic irreducible monic polynomial @h(w) = w^2 - v@ data PolynomialW instance IrreducibleMonic Fq6 PolynomialW where- split _ = x^2 - t x+ split _ = X2 - Y X -- | Quadratic extension field of @Fq6@ defined as @Fq12 = Fq6[w]/<h(w)>@ type Fq12 = ExtensionField Fq6 PolynomialW@@ -77,12 +78,6 @@ -- Instances ------------------------------------------------------------------------------- -instance Ord Fq where- compare = on compare toInt--instance Ord Fq2 where- compare = on compare fromField- instance FromX Fq where yFromX = fqYforX isOdd y = odd (toInt y)@@ -108,7 +103,7 @@ (xbs, ybs) = B.splitAt blen bs x <- fromRepr bo (1 :: Fq) xbs y <- fromRepr bo (1 :: Fq) ybs- return (fromList [x, y])+ return (toField [x, y]) calcReprLength _ n = 2 * calcReprLength (1 :: Fq) n instance ByteRepr Fq6 where@@ -123,7 +118,7 @@ x <- fromRepr bo (1 :: Fq2) xbs y <- fromRepr bo (1 :: Fq2) ybs z <- fromRepr bo (1 :: Fq2) zbs- return (fromList [x, y, z])+ return (toField [x, y, z]) calcReprLength _ n = 3 * calcReprLength (1 :: Fq2) n instance ByteRepr Fq12 where@@ -136,7 +131,7 @@ (xbs, ybs) = B.splitAt blen bs x <- fromRepr bo (1 :: Fq6) xbs y <- fromRepr bo (1 :: Fq6) ybs- return (fromList [x, y])+ return (toField [x, y]) calcReprLength _ n = 2 * calcReprLength (1 :: Fq6) n -------------------------------------------------------------------------------@@ -159,7 +154,7 @@ let a0 = pow alpha _q * alpha if a0 == -1 then Nothing else do let x0 = a1 * a- if alpha == -1 then Just (a1 * fromList [0, 1]) else do+ if alpha == -1 then Just (a1 * toField [0, 1]) else do let b = pow (alpha + 1) qm1by2 Just (b * x0) where@@ -188,15 +183,15 @@ -- | Cubic non-residue in @Fq2@ xi :: Fq2-xi = fromList [fromInteger _xiA, fromInteger _xiB]+xi = toField [fromInteger _xiA, fromInteger _xiB] -- | Multiply by @xi@ (cubic nonresidue in @Fq2@) and reorder coefficients mulXi :: Fq6 -> Fq6 mulXi w = case fromField w of- [x, y, z] -> fromList [z * xi, x, y]- [x, y] -> fromList [0, x, y]- [x] -> fromList [0, x]- [] -> fromList []+ [x, y, z] -> toField [z * xi, x, y]+ [x, y] -> toField [0, x, y]+ [x] -> toField [0, x]+ [] -> toField [] _ -> panic "mulXi not exhaustive." {-# INLINE mulXi #-} @@ -233,29 +228,29 @@ -- | Conjugation fq2Conj :: Fq2 -> Fq2 fq2Conj x = case fromField x of- [y, z] -> fromList [y, -z]- [y] -> fromList [y]+ [y, z] -> toField [y, -z]+ [y] -> toField [y] [] -> 0 _ -> panic "fq2Conj not exhaustive." -- | Multiplication by a scalar in @Fq@ fq2ScalarMul :: Fq -> Fq2 -> Fq2-fq2ScalarMul a x = fromList [a] * x+fq2ScalarMul a x = toField [a] * x -- | Conjugation fq12Conj :: Fq12 -> Fq12 fq12Conj x = case fromField x of- [y, z] -> fromList [y, -z]- [y] -> fromList [y]+ [y, z] -> toField [y, -z]+ [y] -> toField [y] [] -> 0 _ -> panic "fq12Conj not exhaustive." -- | Create a new value in @Fq12@ by providing a list of twelve coefficients -- in @Fq@, should be used instead of the @Fq12@ constructor. construct :: [Fq] -> Fq12-construct [a, b, c, d, e, f, g, h, i, j, k, l] = fromList- [ fromList [fromList [a, b], fromList [c, d], fromList [e, f]]- , fromList [fromList [g, h], fromList [i, j], fromList [k, l]] ]+construct [a, b, c, d, e, f, g, h, i, j, k, l] = toField+ [ toField [toField [a, b], toField [c, d], toField [e, f]]+ , toField [toField [g, h], toField [i, j], toField [k, l]] ] construct _ = panic "Invalid arguments to fq12" -- | Deconstruct a value in @Fq12@ into a list of twelve coefficients in @Fq@.@@ -280,4 +275,4 @@ convert :: [[Integer]] -> [[Fq2]] -> [[Fq2]] convert = zipWith (zipWith (\x y -> pow xi ((x * (_q - 1)) `div` 6) * y)) collapse :: [[Fq2]] -> Fq12- collapse = fromList . map fromList+ collapse = toField . map toField
src/Pairing/Fr.hs view
@@ -25,9 +25,6 @@ -- | Prime field @Fr@ with characteristic @_r@ type Fr = PrimeField 21888242871839275222246405745257275088548364400416034343698204186575808495617 -instance Ord Fr where- compare = on compare toInt- ------------------------------------------------------------------------------- -- Roots of unity -------------------------------------------------------------------------------
src/Pairing/Group.hs view
@@ -24,7 +24,7 @@ import Control.Monad.Random (MonadRandom) import Data.Semigroup ((<>))-import ExtensionField (fromList)+import ExtensionField (toField) import GaloisField (GaloisField(..)) import PrimeField (toInt) import Test.QuickCheck (Arbitrary(..), Gen)@@ -104,11 +104,11 @@ g2 :: G2 g2 = Point x y where- x = fromList+ x = toField [ 10857046999023057135944570762232829481370756359578518086990519993285655852781 , 11559732032986387107991004021392285783925812861821192530917403151452391805634 ] - y = fromList+ y = toField [ 8495653923123431417604973247489272438418190587263600148770280649306958101930 , 4082367875863433681332203403145435568316851327593401208105741076214120093531 ] @@ -122,7 +122,7 @@ -- equation isOnCurveG2 :: G2 -> Bool isOnCurveG2 Infinity = True-isOnCurveG2 (Point x y) = pow y 2 == pow x 3 + fromList [fromInteger _b] / xi+isOnCurveG2 (Point x y) = pow y 2 == pow x 3 + toField [fromInteger _b] / xi -- | Test whether a value is an _r-th root of unity isInGT :: GT -> Bool@@ -134,7 +134,7 @@ -- | Parameter for twisted curve over Fq2 b2 :: Fq2-b2 = fromList [b1] / xi+b2 = toField [b1] / xi ------------------------------------------------------------------------------- -- Generators
src/Pairing/Pairing.hs view
@@ -12,7 +12,7 @@ import Protolude import Data.List ((!!))-import ExtensionField (fromList)+import ExtensionField (toField) import GaloisField (GaloisField(..)) import Pairing.Fq@@ -89,7 +89,7 @@ {-# INLINEABLE mulBy024 #-} mulBy024 :: Fq12 -> EllCoeffs -> Fq12 mulBy024 this (EllCoeffs ell0 ellVW ellVV)- = let a = fromList [fromList [ell0, 0, ellVV], fromList [0, ellVW, 0]]+ = let a = toField [toField [ell0, 0, ellVV], toField [0, ellVW, 0]] in this * a -------------------------------------------------------------------------------
tests/TestFields.hs view
@@ -63,7 +63,7 @@ unit_uRoot :: Assertion unit_uRoot = u^2 @=? -1 where- u = fromList [0, 1] :: Fq2+ u = toField [0, 1] :: Fq2 unit_fq2Pow :: Assertion unit_fq2Pow = do@@ -91,8 +91,8 @@ unit_vRoot :: Assertion unit_vRoot = v^3 @=? 9 + u where- v = fromList [0, 1] :: Fq6- u = fromList [fromList [0, 1]]+ v = toField [0, 1] :: Fq6+ u = toField [toField [0, 1]] ------------------------------------------------------------------------------- -- Fq12@@ -105,8 +105,8 @@ unit_wRoot :: Assertion unit_wRoot = w^2 @=? v where- w = fromList [0, 1] :: Fq12- v = fromList [fromList [0, 1]]+ w = toField [0, 1] :: Fq12+ v = toField [toField [0, 1]] ------------------------------------------------------------------------------- -- Fr
tests/TestGroups.hs view
@@ -14,7 +14,7 @@ import Pairing.Serialize.Types import Pairing.Serialize.Jivsov import Pairing.Serialize.MCLWasm-import ExtensionField (fromList)+import ExtensionField (toField) import Test.Tasty import Test.Tasty.HUnit import Test.QuickCheck.Instances@@ -153,8 +153,8 @@ unit_g2SerializeCompMCLWasm :: Assertion unit_g2SerializeCompMCLWasm = do- let fq2x = fromList ([6544947162799133903546594463061476713923884516504213524167597810128866380952, 1440920261338086273401746857890494196693993714596389710801111883382590011446] :: [Fq]) :: Fq2- let fq2y = fromList ([7927561822697823059695659663409507948904771679743888257723485312240532833493, 2189896469972867352153851473169755334250894385106289486234761879693772655721] :: [Fq]) :: Fq2+ let fq2x = toField ([6544947162799133903546594463061476713923884516504213524167597810128866380952, 1440920261338086273401746857890494196693993714596389710801111883382590011446] :: [Fq]) :: Fq2+ let fq2y = toField ([7927561822697823059695659663409507948904771679743888257723485312240532833493, 2189896469972867352153851473169755334250894385106289486234761879693772655721] :: [Fq]) :: Fq2 let g2pt = Point fq2x fq2y let hs = hexString "980cf2acdb1645247a512f91cbbbbb1f4fa2328c979ae26d550ec7b80e4f780e36f82f7090c4d516a2257fcee804df8421af857b2f80ffccfc11c6f52e882f83" let Right np = unserializePoint MCLWASM g2 (toSL $ H.toBytes hs)
tests/TestPairing.hs view
@@ -20,11 +20,11 @@ inpG2 :: G2 inpG2 = Point- (fromList+ (toField [ 2725019753478801796453339367788033689375851816420509565303521482350756874229 , 7273165102799931111715871471550377909735733521218303035754523677688038059653 ] )- (fromList+ (toField [ 2512659008974376214222774206987427162027254181373325676825515531566330959255 , 957874124722006818841961785324909313781880061366718538693995380805373202866 ] )