Skip to content

Instantly share code, notes, and snippets.

@dchest
Last active August 29, 2015 14:02
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 dchest/226c207b62c6b9c144b6 to your computer and use it in GitHub Desktop.
Save dchest/226c207b62c6b9c144b6 to your computer and use it in GitHub Desktop.
This program generates random test vectors for curve25519 scalarmult based on Go's NaCl implementation
package main
import (
"fmt"
"crypto/rand"
"code.google.com/p/go.crypto/nacl/box"
"code.google.com/p/go.crypto/curve25519"
)
func main() {
for i := 0; i < 1024; i++ {
pk1, sk1, err := box.GenerateKey(rand.Reader)
if err != nil {
panic(err)
}
pk2, sk2, err := box.GenerateKey(rand.Reader)
if err != nil {
panic(err)
}
var out1, out2 [32]byte
curve25519.ScalarMult(&out1, sk1, pk2)
curve25519.ScalarMult(&out2, sk2, pk1)
if out1 != out2 {
panic("differ")
}
fmt.Printf("%x:%x:%x:%x:%x\n", pk1[:], sk1[:], pk2[:], sk2[:], out1[:])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment