Update interface

This commit is contained in:
arnaucube
2021-01-16 18:00:52 +01:00
parent ec095bba83
commit becff7b647
10 changed files with 78 additions and 134 deletions

View File

@@ -93,46 +93,20 @@ func (pk *PublicKey) Point() *Point {
return (*Point)(pk)
}
// SignerPrivateData contains the secret values from the Signer
type SignerPrivateData struct {
D *PrivateKey
K *big.Int
}
// SignerPublicData contains the public values from the Signer (generated from
// its SignerPrivateData)
type SignerPublicData struct {
// Q is the Signer Public Key
Q *PublicKey // = skG
R *Point // = kG
}
// NewSigner returns a new SignerPrivateData with random D & K
func NewSigner() *SignerPrivateData {
sk := NewPrivateKey()
// NewRequestParameters returns a new random k (secret) & R (public) parameters
func NewRequestParameters() (*big.Int, *Point) {
k := newRand()
return &SignerPrivateData{
D: sk,
K: k,
}
}
// PublicData returns the SignerPublicData from the SignerPrivateData
func (signer *SignerPrivateData) PublicData() *SignerPublicData {
return &SignerPublicData{
Q: signer.D.Public(), // Q = dG
R: G.Mul(signer.K), // R = kG
}
return k, G.Mul(k) // R = kG
}
// BlindSign performs the blind signature on the given mBlinded using
// SignerPrivateData values
func (signer *SignerPrivateData) BlindSign(mBlinded *big.Int) *big.Int {
func (sk *PrivateKey) BlindSign(mBlinded *big.Int, k *big.Int) *big.Int {
// TODO add pending checks
// s' = d(m') + k
sBlind := new(big.Int).Add(
new(big.Int).Mul(signer.D.BigInt(), mBlinded),
signer.K)
new(big.Int).Mul(sk.BigInt(), mBlinded),
k)
return sBlind
}
@@ -147,7 +121,7 @@ type UserSecretData struct {
}
// Blind performs the blinding operation on m using SignerPublicData parameters
func Blind(m *big.Int, signer *SignerPublicData) (*big.Int, *UserSecretData) {
func Blind(m *big.Int, signerPubK *PublicKey, signerR *Point) (*big.Int, *UserSecretData) {
u := &UserSecretData{}
u.A = newRand()
u.B = newRand()
@@ -155,10 +129,10 @@ func Blind(m *big.Int, signer *SignerPublicData) (*big.Int, *UserSecretData) {
binv := new(big.Int).ModInverse(u.B, N)
// F = b^-1 R + a b^-1 Q + c G
bR := signer.R.Mul(binv)
bR := signerR.Mul(binv)
abinv := new(big.Int).Mul(u.A, binv)
abinv = new(big.Int).Mod(abinv, N)
abQ := signer.Q.Point().Mul(abinv)
abQ := signerPubK.Point().Mul(abinv)
cG := G.Mul(u.C)
u.F = bR.Add(abQ).Add(cG)
// TODO check F==O

View File

@@ -8,23 +8,25 @@ import (
)
func TestFlow(t *testing.T) {
// message to be signed
// signer: create new signer key pair
sk := NewPrivateKey()
signerPubK := sk.Public()
// signer: when user requests new R parameter to blind a new msg,
// create new signerR (public) with its secret k
k, signerR := NewRequestParameters()
// user: blinds the msg using signer's R
msg := new(big.Int).SetBytes([]byte("test"))
msgBlinded, userSecretData := Blind(msg, signerPubK, signerR)
// create new signer
signerPrivateData := NewSigner()
signerPublicData := signerPrivateData.PublicData()
// signer: signs the blinded message using its private key & secret k
sBlind := sk.BlindSign(msgBlinded, k)
// user blinds the msg
msgBlinded, user := Blind(msg, signerPublicData)
// signer signs the blinded message
sBlind := signerPrivateData.BlindSign(msgBlinded)
// user unblinds the blinded signature
sig := Unblind(sBlind, msg, user)
// user: unblinds the blinded signature
sig := Unblind(sBlind, msg, userSecretData)
// signature can be verified with signer PublicKey (Q)
verified := Verify(msg, sig, signerPublicData.Q)
verified := Verify(msg, sig, signerPubK)
assert.True(t, verified)
}