Debian Codegraph @

msp/number_test.go

raw symbols SCIP
1 package msp
2
3 import (
4 "bytes"
5 "crypto/rand"
6 "testing"
7 )
8
9 func TestFieldElemMultiplicationOne(t *testing.T) {
10 x := FieldElem(make([]byte, ModulusSize))
11 rand.Read(x)
12
13 xy, yx := x.Mul(One), One.Mul(x)
14
15 if !One.IsOne() {
16 t.Fatalf("One is not one?")
17 }
18
19 if bytes.Compare(xy, x) != 0 || bytes.Compare(yx, x) != 0 {
20 t.Fatalf("Multiplication by 1 failed!\nx = %x\n1*x = %x\nx*1 = %x", x, yx, xy)
21 }
22 }
23
24 func TestFieldElemMultiplicationZero(t *testing.T) {
25 x := FieldElem(make([]byte, ModulusSize))
26 rand.Read(x)
27
28 xy, yx := x.Mul(Zero), Zero.Mul(x)
29
30 if !Zero.IsZero() {
31 t.Fatalf("Zero is not zero?")
32 }
33
34 if !xy.IsZero() || !yx.IsZero() {
35 t.Fatalf("Multiplication by 0 failed!\nx = %x\n0*x = %x\nx*0 = %x", x, yx, xy)
36 }
37 }
38
39 func TestFieldElemInvert(t *testing.T) {
40 x := FieldElem(make([]byte, ModulusSize))
41 rand.Read(x)
42
43 xInv := x.Invert()
44
45 xy, yx := x.Mul(xInv), xInv.Mul(x)
46
47 if !xy.IsOne() || !yx.IsOne() {
48 t.Fatalf("Multiplication by inverse failed!\nx = %x\nxInv = %x\nxInv*x = %x\nx*xInv = %x", x, xInv, yx, xy)
49 }
50 }