github.com/clem109/go-ethereum@v1.8.3-0.20180316121352-fe6cf00f480a/crypto/bn256/cloudflare/gfp_test.go (about)

     1  // +build amd64,!appengine,!gccgo
     2  
     3  package bn256
     4  
     5  import (
     6  	"testing"
     7  )
     8  
     9  // Tests that negation works the same way on both assembly-optimized and pure Go
    10  // implementation.
    11  func TestGFpNeg(t *testing.T) {
    12  	n := &gfP{0x0123456789abcdef, 0xfedcba9876543210, 0xdeadbeefdeadbeef, 0xfeebdaedfeebdaed}
    13  	w := &gfP{0xfedcba9876543211, 0x0123456789abcdef, 0x2152411021524110, 0x0114251201142512}
    14  	h := &gfP{}
    15  
    16  	gfpNeg(h, n)
    17  	if *h != *w {
    18  		t.Errorf("negation mismatch: have %#x, want %#x", *h, *w)
    19  	}
    20  }
    21  
    22  // Tests that addition works the same way on both assembly-optimized and pure Go
    23  // implementation.
    24  func TestGFpAdd(t *testing.T) {
    25  	a := &gfP{0x0123456789abcdef, 0xfedcba9876543210, 0xdeadbeefdeadbeef, 0xfeebdaedfeebdaed}
    26  	b := &gfP{0xfedcba9876543210, 0x0123456789abcdef, 0xfeebdaedfeebdaed, 0xdeadbeefdeadbeef}
    27  	w := &gfP{0xc3df73e9278302b8, 0x687e956e978e3572, 0x254954275c18417f, 0xad354b6afc67f9b4}
    28  	h := &gfP{}
    29  
    30  	gfpAdd(h, a, b)
    31  	if *h != *w {
    32  		t.Errorf("addition mismatch: have %#x, want %#x", *h, *w)
    33  	}
    34  }
    35  
    36  // Tests that subtraction works the same way on both assembly-optimized and pure Go
    37  // implementation.
    38  func TestGFpSub(t *testing.T) {
    39  	a := &gfP{0x0123456789abcdef, 0xfedcba9876543210, 0xdeadbeefdeadbeef, 0xfeebdaedfeebdaed}
    40  	b := &gfP{0xfedcba9876543210, 0x0123456789abcdef, 0xfeebdaedfeebdaed, 0xdeadbeefdeadbeef}
    41  	w := &gfP{0x02468acf13579bdf, 0xfdb97530eca86420, 0xdfc1e401dfc1e402, 0x203e1bfe203e1bfd}
    42  	h := &gfP{}
    43  
    44  	gfpSub(h, a, b)
    45  	if *h != *w {
    46  		t.Errorf("subtraction mismatch: have %#x, want %#x", *h, *w)
    47  	}
    48  }
    49  
    50  // Tests that multiplication works the same way on both assembly-optimized and pure Go
    51  // implementation.
    52  func TestGFpMul(t *testing.T) {
    53  	a := &gfP{0x0123456789abcdef, 0xfedcba9876543210, 0xdeadbeefdeadbeef, 0xfeebdaedfeebdaed}
    54  	b := &gfP{0xfedcba9876543210, 0x0123456789abcdef, 0xfeebdaedfeebdaed, 0xdeadbeefdeadbeef}
    55  	w := &gfP{0xcbcbd377f7ad22d3, 0x3b89ba5d849379bf, 0x87b61627bd38b6d2, 0xc44052a2a0e654b2}
    56  	h := &gfP{}
    57  
    58  	gfpMul(h, a, b)
    59  	if *h != *w {
    60  		t.Errorf("multiplication mismatch: have %#x, want %#x", *h, *w)
    61  	}
    62  }