-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxelishash_test.go
68 lines (47 loc) · 1.33 KB
/
xelishash_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
68
package xelishash
import (
"fmt"
"testing"
"time"
)
func testInput(input []byte, expected_hash [32]byte) error {
var scratch_pad ScratchPad
hash := XelisHash(input, &scratch_pad)
if hash != expected_hash {
return fmt.Errorf("hash %x does not match expected hash %x", hash, expected_hash)
}
return nil
}
func TestHash(t *testing.T) {
t.Log("testing hash")
var int_input [KECCAK_WORDS]uint64
keccakp(&int_input)
t.Log(int_input)
err := testInput(make([]byte, 200),
[32]byte{0x0e, 0xbb, 0xbd, 0x8a, 0x31, 0xed, 0xad, 0xfe, 0x09, 0x8f, 0x2d, 0x77, 0x0d, 0x84,
0xb7, 0x19, 0x58, 0x86, 0x75, 0xab, 0x88, 0xa0, 0xa1, 0x70, 0x67, 0xd0, 0x0a, 0x8f,
0x36, 0x18, 0x22, 0x65})
if err != nil {
t.Fatal(err)
}
data := make([]byte, 200)
copy(data, []byte("xelis-hashing-algorithm"))
err = testInput(data, [32]byte{
106, 106, 173, 8, 207, 59, 118, 108, 176, 196, 9, 124, 250, 195, 3,
61, 30, 146, 238, 182, 88, 83, 115, 81, 139, 56, 3, 28, 176, 86, 68, 21})
if err != nil {
t.Fatal(err)
}
}
const nanosecond = 1000 * 1000 * 1000
func BenchmarkHash(b *testing.B) {
var scratch_pad ScratchPad
var input = make([]byte, 200)
b.Log(b.N)
t := time.Now()
for i := 0; i < b.N; i++ {
XelisHash(input, &scratch_pad)
}
deltaT := float64(time.Since(t).Nanoseconds()) / nanosecond
b.Log("H/s:", float64(b.N)/deltaT)
}