Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update schemes.go #49

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 36 additions & 136 deletions kem/schemes/schemes.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package schemes

import (
"fmt"
"log"
"strings"

"github.com/katzenpost/circl/kem/frodo/frodo640shake"
"github.com/katzenpost/circl/kem/kyber/kyber768"

Check failure on line 9 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.21.x)

"github.com/katzenpost/circl/kem/kyber/kyber768" imported and not used

Check failure on line 9 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.22.0)

"github.com/katzenpost/circl/kem/kyber/kyber768" imported and not used

Check failure on line 9 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.21.x)

"github.com/katzenpost/circl/kem/kyber/kyber768" imported and not used

Check failure on line 9 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.22.0)

"github.com/katzenpost/circl/kem/kyber/kyber768" imported and not used
"github.com/katzenpost/circl/kem/mceliece/mceliece348864"
"github.com/katzenpost/circl/kem/mceliece/mceliece348864f"
"github.com/katzenpost/circl/kem/mceliece/mceliece460896"
Expand All @@ -15,63 +17,29 @@
"github.com/katzenpost/circl/kem/mceliece/mceliece6960119f"
"github.com/katzenpost/circl/kem/mceliece/mceliece8192128"
"github.com/katzenpost/circl/kem/mceliece/mceliece8192128f"

"github.com/katzenpost/hpqc/kem"
"github.com/katzenpost/hpqc/kem/adapter"
"github.com/katzenpost/hpqc/kem/combiner"
"github.com/katzenpost/hpqc/kem/hybrid"

Check failure on line 23 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.21.x)

"github.com/katzenpost/hpqc/kem/hybrid" imported and not used

Check failure on line 23 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.22.0)

"github.com/katzenpost/hpqc/kem/hybrid" imported and not used

Check failure on line 23 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.21.x)

"github.com/katzenpost/hpqc/kem/hybrid" imported and not used

Check failure on line 23 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.22.0)

"github.com/katzenpost/hpqc/kem/hybrid" imported and not used
"github.com/katzenpost/hpqc/kem/mlkem768"
"github.com/katzenpost/hpqc/kem/sntrup"
"github.com/katzenpost/hpqc/kem/xwing"

Check failure on line 26 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.21.x)

"github.com/katzenpost/hpqc/kem/xwing" imported and not used

Check failure on line 26 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.22.0)

"github.com/katzenpost/hpqc/kem/xwing" imported and not used

Check failure on line 26 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.21.x)

"github.com/katzenpost/hpqc/kem/xwing" imported and not used

Check failure on line 26 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.22.0)

"github.com/katzenpost/hpqc/kem/xwing" imported and not used
"github.com/katzenpost/hpqc/nike/ctidh/ctidh1024"

Check failure on line 27 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.21.x)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh1024" imported and not used

Check failure on line 27 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.22.0)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh1024" imported and not used

Check failure on line 27 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.21.x)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh1024" imported and not used

Check failure on line 27 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.22.0)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh1024" imported and not used
"github.com/katzenpost/hpqc/nike/ctidh/ctidh2048"

Check failure on line 28 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.21.x)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh2048" imported and not used

Check failure on line 28 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.22.0)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh2048" imported and not used

Check failure on line 28 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.21.x)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh2048" imported and not used

Check failure on line 28 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.22.0)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh2048" imported and not used
"github.com/katzenpost/hpqc/nike/ctidh/ctidh511"

Check failure on line 29 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.21.x)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh511" imported and not used

Check failure on line 29 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.22.0)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh511" imported and not used

Check failure on line 29 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.21.x)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh511" imported and not used

Check failure on line 29 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.22.0)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh511" imported and not used
"github.com/katzenpost/hpqc/nike/ctidh/ctidh512"

Check failure on line 30 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.21.x)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh512" imported and not used

Check failure on line 30 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, amd64, 1.22.0)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh512" imported and not used

Check failure on line 30 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.21.x)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh512" imported and not used

Check failure on line 30 in kem/schemes/schemes.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, arm64, 1.22.0)

"github.com/katzenpost/hpqc/nike/ctidh/ctidh512" imported and not used
"github.com/katzenpost/hpqc/nike/x25519"
"github.com/katzenpost/hpqc/nike/x448"
"github.com/katzenpost/hpqc/rand"
)

