curve25519_test.go 762 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package curve25519
  5. import (
  6. "fmt"
  7. "testing"
  8. )
  9. const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"
  10. func TestBaseScalarMult(t *testing.T) {
  11. var a, b [32]byte
  12. in := &a
  13. out := &b
  14. a[0] = 1
  15. for i := 0; i < 200; i++ {
  16. ScalarBaseMult(out, in)
  17. in, out = out, in
  18. }
  19. result := fmt.Sprintf("%x", in[:])
  20. if result != expectedHex {
  21. t.Errorf("incorrect result: got %s, want %s", result, expectedHex)
  22. }
  23. }
  24. func BenchmarkScalarBaseMult(b *testing.B) {
  25. var in, out [32]byte
  26. in[0] = 1
  27. b.SetBytes(32)
  28. for i := 0; i < b.N; i++ {
  29. ScalarBaseMult(&out, &in)
  30. }
  31. }