Home | History | Annotate | Download | only in curve25519
      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 
      5 package curve25519
      6 
      7 import (
      8 	"fmt"
      9 	"testing"
     10 )
     11 
     12 const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a"
     13 
     14 func TestBaseScalarMult(t *testing.T) {
     15 	var a, b [32]byte
     16 	in := &a
     17 	out := &b
     18 	a[0] = 1
     19 
     20 	for i := 0; i < 200; i++ {
     21 		ScalarBaseMult(out, in)
     22 		in, out = out, in
     23 	}
     24 
     25 	result := fmt.Sprintf("%x", in[:])
     26 	if result != expectedHex {
     27 		t.Errorf("incorrect result: got %s, want %s", result, expectedHex)
     28 	}
     29 }
     30 
     31 func BenchmarkScalarBaseMult(b *testing.B) {
     32 	var in, out [32]byte
     33 	in[0] = 1
     34 
     35 	b.SetBytes(32)
     36 	for i := 0; i < b.N; i++ {
     37 		ScalarBaseMult(&out, &in)
     38 	}
     39 }
     40