Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose randomly generated values for Blind RSA (salt and blind) #320

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions blindsign/blindrsa/blindrsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (v RSAVerifier) fixedBlind(message, salt []byte, r, rInv *big.Int) ([]byte,
return blindedMsg, RSAVerifierState{
encodedMsg: encodedMsg,
verifier: v,
salt: salt,
rInv: rInv,
}, nil
}
Expand Down Expand Up @@ -114,6 +115,21 @@ func (v RSAVerifier) Blind(random io.Reader, message []byte) ([]byte, blindsign.
return v.fixedBlind(message, salt, r, rInv)
}

// FixedBlind runs the Blind function with fixed blind and salt inputs.
func (v RSAVerifier) FixedBlind(message, blind, salt []byte) ([]byte, blindsign.VerifierState, error) {
if blind == nil {
return nil, nil, ErrInvalidRandomness
}

r := new(big.Int).SetBytes(blind)
rInv := new(big.Int).ModInverse(r, v.pk.N)
if rInv == nil {
return nil, nil, ErrInvalidBlind
}

return v.fixedBlind(message, salt, r, rInv)
}

// An RSAVerifierState carries state needed to complete the blind signature protocol
// as a verifier.
type RSAVerifierState struct {
Expand All @@ -123,6 +139,9 @@ type RSAVerifierState struct {
// The hashed and encoded message being signed
encodedMsg []byte

// The salt used when encoding the message
salt []byte

// Inverse of the blinding factor produced by the Verifier
rInv *big.Int
}
Expand Down Expand Up @@ -165,6 +184,17 @@ func (state RSAVerifierState) Finalize(data []byte) ([]byte, error) {
return sig, nil
}

// CopyBlind returns an encoding of the blind value used in the protocol.
func (state RSAVerifierState) CopyBlind() []byte {
r := new(big.Int).ModInverse(state.rInv, state.verifier.pk.N)
return r.Bytes()
}

// CopySalt returns an encoding of the per-message salt used in the protocol.
func (state RSAVerifierState) CopySalt() []byte {
return state.salt
chris-wood marked this conversation as resolved.
Show resolved Hide resolved
}

// An RSASigner represents the Signer in the blind RSA protocol.
// It carries the raw RSA private key used for signing blinded messages.
type RSASigner struct {
Expand Down
6 changes: 6 additions & 0 deletions blindsign/blindsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ type VerifierState interface {
// Finalize completes the blind signature protocol and produces a signature
// over the corresponding Verifier-provided message.
Finalize(data []byte) ([]byte, error)

// CopyBlind returns an encoding of the blind value used in the protocol.
CopyBlind() []byte

// CopySalt returns an encoding of the per-message salt used in the protocol.
CopySalt() []byte
}

// A Signer represents a specific instance of a blind signature signer.
Expand Down