File: bench_test.go

package info (click to toggle)
golang-github-tscholl2-siec 0.0~git20210707.9bdfc48-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 360 kB
  • sloc: makefile: 3
file content (121 lines) | stat: -rw-r--r-- 2,286 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package siec

import (
	"crypto/elliptic"
	"crypto/sha256"
	"testing"

	"github.com/tscholl2/siec/edwards25519"
)

func BenchmarkDouble(b *testing.B) {
	curve := SIEC255()
	x, y := curve.ScalarBaseMult(hash(1))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.Double(x, y)
	}
}

func BenchmarkDoubleP256(b *testing.B) {
	curve := elliptic.P256()
	x, y := curve.ScalarBaseMult(hash(1))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.Double(x, y)
	}
}

func BenchmarkDoubleP224(b *testing.B) {
	curve := elliptic.P224()
	x, y := curve.ScalarBaseMult(hash(1))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.Double(x, y)
	}
}

func BenchmarkAdd(b *testing.B) {
	curve := SIEC255()
	x1, y1 := curve.ScalarBaseMult(hash(1))
	x2, y2 := curve.ScalarBaseMult(hash(2))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.Add(x1, y1, x2, y2)
	}
}

func BenchmarkAddP256(b *testing.B) {
	curve := elliptic.P256()
	x1, y1 := curve.ScalarBaseMult(hash(1))
	x2, y2 := curve.ScalarBaseMult(hash(2))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.Add(x1, y1, x2, y2)
	}
}

func BenchmarkAddP224(b *testing.B) {
	curve := elliptic.P224()
	x1, y1 := curve.ScalarBaseMult(hash(1))
	x2, y2 := curve.ScalarBaseMult(hash(2))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.Add(x1, y1, x2, y2)
	}
}

func BenchmarkScale(b *testing.B) {
	curve := SIEC255()
	k := hash(1)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.ScalarBaseMult(k)
	}
}

func BenchmarkScale2(b *testing.B) {
	curve := SIEC255()
	k := hash(1)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.scalarMult2(curve.Gx, curve.Gy, k)
	}
}

func BenchmarkScaleP256(b *testing.B) {
	curve := elliptic.P256()
	k := hash(1)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.ScalarBaseMult(k)
	}
}

func BenchmarkScaleP224(b *testing.B) {
	curve := elliptic.P224()
	k := hash(1)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		curve.ScalarBaseMult(k)
	}
}

func BenchmarkScaleEd25519(b *testing.B) {
	arr := hash(1)
	arr[0] &= 248
	arr[31] &= 127
	arr[31] |= 64
	var A edwards25519.ExtendedGroupElement
	var hBytes [32]byte
	copy(hBytes[:], arr)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		edwards25519.GeScalarMultBase(&A, &hBytes)
	}
}

func hash(i int) []byte {
	arr := sha256.Sum256([]byte{byte(i)})
	return arr[:]
}