github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/crypto/bn256/cloudflare/gfp_test.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  package bn256
    10  
    11  import (
    12  	"testing"
    13  )
    14  
    15  //测试否定在装配优化和纯go上的工作方式相同
    16  //实施。
    17  func TestGFpNeg(t *testing.T) {
    18  	n := &gfP{0x0123456789abcdef, 0xfedcba9876543210, 0xdeadbeefdeadbeef, 0xfeebdaedfeebdaed}
    19  	w := &gfP{0xfedcba9876543211, 0x0123456789abcdef, 0x2152411021524110, 0x0114251201142512}
    20  	h := &gfP{}
    21  
    22  	gfpNeg(h, n)
    23  	if *h != *w {
    24  		t.Errorf("negation mismatch: have %#x, want %#x", *h, *w)
    25  	}
    26  }
    27  
    28  //测试添加在装配优化和纯Go上的工作方式相同
    29  //实施。
    30  func TestGFpAdd(t *testing.T) {
    31  	a := &gfP{0x0123456789abcdef, 0xfedcba9876543210, 0xdeadbeefdeadbeef, 0xfeebdaedfeebdaed}
    32  	b := &gfP{0xfedcba9876543210, 0x0123456789abcdef, 0xfeebdaedfeebdaed, 0xdeadbeefdeadbeef}
    33  	w := &gfP{0xc3df73e9278302b8, 0x687e956e978e3572, 0x254954275c18417f, 0xad354b6afc67f9b4}
    34  	h := &gfP{}
    35  
    36  	gfpAdd(h, a, b)
    37  	if *h != *w {
    38  		t.Errorf("addition mismatch: have %#x, want %#x", *h, *w)
    39  	}
    40  }
    41  
    42  //减法在程序集优化和纯go上的工作方式相同
    43  //实施。
    44  func TestGFpSub(t *testing.T) {
    45  	a := &gfP{0x0123456789abcdef, 0xfedcba9876543210, 0xdeadbeefdeadbeef, 0xfeebdaedfeebdaed}
    46  	b := &gfP{0xfedcba9876543210, 0x0123456789abcdef, 0xfeebdaedfeebdaed, 0xdeadbeefdeadbeef}
    47  	w := &gfP{0x02468acf13579bdf, 0xfdb97530eca86420, 0xdfc1e401dfc1e402, 0x203e1bfe203e1bfd}
    48  	h := &gfP{}
    49  
    50  	gfpSub(h, a, b)
    51  	if *h != *w {
    52  		t.Errorf("subtraction mismatch: have %#x, want %#x", *h, *w)
    53  	}
    54  }
    55  
    56  //乘法在程序集优化和纯go上的工作方式相同的测试
    57  //实施。
    58  func TestGFpMul(t *testing.T) {
    59  	a := &gfP{0x0123456789abcdef, 0xfedcba9876543210, 0xdeadbeefdeadbeef, 0xfeebdaedfeebdaed}
    60  	b := &gfP{0xfedcba9876543210, 0x0123456789abcdef, 0xfeebdaedfeebdaed, 0xdeadbeefdeadbeef}
    61  	w := &gfP{0xcbcbd377f7ad22d3, 0x3b89ba5d849379bf, 0x87b61627bd38b6d2, 0xc44052a2a0e654b2}
    62  	h := &gfP{}
    63  
    64  	gfpMul(h, a, b)
    65  	if *h != *w {
    66  		t.Errorf("multiplication mismatch: have %#x, want %#x", *h, *w)
    67  	}
    68  }