github.com/cloudflare/circl@v1.5.0/kem/schemes/schemes.go (about)

     1  // Package schemes contains a register of KEM schemes.
     2  //
     3  // # Schemes Implemented
     4  //
     5  // Based on standard elliptic curves:
     6  //
     7  //	HPKE_KEM_P256_HKDF_SHA256, HPKE_KEM_P384_HKDF_SHA384, HPKE_KEM_P521_HKDF_SHA512
     8  //
     9  // Based on standard Diffie-Hellman functions:
    10  //
    11  //	HPKE_KEM_X25519_HKDF_SHA256, HPKE_KEM_X448_HKDF_SHA512
    12  //
    13  // Post-quantum kems:
    14  //
    15  //	FrodoKEM-640-SHAKE
    16  //	Kyber512, Kyber768, Kyber1024
    17  package schemes
    18  
    19  import (
    20  	"strings"
    21  
    22  	"github.com/cloudflare/circl/hpke"
    23  	"github.com/cloudflare/circl/kem"
    24  	"github.com/cloudflare/circl/kem/frodo/frodo640shake"
    25  	"github.com/cloudflare/circl/kem/hybrid"
    26  	"github.com/cloudflare/circl/kem/kyber/kyber1024"
    27  	"github.com/cloudflare/circl/kem/kyber/kyber512"
    28  	"github.com/cloudflare/circl/kem/kyber/kyber768"
    29  	"github.com/cloudflare/circl/kem/mlkem/mlkem1024"
    30  	"github.com/cloudflare/circl/kem/mlkem/mlkem512"
    31  	"github.com/cloudflare/circl/kem/mlkem/mlkem768"
    32  )
    33  
    34  var allSchemes = [...]kem.Scheme{
    35  	hpke.KEM_P256_HKDF_SHA256.Scheme(),
    36  	hpke.KEM_P384_HKDF_SHA384.Scheme(),
    37  	hpke.KEM_P521_HKDF_SHA512.Scheme(),
    38  	hpke.KEM_X25519_HKDF_SHA256.Scheme(),
    39  	hpke.KEM_X448_HKDF_SHA512.Scheme(),
    40  	frodo640shake.Scheme(),
    41  	kyber512.Scheme(),
    42  	kyber768.Scheme(),
    43  	kyber1024.Scheme(),
    44  	mlkem512.Scheme(),
    45  	mlkem768.Scheme(),
    46  	mlkem1024.Scheme(),
    47  	hybrid.Kyber512X25519(),
    48  	hybrid.Kyber768X25519(),
    49  	hybrid.Kyber768X448(),
    50  	hybrid.Kyber1024X448(),
    51  	hybrid.P256Kyber768Draft00(),
    52  	hybrid.X25519MLKEM768(),
    53  }
    54  
    55  var allSchemeNames map[string]kem.Scheme
    56  
    57  func init() {
    58  	allSchemeNames = make(map[string]kem.Scheme)
    59  	for _, scheme := range allSchemes {
    60  		allSchemeNames[strings.ToLower(scheme.Name())] = scheme
    61  	}
    62  }
    63  
    64  // ByName returns the scheme with the given name and nil if it is not
    65  // supported.
    66  //
    67  // Names are case insensitive.
    68  func ByName(name string) kem.Scheme {
    69  	return allSchemeNames[strings.ToLower(name)]
    70  }
    71  
    72  // All returns all KEM schemes supported.
    73  func All() []kem.Scheme { a := allSchemes; return a[:] }