summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsdiehl <>2019-08-13 15:00:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-08-13 15:00:00 (GMT)
commit83de526dbff29d4a3df97cf4180ae9f77319b294 (patch)
treeb1dd2fba3fc0d5ee230e03270ac461ac6ab4e297
parente91e1a13d6b11b7459c7bbf03ec4551fbe34827e (diff)
version 1.0.11.0.1
-rw-r--r--Bulletproofs/Curve.hs11
-rw-r--r--Bulletproofs/Fq.hs52
-rw-r--r--ChangeLog.md5
-rw-r--r--bulletproofs.cabal26
-rw-r--r--tests/TestProtocol.hs1
5 files changed, 25 insertions, 70 deletions
diff --git a/Bulletproofs/Curve.hs b/Bulletproofs/Curve.hs
index 0530478..db2bdbc 100644
--- a/Bulletproofs/Curve.hs
+++ b/Bulletproofs/Curve.hs
@@ -12,6 +12,7 @@ module Bulletproofs.Curve (
) where
import Protolude hiding (hash)
+import Data.Maybe (fromJust)
import Crypto.Hash
import qualified Crypto.PubKey.ECC.Generate as Crypto
@@ -20,7 +21,8 @@ import qualified Crypto.PubKey.ECC.Types as Crypto
import qualified Data.ByteArray as BA
import Crypto.Number.Serialize (os2ip)
-import Math.NumberTheory.Moduli.Sqrt (sqrtModP)
+import Math.NumberTheory.Moduli.Sqrt (sqrtsModPrime)
+import Math.NumberTheory.UniqueFactorisation (isPrime)
import Numeric
import qualified Data.List as L
@@ -98,11 +100,10 @@ _p = Crypto.ecc_p cp
generateH :: Crypto.Point -> [Char] -> Crypto.Point
generateH basePoint extra =
case yM of
- Nothing -> generateH basePoint (toS $ '1':extra)
- Just y -> if Crypto.isPointValid curve (Crypto.Point x y)
+ [] -> generateH basePoint (toS $ '1':extra)
+ (y:_) -> if Crypto.isPointValid curve (Crypto.Point x y)
then Crypto.Point x y
else generateH basePoint (toS $ '1':extra)
where
x = oracle (pointToBS basePoint <> toS extra) `mod` _p
- yM = sqrtModP (x ^ 3 + 7) _p
-
+ yM = sqrtsModPrime (fromInteger (x ^ 3 + 7)) ((fromJust (isPrime _p)))
diff --git a/Bulletproofs/Fq.hs b/Bulletproofs/Fq.hs
index e650fbf..2b4da84 100644
--- a/Bulletproofs/Fq.hs
+++ b/Bulletproofs/Fq.hs
@@ -1,68 +1,18 @@
{-# LANGUAGE TypeFamilies #-}
--- | Prime field with characteristic _q, over which the elliptic curve
--- is defined and the other finite field extensions.
---
--- * Fq
--- * Fq2 := Fq[u]/u^2 + 1
--- * Fq6 := Fq2[v]/v^3 - (9 + u)
--- * Fq12 := Fq6[w]/w^2 - v
module Bulletproofs.Fq
( Fq
, PF
- , fqRandom
- , fqPow
- , fqSqrt
- , toInt
) where
import Protolude
-import Crypto.Random (MonadRandom)
-import Crypto.Number.Generate (generateMax)
-import Math.NumberTheory.Moduli.Class (powMod)
-import PrimeField (PrimeField(..), toInt)
-import Pairing.Modular
+import PrimeField (PrimeField(..))
import Bulletproofs.Curve
-
--------------------------------------------------------------------------------
--- Types
--------------------------------------------------------------------------------
-
-- | Prime field @Fq@ with characteristic @_q@
type Fq = PrimeField 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
-- | Type family to extract the characteristic of the prime field
type family PF a where
PF (PrimeField k) = k
-
--------------------------------------------------------------------------------
--- Instances
--------------------------------------------------------------------------------
-
-instance Ord Fq where
- compare = on compare toInt
-
--------------------------------------------------------------------------------
--- Random
--------------------------------------------------------------------------------
-
-fqRandom :: MonadRandom m => m Fq
-fqRandom = fromInteger <$> generateMax _q
-
--------------------------------------------------------------------------------
--- Y for X
--------------------------------------------------------------------------------
-
-fqPow :: Integral e => Fq -> e -> Fq
-fqPow a b = fromInteger (withQ (modUnOp (toInt a) (flip powMod b)))
-{-# INLINE fqPow #-}
-
-fqSqrt :: Bool -> Fq -> Maybe Fq
-fqSqrt largestY a = do
- (y1, y2) <- withQM (modUnOpMTup (toInt a) bothSqrtOf)
- return (fromInteger ((if largestY then max else min) y1 y2))
-
-fqYforX :: Fq -> Bool -> Maybe Fq
-fqYforX x largestY = fqSqrt largestY (x `fqPow` 3 + fromInteger _b)
diff --git a/ChangeLog.md b/ChangeLog.md
index 0437bd4..94c03d8 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,5 +1,10 @@
# Changelog for bulletproofs
+## 1.0.1
+
+* Fix arithmoi dependency.
+* Fix galois-field dependency.
+
## 1.0
* Use galois-field library as dependency
diff --git a/bulletproofs.cabal b/bulletproofs.cabal
index dc0bdbc..c8cade7 100644
--- a/bulletproofs.cabal
+++ b/bulletproofs.cabal
@@ -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: c3039f817828e381dba02b51b3dd24480614dfa32254ebae4b12992e2d2a126e
+-- hash: 8d64db9eb665557111c118de02a106cc7b0671597707d1314eba6f33cfbe9dd6
name: bulletproofs
-version: 1.0.0
+version: 1.0.1
description: Please see the README on GitHub at <https://github.com/adjoint-io/bulletproofs#readme>
category: Cryptography
homepage: https://github.com/adjoint-io/bulletproofs#readme
@@ -14,10 +16,9 @@ maintainer: Adjoint Inc (info@adjoint.io)
license: Apache
license-file: LICENSE
build-type: Simple
-cabal-version: >= 1.10
extra-source-files:
- ChangeLog.md
README.md
+ ChangeLog.md
source-repository head
type: git
@@ -51,13 +52,12 @@ library
build-depends:
MonadRandom
, QuickCheck
- , arithmoi
+ , arithmoi >=0.8
, base >=4.7 && <5
, containers
, cryptonite
- , galois-field
+ , galois-field ==0.4.0
, memory
- , pairing
, protolude >=0.2
, random-shuffle
, text
@@ -78,14 +78,13 @@ test-suite bulletproofs-test
build-depends:
MonadRandom
, QuickCheck
- , arithmoi
+ , arithmoi >=0.8
, base
, bulletproofs
, containers
, cryptonite
- , galois-field
+ , galois-field ==0.4.0
, memory
- , pairing
, protolude >=0.2
, random-shuffle
, tasty
@@ -105,15 +104,14 @@ benchmark rangeproof-benchmarks
build-depends:
MonadRandom
, QuickCheck
- , arithmoi
+ , arithmoi >=0.8
, base >=4.7 && <5
, bulletproofs
, containers
, criterion >=1.5.1.0
, cryptonite
- , galois-field
+ , galois-field ==0.4.0
, memory
- , pairing
, protolude >=0.2
, random-shuffle
, tasty
diff --git a/tests/TestProtocol.hs b/tests/TestProtocol.hs
index 68d9afc..4f57fbb 100644
--- a/tests/TestProtocol.hs
+++ b/tests/TestProtocol.hs
@@ -15,6 +15,7 @@ import qualified Crypto.PubKey.ECC.Generate as Crypto
import qualified Crypto.PubKey.ECC.Prim as Crypto
import qualified Crypto.PubKey.ECC.Types as Crypto
import GaloisField (GaloisField(..))
+import PrimeField (toInt)
import Bulletproofs.Curve
import qualified Bulletproofs.RangeProof as RP