File: isogeny_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 (35 lines) | stat: -rw-r--r-- 705 bytes parent folder | download | duplicates (4)
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
package goldilocks

import (
	"crypto/rand"
	"testing"

	"github.com/cloudflare/circl/internal/test"
)

func randomPoint() *Point {
	var k Scalar
	_, _ = rand.Read(k[:])
	return Curve{}.ScalarBaseMult(&k)
}

func TestIsogeny(t *testing.T) {
	const testTimes = 1 << 10
	var gold Curve
	var twist twistCurve

	for i := 0; i < testTimes; i++ {
		P := randomPoint()
		Q := gold.pull(gold.push(P)) // phi^-(phi^+(P))
		got := Q
		want := gold.Double(gold.Double(P)) // 4P
		if !got.IsEqual(want) {
			test.ReportError(t, got, want, P)
		}
		got = twist.push(twist.pull(Q))    // phi^-(phi^+(Q))
		want = gold.Double(gold.Double(Q)) // 4Q
		if !got.IsEqual(want) {
			test.ReportError(t, got, want, P)
		}
	}
}