forked from kilic/bls12-381
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbls12_381_test.go
67 lines (61 loc) · 1.1 KB
/
bls12_381_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package bls12381
import (
"crypto/rand"
"encoding/hex"
"errors"
"flag"
"math/big"
"os"
"testing"
)
var fuz int
func TestMain(m *testing.M) {
_fuz := flag.Int("fuzz", 10, "# of iterations")
flag.Parse()
fuz = *_fuz
os.Exit(m.Run())
}
func randScalar(max *big.Int) *big.Int {
a, err := rand.Int(rand.Reader, max)
if err != nil {
panic(errors.New(""))
}
return a
}
func fromHex(size int, hexStrs ...string) []byte {
var out []byte
if size > 0 {
out = make([]byte, size*len(hexStrs))
}
for i := 0; i < len(hexStrs); i++ {
hexStr := hexStrs[i]
if hexStr[:2] == "0x" {
hexStr = hexStr[2:]
}
if len(hexStr)%2 == 1 {
hexStr = "0" + hexStr
}
bytes, err := hex.DecodeString(hexStr)
if err != nil {
return nil
}
if size <= 0 {
out = append(out, bytes...)
} else {
if len(bytes) > size {
return nil
}
offset := i*size + (size - len(bytes))
copy(out[offset:], bytes)
}
}
return out
}
func padBytes(in []byte, size int) []byte {
out := make([]byte, size)
if len(in) > size {
panic("bad input for padding")
}
copy(out[size-len(in):], in)
return out
}