Skip to content

Commit

Permalink
sphinx: fix CTIDH unit tests and benchmark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
david415 committed Jan 10, 2024
1 parent 1175a1c commit 3136120
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 39 deletions.
4 changes: 2 additions & 2 deletions core/sphinx/ctidh1024_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"

"github.com/katzenpost/katzenpost/core/crypto/kem/adapter"
"github.com/katzenpost/katzenpost/core/crypto/nike/ctidh"
ctidh "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh1024"
)

func BenchmarkCtidh1024SphinxUnwrap(b *testing.B) {
Expand All @@ -33,6 +33,6 @@ func BenchmarkCtidh1024SphinxUnwrap(b *testing.B) {
benchmarkSphinxUnwrap(b, ctidh.CTIDH1024Scheme)
}

func BenchmarkKEMSphinxUnwrapCSTIDH1024(b *testing.B) {
func BenchmarkKEMSphinxUnwrapCTIDH1024(b *testing.B) {
benchmarkKEMSphinxUnwrap(b, adapter.FromNIKE(ctidh.CTIDH1024Scheme))
}
4 changes: 2 additions & 2 deletions core/sphinx/ctidh2048_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ package sphinx
import (
"testing"

ctidhnike "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh"
ctidh "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh2048"
)

func BenchmarkCtidh2048SphinxUnwrap(b *testing.B) {
benchmarkSphinxUnwrap(b, ctidhnike.NewCtidhNike())
benchmarkSphinxUnwrap(b, ctidh.CTIDH2048Scheme)
}
4 changes: 2 additions & 2 deletions core/sphinx/ctidh511_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ package sphinx
import (
"testing"

ctidhnike "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh"
ctidhnike "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh511"
)

func BenchmarkCtidh511SphinxUnwrap(b *testing.B) {
benchmarkSphinxUnwrap(b, ctidhnike.NewCtidhNike())
benchmarkSphinxUnwrap(b, ctidhnike.CTIDH511Scheme)
}
4 changes: 2 additions & 2 deletions core/sphinx/ctidh512_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ package sphinx
import (
"testing"

ctidhnike "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh"
ctidhnike "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh512"
)

func BenchmarkCtidh512SphinxUnwrap(b *testing.B) {
benchmarkSphinxUnwrap(b, ctidhnike.NewCtidhNike())
benchmarkSphinxUnwrap(b, ctidhnike.CTIDH512Scheme)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build ctidh
// +build ctidh
//go:build ctidh1024

// sphinx_ctidh_test.go - Sphinx Packet Format tests.
// Copyright (C) 2022 David Stainton.
Expand All @@ -20,20 +19,14 @@
package sphinx

import (
"crypto/rand"
"testing"

"github.com/stretchr/testify/require"

"github.com/katzenpost/katzenpost/core/crypto/nike"
"github.com/katzenpost/katzenpost/core/crypto/nike/ctidh"
ecdhnike "github.com/katzenpost/katzenpost/core/crypto/nike/ecdh"
ctidh "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh1024"
"github.com/katzenpost/katzenpost/core/crypto/nike/hybrid"
"github.com/katzenpost/katzenpost/core/sphinx/geo"
)

func TestHybridCtidhForwardSphinx(t *testing.T) {
t.Parallel()
const testPayload = "It is the stillest words that bring on the storm. Thoughts that come on doves’ feet guide the world."

mynike := hybrid.CTIDH1024X25519
Expand All @@ -47,27 +40,7 @@ func TestHybridCtidhForwardSphinx(t *testing.T) {
testForwardSphinx(t, mynike, sphinx, []byte(testPayload))
}

func TestSphinxConstruction(t *testing.T) {
var mynike nike.Scheme
mynike = ecdhnike.NewEcdhNike(rand.Reader)
g := geo.GeometryFromUserForwardPayloadLength(mynike, 12345, false, 5)
t.Logf("NIKEName %s", g.NIKEName)
sphinx := NewSphinx(g)
require.NotNil(t, sphinx.nike)

/* XXX this code panics if CTIDH1024Scheme isn't included in the
NIKE Scheme map in the nike/schemes module.
mynike = ctidh.CTIDH1024Scheme
g = geo.GeometryFromUserForwardPayloadLength(mynike, 12345, false, 5)
t.Logf("NIKEName %s", g.NIKEName)
sphinx = NewSphinx(g)
require.NotNil(t, sphinx.nike)
*/
}

func TestCtidhForwardSphinx(t *testing.T) {
t.Parallel()
const testPayload = "It is the stillest words that bring on the storm. Thoughts that come on doves’ feet guide the world."

mynike := ctidh.CTIDH1024Scheme
Expand All @@ -78,7 +51,6 @@ func TestCtidhForwardSphinx(t *testing.T) {
}

func TestCtidhSURB(t *testing.T) {
t.Parallel()
const testPayload = "The smallest minority on earth is the individual. Those who deny individual rights cannot claim to be defenders of minorities."

mynike := ctidh.CTIDH1024Scheme
Expand All @@ -89,7 +61,6 @@ func TestCtidhSURB(t *testing.T) {
}

func TestCTIDHSphinxGeometry(t *testing.T) {
t.Parallel()
withSURB := false
g := geo.GeometryFromUserForwardPayloadLength(ctidh.CTIDH1024Scheme, 512, withSURB, 5)
t.Logf("NIKE Sphinx CTIDH 5 hops: HeaderLength = %d", g.HeaderLength)
Expand Down
69 changes: 69 additions & 0 deletions core/sphinx/sphinx_ctidh2048_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//go:build ctidh2048

// sphinx_ctidh_test.go - Sphinx Packet Format tests.
// Copyright (C) 2022 David Stainton.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package sphinx

import (
"testing"

ctidh "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh2048"
"github.com/katzenpost/katzenpost/core/crypto/nike/hybrid"
"github.com/katzenpost/katzenpost/core/sphinx/geo"
)

func TestHybridCtidhForwardSphinx(t *testing.T) {
const testPayload = "It is the stillest words that bring on the storm. Thoughts that come on doves’ feet guide the world."

mynike := hybrid.CTIDH2048X25519
g := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)

t.Logf("NIKE: %s", g.NIKEName)
t.Logf("KEM: %s", g.KEMName)

sphinx := NewNIKESphinx(mynike, g)

testForwardSphinx(t, mynike, sphinx, []byte(testPayload))
}

func TestCtidhForwardSphinx(t *testing.T) {
const testPayload = "It is the stillest words that bring on the storm. Thoughts that come on doves’ feet guide the world."

mynike := ctidh.CTIDH2048Scheme
geo := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)
sphinx := NewNIKESphinx(mynike, geo)

testForwardSphinx(t, mynike, sphinx, []byte(testPayload))
}

func TestCtidhSURB(t *testing.T) {
const testPayload = "The smallest minority on earth is the individual. Those who deny individual rights cannot claim to be defenders of minorities."

mynike := ctidh.CTIDH2048Scheme
geo := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)
sphinx := NewNIKESphinx(mynike, geo)

testSURB(t, mynike, sphinx, []byte(testPayload))
}

func TestCTIDHSphinxGeometry(t *testing.T) {
withSURB := false
g := geo.GeometryFromUserForwardPayloadLength(ctidh.CTIDH2048Scheme, 512, withSURB, 5)
t.Logf("NIKE Sphinx CTIDH 5 hops: HeaderLength = %d", g.HeaderLength)
g = geo.GeometryFromUserForwardPayloadLength(ctidh.CTIDH2048Scheme, 512, withSURB, 10)
t.Logf("NIKE Sphinx CTIDH 10 hops: HeaderLength = %d", g.HeaderLength)
}
69 changes: 69 additions & 0 deletions core/sphinx/sphinx_ctidh511_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//go:build ctidh511

// sphinx_ctidh_test.go - Sphinx Packet Format tests.
// Copyright (C) 2022 David Stainton.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package sphinx

import (
"testing"

ctidh "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh511"
"github.com/katzenpost/katzenpost/core/crypto/nike/hybrid"
"github.com/katzenpost/katzenpost/core/sphinx/geo"
)

func TestHybridCtidhForwardSphinx(t *testing.T) {
const testPayload = "It is the stillest words that bring on the storm. Thoughts that come on doves’ feet guide the world."

mynike := hybrid.CTIDH511X25519
g := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)

t.Logf("NIKE: %s", g.NIKEName)
t.Logf("KEM: %s", g.KEMName)

sphinx := NewNIKESphinx(mynike, g)

testForwardSphinx(t, mynike, sphinx, []byte(testPayload))
}

func TestCtidhForwardSphinx(t *testing.T) {
const testPayload = "It is the stillest words that bring on the storm. Thoughts that come on doves’ feet guide the world."

mynike := ctidh.CTIDH511Scheme
geo := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)
sphinx := NewNIKESphinx(mynike, geo)

testForwardSphinx(t, mynike, sphinx, []byte(testPayload))
}

func TestCtidhSURB(t *testing.T) {
const testPayload = "The smallest minority on earth is the individual. Those who deny individual rights cannot claim to be defenders of minorities."

mynike := ctidh.CTIDH511Scheme
geo := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)
sphinx := NewNIKESphinx(mynike, geo)

testSURB(t, mynike, sphinx, []byte(testPayload))
}

func TestCTIDHSphinxGeometry(t *testing.T) {
withSURB := false
g := geo.GeometryFromUserForwardPayloadLength(ctidh.CTIDH511Scheme, 512, withSURB, 5)
t.Logf("NIKE Sphinx CTIDH 5 hops: HeaderLength = %d", g.HeaderLength)
g = geo.GeometryFromUserForwardPayloadLength(ctidh.CTIDH511Scheme, 512, withSURB, 10)
t.Logf("NIKE Sphinx CTIDH 10 hops: HeaderLength = %d", g.HeaderLength)
}
69 changes: 69 additions & 0 deletions core/sphinx/sphinx_ctidh512_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//go:build ctidh512

// sphinx_ctidh_test.go - Sphinx Packet Format tests.
// Copyright (C) 2022 David Stainton.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package sphinx

import (
"testing"

ctidh "github.com/katzenpost/katzenpost/core/crypto/nike/ctidh512"
"github.com/katzenpost/katzenpost/core/crypto/nike/hybrid"
"github.com/katzenpost/katzenpost/core/sphinx/geo"
)

func TestHybridCtidhForwardSphinx(t *testing.T) {
const testPayload = "It is the stillest words that bring on the storm. Thoughts that come on doves’ feet guide the world."

mynike := hybrid.CTIDH512X25519
g := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)

t.Logf("NIKE: %s", g.NIKEName)
t.Logf("KEM: %s", g.KEMName)

sphinx := NewNIKESphinx(mynike, g)

testForwardSphinx(t, mynike, sphinx, []byte(testPayload))
}

