diff --git a/btcec/schnorr/musig2/nonces.go b/btcec/schnorr/musig2/nonces.go index 5a7fbd4b..d22f18cd 100644 --- a/btcec/schnorr/musig2/nonces.go +++ b/btcec/schnorr/musig2/nonces.go @@ -31,7 +31,7 @@ var ( // NonceGenTag is used to generate the value (from a set of required an // optional field) that will be used as the part of the secret nonce. - NonceGenTag = []byte("Musig/nonce") + NonceGenTag = []byte("MuSig/nonce") byteOrder = binary.BigEndian ) @@ -270,6 +270,16 @@ func GenNonces(options ...NonceGenOption) (*Nonces, error) { return nil, err } + // If the options contain a secret key, we XOR it with with the tagged + // random bytes. + if len(opts.secretKey) == 32 { + taggedHash := chainhash.TaggedHash(NonceAuxTag, randBytes[:]) + + for i := 0; i < chainhash.HashSize; i++ { + randBytes[i] = opts.secretKey[i] ^ taggedHash[i] + } + } + // Using our randomness and the set of optional params, generate our // two secret nonces: k1 and k2. k1, err := genNonceAuxBytes(randBytes[:], 1, opts)