Permalink
Browse files

fuzz: more tests in elliptic.Curve fuzzer

  • Loading branch information...
mmcloughlin committed Feb 4, 2019
1 parent 48b4589 commit 114c73e6ef74034d4af9a21b070b93dced95c393
Showing with 23 additions and 1 deletion.
  1. +23 −1 fuzz/fuzz.go
@@ -52,11 +52,12 @@ func Curve(data []byte, c elliptic.Curve) int {
ref := c.Params()
n := ref.BitSize / 8

// ScalarBaseMult
if len(data) < n {
return -1
}

s := data[:n]
data = data[n:]

x, y := c.ScalarBaseMult(s)
rx, ry := ref.ScalarBaseMult(s)
@@ -65,5 +66,26 @@ func Curve(data []byte, c elliptic.Curve) int {
panic("mismatch ScalarBaseMult")
}

// ScalarMult
if len(data) < n {
return -1
}
s = data[:n]
data = data[n:]

x, y = c.ScalarMult(x, y, s)
rx, ry = ref.ScalarMult(rx, ry, s)

if x.Cmp(rx) != 0 || y.Cmp(ry) != 0 {
panic("mismatch ScalarMult")
}

// Confirm Add and Double have expected properties.
ax, ay := c.Add(x, y, x, y)
dx, dy := c.Double(x, y)
if ax.Cmp(dx) != 0 || ay.Cmp(dy) != 0 {
panic("mismatch between Add and Double")
}

return 0
}

0 comments on commit 114c73e

Please sign in to comment.