Skip to content

Commit

Permalink
schnorr: simplify some signing math
Browse files Browse the repository at this point in the history
We reuse the Bytes() function rather than duplicating its logic.
  • Loading branch information
wydengyre authored and jcvernaleo committed Nov 29, 2023
1 parent 6ea604d commit a4236c5
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions btcec/schnorr/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,9 @@ func schnorrSign(privKey, nonce *btcec.ModNScalar, pubKey *btcec.PublicKey, hash
// Step 12.
//
// e = tagged_hash("BIP0340/challenge", bytes(R) || bytes(P) || m) mod n
var rBytes [32]byte
r := &R.X
r.PutBytesUnchecked(rBytes[:])
pBytes := SerializePubKey(pubKey)

commitment := chainhash.TaggedHash(
chainhash.TagBIP0340Challenge, rBytes[:], pBytes, hash,
chainhash.TagBIP0340Challenge, R.X.Bytes()[:], pBytes, hash,
)

var e btcec.ModNScalar
Expand All @@ -324,7 +320,7 @@ func schnorrSign(privKey, nonce *btcec.ModNScalar, pubKey *btcec.PublicKey, hash
s := new(btcec.ModNScalar).Mul2(&e, privKey).Add(&k)
k.Zero()

sig := NewSignature(r, s)
sig := NewSignature(&R.X, s)

// Step 14.
//
Expand Down

0 comments on commit a4236c5

Please sign in to comment.