github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/lib/secp256k1/field_test.go (about)

     1  package secp256k1
     2  
     3  import (
     4  	"testing"
     5  	"crypto/rand"
     6  )
     7  
     8  
     9  func TestFeInv(t *testing.T) {
    10  	var in, out, exp Field
    11  	in.SetHex("813925AF112AAB8243F8CCBADE4CC7F63DF387263028DE6E679232A73A7F3C31")
    12  	exp.SetHex("7F586430EA30F914965770F6098E492699C62EE1DF6CAFFA77681C179FDF3117")
    13  	in.Inv(&out)
    14  	if !out.Equals(&exp) {
    15  		t.Error("fe.Inv() failed")
    16  	}
    17  }
    18  
    19  func BenchmarkFieldSqrt(b *testing.B) {
    20  	var dat [32]byte
    21  	var f, tmp Field
    22  	rand.Read(dat[:])
    23  	f.SetB32(dat[:])
    24  	for i := 0; i < b.N; i++ {
    25  		f.Sqrt(&tmp)
    26  	}
    27  }
    28  
    29  
    30  func BenchmarkFieldInv(b *testing.B) {
    31  	var dat [32]byte
    32  	var f, tmp Field
    33  	rand.Read(dat[:])
    34  	f.SetB32(dat[:])
    35  	for i := 0; i < b.N; i++ {
    36  		f.Inv(&tmp)
    37  	}
    38  }
    39