var potentialSchemes = [...]kem.Scheme{

// PQ KEMs

adapter.FromNIKE(ctidh511.Scheme()),
adapter.FromNIKE(ctidh512.Scheme()),
adapter.FromNIKE(ctidh1024.Scheme()),
adapter.FromNIKE(ctidh2048.Scheme()),

// hybrid KEMs

combiner.New(
"CTIDH512-X25519",
[]kem.Scheme{
adapter.FromNIKE(ctidh512.Scheme()),
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
},
),
combiner.New(
"CTIDH1024-X448",
[]kem.Scheme{
adapter.FromNIKE(ctidh1024.Scheme()),
adapter.FromNIKE(x448.Scheme(rand.Reader)),
},
),
}

var allSchemes = []kem.Scheme{

// classical KEM schemes (converted from NIKE via hashed elgamal construction)

// Classical DiffieHellman imeplementation has a bug with this ticket:
// https://github.com/katzenpost/hpqc/issues/39
//adapter.FromNIKE(diffiehellman.Scheme()),

// Group schemes into logical categories
var classicalSchemes = []kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
adapter.FromNIKE(x448.Scheme(rand.Reader)),
}

// post quantum KEM schemes

var postQuantumSchemes = []kem.Scheme{
mlkem768.Scheme(),
sntrup.Scheme(),
frodo640shake.Scheme(),
Expand All @@ -85,21 +53,9 @@
mceliece6960119f.Scheme(),
mceliece8192128.Scheme(),
mceliece8192128f.Scheme(),
}

// hybrid KEM schemes

xwing.Scheme(),

// XXX TODO: must soon deprecate use of "hybrid.New" in favour of "combiner.New".
// We'd also like to remove Kyber now that we have mlkem768.
hybrid.New(
"Kyber768-X25519",
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
kyber768.Scheme(),
),

// If Xwing is not the PQ Hybrid KEM you are looking for then we recommend
// using our secure generic KEM combiner:
var hybridSchemes = []kem.Scheme{
combiner.New(
"MLKEM768-X25519",
[]kem.Scheme{
Expand All @@ -114,102 +70,46 @@
mlkem768.Scheme(),
},
),

// all the Classic McEliece's from our fork of circl
combiner.New(
"mceliece348864-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece348864.Scheme(),
},
),
combiner.New(
"mceliece348864f-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece348864f.Scheme(),
},
),
combiner.New(
"mceliece460896-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece460896.Scheme(),
},
),
combiner.New(
"mceliece460896f-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece460896f.Scheme(),
},
),
combiner.New(
"mceliece6688128-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece6688128.Scheme(),
},
),
combiner.New(
"mceliece6688128f-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece6688128f.Scheme(),
},
),
combiner.New(
"mceliece6960119-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece6960119.Scheme(),
},
),
combiner.New(
"mceliece6960119f-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece6960119f.Scheme(),
},
),
combiner.New(
"mceliece8192128-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece8192128.Scheme(),
},
),
combiner.New(
"mceliece8192128f-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece8192128f.Scheme(),
},
),
}

// Collect all schemes together
var allSchemes []kem.Scheme
var allSchemeNames map[string]kem.Scheme

// Initialize all schemes and validate them
func init() {
allSchemeNames = make(map[string]kem.Scheme)
for _, scheme := range potentialSchemes {
if scheme != nil {
allSchemes = append(allSchemes, scheme)
allSchemes = append(allSchemes, classicalSchemes...)
allSchemes = append(allSchemes, postQuantumSchemes...)
allSchemes = append(allSchemes, hybridSchemes...)

for _, scheme := range allSchemes {
if err := validateScheme(scheme); err == nil {
allSchemeNames[strings.ToLower(scheme.Name())] = scheme
} else {
log.Printf("Warning: %v", err)
}
}
for _, scheme := range allSchemes {
allSchemeNames[strings.ToLower(scheme.Name())] = scheme
}

// Validate a scheme to ensure it is not nil and has a valid name
func validateScheme(scheme kem.Scheme) error {
if scheme == nil || strings.TrimSpace(scheme.Name()) == "" {
return fmt.Errorf("invalid scheme: %v", scheme)
}
return nil
}

// ByName returns the NIKE scheme by string name.
func ByName(name string) kem.Scheme {
ret := allSchemeNames[strings.ToLower(name)]
return ret
// ByName retrieves a scheme by name, returning an error if not found
func ByName(name string) (kem.Scheme, error) {
scheme, ok := allSchemeNames[strings.ToLower(name)]
if !ok {
return nil, fmt.Errorf("scheme '%s' not found", name)
}
return scheme, nil
}

// All returns all NIKE schemes supported.
// All returns a slice of all supported schemes
func All() []kem.Scheme {
a := allSchemes
return a[:]
return allSchemes
}
Loading