-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathissuer.go
75 lines (62 loc) · 2.68 KB
/
issuer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2016 Maarten Everts. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gabi
import (
"crypto/rand"
"math/big"
)
// Issuer holds the key material for a credential issuer.
type Issuer struct {
Sk *PrivateKey
Pk *PublicKey
Context *big.Int
}
// NewIssuer creates a new credential issuer.
func NewIssuer(sk *PrivateKey, pk *PublicKey, context *big.Int) *Issuer {
return &Issuer{Sk: sk, Pk: pk, Context: context}
}
// IssueSignature produces an IssueSignatureMessage for the attributes based on
// the IssueCommitmentMessage provided. Note that this function DOES NOT check
// the proofs containted in the IssueCommitmentMessage! That needs to be done at
// a higher level!
func (i *Issuer) IssueSignature(msg *IssueCommitmentMessage, attributes []*big.Int, nonce1 *big.Int) (*IssueSignatureMessage, error) {
signature, err := i.signCommitmentAndAttributes(msg.U, attributes)
if err != nil {
return nil, err
}
proof := i.proveSignature(signature, msg.Nonce2)
return &IssueSignatureMessage{Signature: signature, Proof: proof}, nil
}
// signCommitmentAndAttributes produces a (partial) signature on the commitment
// and the attributes. The signature by itself does not verify because the
// commitment contains a blinding factor that needs to be taken into account
// when verifying the signature.
func (i *Issuer) signCommitmentAndAttributes(U *big.Int, attributes []*big.Int) (*CLSignature, error) {
// Skip the first generator
return signMessageBlockAndCommitment(i.Sk, i.Pk, U, attributes, i.Pk.R[1:])
}
// randomElementMultiplicativeGroup returns a random element in the
// multiplicative group Z_{modulus}^*.
func randomElementMultiplicativeGroup(modulus *big.Int) *big.Int {
r := big.NewInt(0)
t := new(big.Int)
for r.Sign() <= 0 || t.GCD(nil, nil, r, modulus).Cmp(bigONE) != 0 {
// TODO: for memory/cpu efficiency re-use r's memory. See Go's
// implementation for finding a random prime.
r, _ = rand.Int(rand.Reader, modulus)
}
return r
}
// proveSignature returns a proof of knowledge of $e^{-1}$ in the signature.
func (i *Issuer) proveSignature(signature *CLSignature, nonce2 *big.Int) *ProofS {
Q := new(big.Int).Exp(signature.A, signature.E, i.Pk.N)
groupModulus := new(big.Int).Mul(i.Sk.PPrime, i.Sk.QPrime)
d := new(big.Int).ModInverse(signature.E, groupModulus)
eCommit := randomElementMultiplicativeGroup(groupModulus)
ACommit := new(big.Int).Exp(Q, eCommit, i.Pk.N)
c := hashCommit([]*big.Int{i.Context, Q, signature.A, nonce2, ACommit}, false)
eResponse := new(big.Int).Mul(c, d)
eResponse.Sub(eCommit, eResponse).Mod(eResponse, groupModulus)
return &ProofS{c, eResponse}
}