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