Skip to content

Commit 9fd570d

Browse files
committed
curve4q: Test showing DH does not fails on identity point.
1 parent c988ceb commit 9fd570d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

dh/curve4q/curve4Q_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"testing"
99

10+
"github.com/cloudflare/circl/ecc/fourq"
1011
"github.com/cloudflare/circl/internal/test"
1112
)
1213

@@ -37,6 +38,60 @@ func TestDH(t *testing.T) {
3738
}
3839
}
3940

41+
func TestDHLowOrder(t *testing.T) {
42+
var secretAlice, validPublicAlice, invalidPublicAlice, sharedAlice Key
43+
var secretBob, publicBob, sharedBob Key
44+
45+
t.Run("zeroPoint", func(t *testing.T) {
46+
testTimes := 1 << 10
47+
48+
for i := 0; i < testTimes; i++ {
49+
_, _ = rand.Read(secretAlice[:])
50+
_, _ = rand.Read(secretBob[:])
51+
52+
KeyGen(&validPublicAlice, &secretAlice)
53+
KeyGen(&publicBob, &secretBob)
54+
55+
zeroPoint := fourq.Point{}
56+
zeroPoint.SetIdentity()
57+
zeroPoint.Marshal((*[Size]byte)(&invalidPublicAlice))
58+
59+
ok := Shared(&sharedAlice, &secretAlice, &publicBob)
60+
test.CheckOk(ok, "shared must not fail", t)
61+
62+
ok = Shared(&sharedBob, &secretBob, &validPublicAlice)
63+
test.CheckOk(ok, "shared must not fail", t)
64+
65+
invalid := Shared(&sharedBob, &secretBob, &invalidPublicAlice)
66+
test.CheckOk(!invalid, "shared must fail", t)
67+
}
68+
})
69+
70+
t.Run("lowOrderPoint", func(t *testing.T) {
71+
KeyGen(&validPublicAlice, &secretAlice)
72+
KeyGen(&publicBob, &secretBob)
73+
74+
// Point of order 56
75+
lowOrderPoint := fourq.Point{
76+
X: fourq.Fq{
77+
fourq.Fp{0xc0, 0xe5, 0x21, 0x04, 0xaa, 0xe1, 0x93, 0xd8, 0x9b, 0x50, 0x42, 0x54, 0xd6, 0x46, 0x86, 0x74},
78+
fourq.Fp{0x21, 0x25, 0x4d, 0x9a, 0xda, 0x8f, 0xad, 0x28, 0xa2, 0x3d, 0xfd, 0x02, 0x13, 0xea, 0xd2, 0x56},
79+
},
80+
Y: fourq.Fq{
81+
fourq.Fp{0xaf, 0x71, 0xe4, 0x3b, 0x22, 0x21, 0x41, 0xef, 0x12, 0xba, 0x67, 0x02, 0x57, 0x1, 0xe5, 0x58},
82+
fourq.Fp{0x0e, 0x1a, 0xf5, 0xe5, 0xb8, 0x24, 0x9c, 0xe0, 0xed, 0xc3, 0xc4, 0x69, 0x7, 0x32, 0x8e, 0x2c},
83+
},
84+
}
85+
86+
ok := lowOrderPoint.IsOnCurve()
87+
test.CheckOk(ok, "point is on curve", t)
88+
89+
lowOrderPoint.Marshal((*[Size]byte)(&invalidPublicAlice))
90+
invalid := Shared(&sharedBob, &secretBob, &invalidPublicAlice)
91+
test.CheckOk(!invalid, "shared must fail", t)
92+
})
93+
}
94+
4095
func BenchmarkDH(b *testing.B) {
4196
var secret, public, shared Key
4297
_, _ = rand.Read(secret[:])

0 commit comments

Comments
 (0)