File: api_test.go

package info (click to toggle)
golang-github-cloudflare-circl 1.0.0%2B20200724-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,788 kB
  • sloc: asm: 19,418; ansic: 1,289; makefile: 54
file content (56 lines) | stat: -rw-r--r-- 1,144 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
// +build arm64 amd64

package p384_test

import (
	"crypto/elliptic"
	"crypto/rand"
	"fmt"
	"testing"

	"github.com/cloudflare/circl/ecc/p384"
)

func BenchmarkScalarMult(b *testing.B) {
	curve := p384.P384()
	params := curve.Params()

	K, _ := rand.Int(rand.Reader, params.N)
	M, _ := rand.Int(rand.Reader, params.N)
	N, _ := rand.Int(rand.Reader, params.N)
	k := K.Bytes()
	m := M.Bytes()
	n := N.Bytes()

	b.Run("kG", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			curve.ScalarBaseMult(k)
		}
	})
	b.Run("kP", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			curve.ScalarMult(params.Gx, params.Gy, k)
		}
	})
	b.Run("kG+lP", func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			_, _ = curve.CombinedMult(params.Gx, params.Gy, m, n)
		}
	})
}

func Example_p384() {
	// import "github.com/cloudflare/circl/ecc/p384"
	// import "crypto/elliptic"
	circl := p384.P384()
	stdlib := elliptic.P384()

	params := circl.Params()
	K, _ := rand.Int(rand.Reader, params.N)
	k := K.Bytes()

	x1, y1 := circl.ScalarBaseMult(k)
	x2, y2 := stdlib.ScalarBaseMult(k)
	fmt.Printf("%v, %v", x1.Cmp(x2) == 0, y1.Cmp(y2) == 0)
	// Output: true, true
}