Skip to content

Instantly share code, notes, and snippets.

@liamsi
Last active February 2, 2019 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamsi/44466eae97c74904324f702feefa5583 to your computer and use it in GitHub Desktop.
Save liamsi/44466eae97c74904324f702feefa5583 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"crypto/sha256"
"github.com/btcsuite/btcd/btcec"
)
func main() {
msg := []byte("Then strong encryption became available to the masses, and trust was no longer required.")
priv, err := btcec.NewPrivateKey(btcec.S256())
if err != nil {
panic("Duh!")
}
h := sha256.Sum256(msg)
sig, err := priv.Sign(h[:])
if err != nil {
panic("Duh^2!")
}
fmt.Println("Signature is valid?", sig.Verify(h[:], priv.PubKey()))
// s = N - s
sig.S.Sub(btcec.S256().CurveParams.N, sig.S)
fmt.Println("'Malleated' Signature is still valid?", sig.Verify(h[:], priv.PubKey()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment