Skip to content

Commit

Permalink
Merge pull request #37 from getamis/hash_parameter
Browse files Browse the repository at this point in the history
crypto/homo/cl/: add a and c into hash function
  • Loading branch information
bun919tw authored Apr 7, 2020
2 parents a69816f + e75ba0e commit 79f7f8b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 30 deletions.
6 changes: 6 additions & 0 deletions crypto/homo/cl/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ func (m *PubKeyMessage) ToPubkey() (*PublicKey, error) {
if p.Cmp(big0) < 1 {
return nil, ErrInvalidMessage
}
if a.Cmp(big0) < 1 {
return nil, ErrInvalidMessage
}
if q.Cmp(big0) < 1 {
return nil, ErrInvalidMessage
}
if c.Cmp(big0) < 1 {
return nil, ErrInvalidMessage
}
g, err := m.G.ToCacheExp()
if err != nil {
return nil, err
Expand Down
72 changes: 44 additions & 28 deletions crypto/homo/cl/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crypto/homo/cl/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ message Hash {
binaryquadraticform.BQForm h = 5;
bytes p = 6;
bytes q = 7;
bytes a = 8;
bytes c = 9;
}
14 changes: 14 additions & 0 deletions crypto/homo/cl/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,19 @@ var _ = Describe("Message test", func() {
Expect(err).Should(Equal(ErrInvalidMessage))
Expect(pub).Should(BeNil())
})

It("zero A", func() {
msg.A = big0.Bytes()
pub, err := msg.ToPubkey()
Expect(err).Should(Equal(ErrInvalidMessage))
Expect(pub).Should(BeNil())
})

It("zero C", func() {
msg.C = big0.Bytes()
pub, err := msg.ToPubkey()
Expect(err).Should(Equal(ErrInvalidMessage))
Expect(pub).Should(BeNil())
})
})
})
8 changes: 6 additions & 2 deletions crypto/homo/cl/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (pubKey *PublicKey) buildProof(plainText *big.Int, r *big.Int) (*ProofMessa
return nil, err
}

// k:=H(t1, t2, g, f, h, p, q) mod c
// k:=H(t1, t2, g, f, h, p, q, a, c) mod c
blake2bKey, err := utils.GenRandomBytes(blake2b.Size256)
if err != nil {
return nil, err
Expand All @@ -102,6 +102,8 @@ func (pubKey *PublicKey) buildProof(plainText *big.Int, r *big.Int) (*ProofMessa
H: pubKey.h.ToMessage(),
P: pubKey.p.Bytes(),
Q: pubKey.q.Bytes(),
A: pubKey.a.Bytes(),
C: pubKey.c.Bytes(),
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -162,7 +164,7 @@ func (pubKey *PublicKey) VerifyEnc(bs []byte) error {
return err
}
// Check g^{u1}=t1*c1^k
// k:=H(t1, t2, g, f, h, p, q) mod c
// k:=H(t1, t2, g, f, h, p, q, a, c) mod c
k, err := utils.HashProtos(msg.Proof.Blake2BKey, pubKey.c, &Hash{
T1: msg.Proof.T1,
T2: msg.Proof.T2,
Expand All @@ -171,6 +173,8 @@ func (pubKey *PublicKey) VerifyEnc(bs []byte) error {
H: pubKey.h.ToMessage(),
P: pubKey.p.Bytes(),
Q: pubKey.q.Bytes(),
A: pubKey.a.Bytes(),
C: pubKey.c.Bytes(),
})
if err != nil {
return err
Expand Down

0 comments on commit 79f7f8b

Please sign in to comment.