Skip to content

Commit cdb4a98

Browse files
author
Manu Drijvers
committed
[FAB-7396] Use the most recent version of amcl
Change-Id: Ia954b9cfb759825df6e47400f3a96780ec3612b2 Signed-off-by: Manu Drijvers <mdr@zurich.ibm.com>
1 parent ff0b4fa commit cdb4a98

File tree

128 files changed

+17188
-3940
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+17188
-3940
lines changed

common/tools/idemixgen/idemixca/idemixca.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/hyperledger/fabric/idemix"
1212
"github.com/hyperledger/fabric/msp"
1313
m "github.com/hyperledger/fabric/protos/msp"
14-
amcl "github.com/manudrijvers/amcl/go"
14+
"github.com/milagro-crypto/amcl/version3/go/amcl/FP256BN"
1515
"github.com/pkg/errors"
1616
)
1717

@@ -44,7 +44,7 @@ func GenerateIssuerKey() ([]byte, []byte, error) {
4444
// (meaning it is used only for verification)
4545
// then only a public key of the CA (issuer) is added to the MSP config (besides the name)
4646
func GenerateSignerConfig(isAdmin bool, ouString string, key *idemix.IssuerKey) ([]byte, error) {
47-
attrs := make([]*amcl.BIG, 2)
47+
attrs := make([]*FP256BN.BIG, 2)
4848

4949
if ouString == "" {
5050
return nil, errors.Errorf("the OU attribute value is empty")
@@ -57,7 +57,7 @@ func GenerateSignerConfig(isAdmin bool, ouString string, key *idemix.IssuerKey)
5757
}
5858

5959
attrs[0] = idemix.HashModOrder([]byte(ouString))
60-
attrs[1] = amcl.NewBIGint(int(role))
60+
attrs[1] = FP256BN.NewBIGint(int(role))
6161

6262
rng, err := idemix.GetRand()
6363
if err != nil {

idemix/credential.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77
package idemix
88

99
import (
10-
amcl "github.com/manudrijvers/amcl/go"
10+
"github.com/milagro-crypto/amcl/version3/go/amcl"
11+
"github.com/milagro-crypto/amcl/version3/go/amcl/FP256BN"
1112
"github.com/pkg/errors"
1213
)
1314

@@ -33,7 +34,7 @@ import (
3334
// NewCredential issues a new credential, which is the last step of the interactive issuance protocol
3435
// All attribute values are added by the issuer at this step and then signed together with a commitment to
3536
// the user's secret key from a credential request
36-
func NewCredential(key *IssuerKey, m *CredRequest, attrs []*amcl.BIG, rng *amcl.RAND) (*Credential, error) {
37+
func NewCredential(key *IssuerKey, m *CredRequest, attrs []*FP256BN.BIG, rng *amcl.RAND) (*Credential, error) {
3738
// check the credential request that contains
3839
err := m.Check(key.IPk)
3940
if err != nil {
@@ -49,7 +50,7 @@ func NewCredential(key *IssuerKey, m *CredRequest, attrs []*amcl.BIG, rng *amcl.
4950
E := RandModOrder(rng)
5051
S := RandModOrder(rng)
5152

52-
B := amcl.NewECP()
53+
B := FP256BN.NewECP()
5354
B.Copy(GenG1)
5455
Nym := EcpFromProto(m.Nym)
5556
B.Add(Nym)
@@ -63,7 +64,7 @@ func NewCredential(key *IssuerKey, m *CredRequest, attrs []*amcl.BIG, rng *amcl.
6364
B.Add(EcpFromProto(key.IPk.HAttrs[len(attrs)-1]).Mul(attrs[len(attrs)-1]))
6465
}
6566

66-
Exp := amcl.Modadd(amcl.FromBytes(key.GetISk()), E, GroupOrder)
67+
Exp := Modadd(FP256BN.FromBytes(key.GetISk()), E, GroupOrder)
6768
Exp.Invmodp(GroupOrder)
6869
A := B.Mul(Exp)
6970

@@ -81,19 +82,19 @@ func NewCredential(key *IssuerKey, m *CredRequest, attrs []*amcl.BIG, rng *amcl.
8182
}
8283

8384
// Complete completes the credential by updating it with the randomness used to generate CredRequest
84-
func (cred *Credential) Complete(credS1 *amcl.BIG) {
85-
cred.S = BigToBytes(amcl.Modadd(amcl.FromBytes(cred.S), credS1, GroupOrder))
85+
func (cred *Credential) Complete(credS1 *FP256BN.BIG) {
86+
cred.S = BigToBytes(Modadd(FP256BN.FromBytes(cred.S), credS1, GroupOrder))
8687
}
8788

8889
// Ver cryptographically verifies the credential by verifying the signature
8990
// on the attribute values and user's secret key
90-
func (cred *Credential) Ver(sk *amcl.BIG, ipk *IssuerPublicKey) error {
91+
func (cred *Credential) Ver(sk *FP256BN.BIG, ipk *IssuerPublicKey) error {
9192

9293
// parse the credential
9394
A := EcpFromProto(cred.GetA())
9495
B := EcpFromProto(cred.GetB())
95-
E := amcl.FromBytes(cred.GetE())
96-
S := amcl.FromBytes(cred.GetS())
96+
E := FP256BN.FromBytes(cred.GetE())
97+
S := FP256BN.FromBytes(cred.GetS())
9798

9899
// verify that all attribute values are present
99100
for i := 0; i < len(cred.GetAttrs()); i++ {
@@ -103,23 +104,24 @@ func (cred *Credential) Ver(sk *amcl.BIG, ipk *IssuerPublicKey) error {
103104
}
104105

105106
// verify cryptographic signature on the attributes and the user secret key
106-
BPrime := amcl.NewECP()
107+
BPrime := FP256BN.NewECP()
107108
BPrime.Copy(GenG1)
108109
BPrime.Add(EcpFromProto(ipk.HSk).Mul2(sk, EcpFromProto(ipk.HRand), S))
109110
for i := 0; i < len(cred.Attrs)/2; i++ {
110-
BPrime.Add(EcpFromProto(ipk.HAttrs[2*i]).Mul2(amcl.FromBytes(cred.Attrs[2*i]), EcpFromProto(ipk.HAttrs[2*i+1]), amcl.FromBytes(cred.Attrs[2*i+1])))
111+
BPrime.Add(EcpFromProto(ipk.HAttrs[2*i]).Mul2(FP256BN.FromBytes(cred.Attrs[2*i]), EcpFromProto(ipk.HAttrs[2*i+1]), FP256BN.FromBytes(cred.Attrs[2*i+1])))
111112
}
112113
if len(cred.Attrs)%2 != 0 {
113-
BPrime.Add(EcpFromProto(ipk.HAttrs[len(cred.Attrs)-1]).Mul(amcl.FromBytes(cred.Attrs[len(cred.Attrs)-1])))
114+
BPrime.Add(EcpFromProto(ipk.HAttrs[len(cred.Attrs)-1]).Mul(FP256BN.FromBytes(cred.Attrs[len(cred.Attrs)-1])))
114115
}
115116
if !B.Equals(BPrime) {
116117
return errors.Errorf("b-value from credential does not match the attribute values")
117118
}
118119

119120
a := GenG2.Mul(E)
120121
a.Add(Ecp2FromProto(ipk.W))
122+
a.Affine()
121123

122-
if !amcl.Fexp(amcl.Ate(a, A)).Equals(amcl.Fexp(amcl.Ate(GenG2, B))) {
124+
if !FP256BN.Fexp(FP256BN.Ate(a, A)).Equals(FP256BN.Fexp(FP256BN.Ate(GenG2, B))) {
123125
return errors.Errorf("credential is not cryptographically valid")
124126
}
125127
return nil

idemix/credrequest.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ SPDX-License-Identifier: Apache-2.0
77
package idemix
88

99
import (
10-
amcl "github.com/manudrijvers/amcl/go"
10+
"github.com/milagro-crypto/amcl/version3/go/amcl"
11+
"github.com/milagro-crypto/amcl/version3/go/amcl/FP256BN"
1112
"github.com/pkg/errors"
1213
)
1314

@@ -30,7 +31,7 @@ const credRequestLabel = "credRequest"
3031
// the signature value, a randomness used to create the signature, the user secret, and the attribute values
3132

3233
// NewCredRequest creates a new Credential Request, the first message of the interactive credential issuance protocol (from user to issuer)
33-
func NewCredRequest(sk *amcl.BIG, credS1 *amcl.BIG, IssuerNonce *amcl.BIG, ipk *IssuerPublicKey, rng *amcl.RAND) *CredRequest {
34+
func NewCredRequest(sk *FP256BN.BIG, credS1 *FP256BN.BIG, IssuerNonce *FP256BN.BIG, ipk *IssuerPublicKey, rng *amcl.RAND) *CredRequest {
3435
HSk := EcpFromProto(ipk.HSk)
3536
HRand := EcpFromProto(ipk.HRand)
3637
Nym := HSk.Mul2(sk, HRand, credS1)
@@ -55,19 +56,19 @@ func NewCredRequest(sk *amcl.BIG, credS1 *amcl.BIG, IssuerNonce *amcl.BIG, ipk *
5556
copy(proofData[index:], ipk.Hash)
5657

5758
proofC := HashModOrder(proofData)
58-
proofS1 := amcl.Modadd(amcl.Modmul(proofC, sk, GroupOrder), rSk, GroupOrder)
59-
proofS2 := amcl.Modadd(amcl.Modmul(proofC, credS1, GroupOrder), rRand, GroupOrder)
59+
proofS1 := Modadd(FP256BN.Modmul(proofC, sk, GroupOrder), rSk, GroupOrder)
60+
proofS2 := Modadd(FP256BN.Modmul(proofC, credS1, GroupOrder), rRand, GroupOrder)
6061

6162
return &CredRequest{EcpToProto(Nym), BigToBytes(IssuerNonce), BigToBytes(proofC), BigToBytes(proofS1), BigToBytes(proofS2)}
6263
}
6364

6465
// Check cryptographically verifies the credential request
6566
func (m *CredRequest) Check(ipk *IssuerPublicKey) error {
6667
Nym := EcpFromProto(m.GetNym())
67-
IssuerNonce := amcl.FromBytes(m.GetIssuerNonce())
68-
ProofC := amcl.FromBytes(m.GetProofC())
69-
ProofS1 := amcl.FromBytes(m.GetProofS1())
70-
ProofS2 := amcl.FromBytes(m.GetProofS2())
68+
IssuerNonce := FP256BN.FromBytes(m.GetIssuerNonce())
69+
ProofC := FP256BN.FromBytes(m.GetProofC())
70+
ProofS1 := FP256BN.FromBytes(m.GetProofS1())
71+
ProofS2 := FP256BN.FromBytes(m.GetProofS2())
7172

7273
HSk := EcpFromProto(ipk.HSk)
7374
HRand := EcpFromProto(ipk.HRand)
@@ -93,7 +94,7 @@ func (m *CredRequest) Check(ipk *IssuerPublicKey) error {
9394
index = appendBytesBig(proofData, index, IssuerNonce)
9495
copy(proofData[index:], ipk.Hash)
9596

96-
if !ProofC.Equals(HashModOrder(proofData)) {
97+
if *ProofC != *HashModOrder(proofData) {
9798
return errors.Errorf("zero knowledge proof is invalid")
9899
}
99100

idemix/idemix_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ SPDX-License-Identifier: Apache-2.0
77
package idemix
88

99
import (
10-
"testing"
11-
1210
"bytes"
11+
"testing"
1312

14-
amcl "github.com/manudrijvers/amcl/go"
13+
"github.com/milagro-crypto/amcl/version3/go/amcl/FP256BN"
1514
"github.com/stretchr/testify/assert"
1615
)
1716

1817
func TestIdemix(t *testing.T) {
1918
AttributeNames := []string{"Attr1", "Attr2", "Attr3", "Attr4", "Attr5"}
20-
attrs := make([]*amcl.BIG, len(AttributeNames))
19+
attrs := make([]*FP256BN.BIG, len(AttributeNames))
2120
for i := range AttributeNames {
22-
attrs[i] = amcl.NewBIGint(i)
21+
attrs[i] = FP256BN.NewBIGint(i)
2322
}
2423

2524
// Test issuer key generation
@@ -77,7 +76,7 @@ func TestIdemix(t *testing.T) {
7776
assert.NoError(t, cred.Ver(sk, key.IPk), "credential should be valid")
7877

7978
// Issuing a credential with the incorrect amount of attributes should fail
80-
_, err = NewCredential(key, m, []*amcl.BIG{}, rng)
79+
_, err = NewCredential(key, m, []*FP256BN.BIG{}, rng)
8180
assert.Error(t, err, "issuing a credential with the incorrect amount of attributes should fail")
8281

8382
// Breaking the ZK proof of the CredRequest should make it invalid

idemix/issuerkey.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ package idemix
88

99
import (
1010
"github.com/golang/protobuf/proto"
11-
amcl "github.com/manudrijvers/amcl/go"
11+
"github.com/milagro-crypto/amcl/version3/go/amcl"
12+
"github.com/milagro-crypto/amcl/version3/go/amcl/FP256BN"
1213
"github.com/pkg/errors"
1314
)
1415

@@ -81,7 +82,7 @@ func NewIssuerKey(AttributeNames []string, rng *amcl.RAND) (*IssuerKey, error) {
8182
proofC := HashModOrder(proofData)
8283
key.IPk.ProofC = BigToBytes(proofC)
8384

84-
proofS := amcl.Modadd(amcl.Modmul(proofC, ISk, GroupOrder), r, GroupOrder)
85+
proofS := Modadd(FP256BN.Modmul(proofC, ISk, GroupOrder), r, GroupOrder)
8586
key.IPk.ProofS = BigToBytes(proofS)
8687

8788
serializedIPk, err := proto.Marshal(key.IPk)
@@ -99,15 +100,15 @@ func (IPk *IssuerPublicKey) Check() error {
99100
NumAttrs := len(IPk.GetAttributeNames())
100101
HSk := EcpFromProto(IPk.GetHSk())
101102
HRand := EcpFromProto(IPk.GetHRand())
102-
HAttrs := make([]*amcl.ECP, len(IPk.GetHAttrs()))
103+
HAttrs := make([]*FP256BN.ECP, len(IPk.GetHAttrs()))
103104
for i := 0; i < len(IPk.GetHAttrs()); i++ {
104105
HAttrs[i] = EcpFromProto(IPk.GetHAttrs()[i])
105106
}
106107
BarG1 := EcpFromProto(IPk.GetBarG1())
107108
BarG2 := EcpFromProto(IPk.GetBarG2())
108109
W := Ecp2FromProto(IPk.GetW())
109-
ProofC := amcl.FromBytes(IPk.GetProofC())
110-
ProofS := amcl.FromBytes(IPk.GetProofS())
110+
ProofC := FP256BN.FromBytes(IPk.GetProofC())
111+
ProofS := FP256BN.FromBytes(IPk.GetProofS())
111112

112113
if NumAttrs < 0 ||
113114
HSk == nil ||
@@ -130,9 +131,9 @@ func (IPk *IssuerPublicKey) Check() error {
130131
index := 0
131132

132133
t1 := GenG2.Mul(ProofS)
133-
t1.Add(W.Mul(amcl.Modneg(ProofC, GroupOrder)))
134+
t1.Add(W.Mul(FP256BN.Modneg(ProofC, GroupOrder)))
134135
t2 := BarG1.Mul(ProofS)
135-
t2.Add(BarG2.Mul(amcl.Modneg(ProofC, GroupOrder)))
136+
t2.Add(BarG2.Mul(FP256BN.Modneg(ProofC, GroupOrder)))
136137

137138
index = appendBytesG2(proofData, index, t1)
138139
index = appendBytesG1(proofData, index, t2)
@@ -141,7 +142,7 @@ func (IPk *IssuerPublicKey) Check() error {
141142
index = appendBytesG2(proofData, index, W)
142143
index = appendBytesG1(proofData, index, BarG2)
143144

144-
if !ProofC.Equals(HashModOrder(proofData)) {
145+
if *ProofC != *HashModOrder(proofData) {
145146
return errors.Errorf("zero knowledge proof in public key invalid")
146147
}
147148

idemix/nymsignature.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ SPDX-License-Identifier: Apache-2.0
77
package idemix
88

99
import (
10-
amcl "github.com/manudrijvers/amcl/go"
10+
"github.com/milagro-crypto/amcl/version3/go/amcl"
11+
"github.com/milagro-crypto/amcl/version3/go/amcl/FP256BN"
1112
"github.com/pkg/errors"
1213
)
1314

1415
// NewSignature creates a new idemix pseudonym signature
15-
func NewNymSignature(sk *amcl.BIG, Nym *amcl.ECP, RNym *amcl.BIG, ipk *IssuerPublicKey, msg []byte, rng *amcl.RAND) (*NymSignature, error) {
16+
func NewNymSignature(sk *FP256BN.BIG, Nym *FP256BN.ECP, RNym *FP256BN.BIG, ipk *IssuerPublicKey, msg []byte, rng *amcl.RAND) (*NymSignature, error) {
1617
if sk == nil || Nym == nil || RNym == nil || ipk == nil || rng == nil {
1718
return nil, errors.Errorf("cannot create NymSignature: received nil input")
1819
}
@@ -57,8 +58,8 @@ func NewNymSignature(sk *amcl.BIG, Nym *amcl.ECP, RNym *amcl.BIG, ipk *IssuerPub
5758
ProofC := HashModOrder(proofData)
5859

5960
// Finally, we compute the s-values, which form the response answering challenge c
60-
ProofSSk := amcl.Modadd(rSk, amcl.Modmul(ProofC, sk, GroupOrder), GroupOrder)
61-
ProofSRNym := amcl.Modadd(rRNym, amcl.Modmul(ProofC, RNym, GroupOrder), GroupOrder)
61+
ProofSSk := Modadd(rSk, FP256BN.Modmul(ProofC, sk, GroupOrder), GroupOrder)
62+
ProofSRNym := Modadd(rRNym, FP256BN.Modmul(ProofC, RNym, GroupOrder), GroupOrder)
6263

6364
// The signature consists of the Fiat-Shamir hash (ProofC), the s-values (ProofSSk, ProofSRNym), and the nonce.
6465
return &NymSignature{
@@ -69,12 +70,12 @@ func NewNymSignature(sk *amcl.BIG, Nym *amcl.ECP, RNym *amcl.BIG, ipk *IssuerPub
6970
}
7071

7172
// Ver verifies an idemix NymSignature
72-
func (sig *NymSignature) Ver(nym *amcl.ECP, ipk *IssuerPublicKey, msg []byte) error {
73-
ProofC := amcl.FromBytes(sig.GetProofC())
74-
ProofSSk := amcl.FromBytes(sig.GetProofSSk())
75-
ProofSRNym := amcl.FromBytes(sig.GetProofSRNym())
73+
func (sig *NymSignature) Ver(nym *FP256BN.ECP, ipk *IssuerPublicKey, msg []byte) error {
74+
ProofC := FP256BN.FromBytes(sig.GetProofC())
75+
ProofSSk := FP256BN.FromBytes(sig.GetProofSSk())
76+
ProofSRNym := FP256BN.FromBytes(sig.GetProofSRNym())
7677

77-
Nonce := amcl.FromBytes(sig.GetNonce())
78+
Nonce := FP256BN.FromBytes(sig.GetNonce())
7879

7980
HRand := EcpFromProto(ipk.HRand)
8081
HSk := EcpFromProto(ipk.HSk)
@@ -102,7 +103,7 @@ func (sig *NymSignature) Ver(nym *amcl.ECP, ipk *IssuerPublicKey, msg []byte) er
102103
proofData = proofData[:2*FieldBytes]
103104
index = appendBytesBig(proofData, index, c)
104105
index = appendBytesBig(proofData, index, Nonce)
105-
if !ProofC.Equals(HashModOrder(proofData)) {
106+
if *ProofC != *HashModOrder(proofData) {
106107
return errors.Errorf("pseudonym signature invalid: zero-knowledge proof is invalid")
107108
}
108109

0 commit comments

Comments
 (0)