func TestCtidhForwardSphinx(t *testing.T) {
const testPayload = "It is the stillest words that bring on the storm. Thoughts that come on doves’ feet guide the world."

mynike := ctidh.CTIDH512Scheme
geo := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)
sphinx := NewNIKESphinx(mynike, geo)

testForwardSphinx(t, mynike, sphinx, []byte(testPayload))
}

func TestCtidhSURB(t *testing.T) {
const testPayload = "The smallest minority on earth is the individual. Those who deny individual rights cannot claim to be defenders of minorities."

mynike := ctidh.CTIDH512Scheme
geo := geo.GeometryFromUserForwardPayloadLength(mynike, len(testPayload), false, 5)
sphinx := NewNIKESphinx(mynike, geo)

testSURB(t, mynike, sphinx, []byte(testPayload))
}

func TestCTIDHSphinxGeometry(t *testing.T) {
withSURB := false
g := geo.GeometryFromUserForwardPayloadLength(ctidh.CTIDH512Scheme, 512, withSURB, 5)
t.Logf("NIKE Sphinx CTIDH 5 hops: HeaderLength = %d", g.HeaderLength)
g = geo.GeometryFromUserForwardPayloadLength(ctidh.CTIDH512Scheme, 512, withSURB, 10)
t.Logf("NIKE Sphinx CTIDH 10 hops: HeaderLength = %d", g.HeaderLength)
}

0 comments on commit 3136120

Please sign in to comment.