utls/tls_cf.go
Gaukas Wang 6c1a910019 uTLS: X25519Kyber768Draft00 hybrid post-quantum key agreement by cloudflare/go (#222)
* crypto/tls: Add hybrid post-quantum key agreement  (#13)

* import: client-side KEM from cloudflare/go

* import: server-side KEM from cloudflare/go

* fix: modify test to get rid of CFEvents.

Note: uTLS does not promise any server-side functionality, and this change is made to be able to conduct unit tests which requires both side to be able to handle KEM Curves.

Co-authored-by: Christopher Wood <caw@heapingbits.net>
Co-Authored-By: Bas Westerbaan <bas@westerbaan.name>

----

Based on:

* crypto/tls: Add hybrid post-quantum key agreement 

Adds X25519Kyber512Draft00, X25519Kyber768Draft00, and
P256Kyber768Draft00 hybrid post-quantum key agreements with temporary
group identifiers.

The hybrid post-quantum key exchanges uses plain X{25519,448} instead
of HPKE, which we assume will be more likely to be adopted. The order
is chosen to match CECPQ2.

Not enabled by default.

Adds CFEvents to detect `HelloRetryRequest`s and to signal which
key agreement was used.

Co-authored-by: Christopher Wood <caw@heapingbits.net>

 [bas, 1.20.1: also adds P256Kyber768Draft00]
 [pwu, 1.20.4: updated circl to v1.3.3, moved code to cfevent.go]

* crypto: add support for CIRCL signature schemes

* only partially port the commit from cloudflare/go. We would stick to the official x509 at the cost of incompatibility.

Co-Authored-By: Bas Westerbaan <bas@westerbaan.name>
Co-Authored-By: Christopher Patton <3453007+cjpatton@users.noreply.github.com>
Co-Authored-By: Peter Wu <peter@lekensteyn.nl>

* crypto/tls: add new X25519Kyber768Draft00 code point

Ported from cloudflare/go to support the upcoming new post-quantum keyshare.

----

* Point tls.X25519Kyber768Draft00 to the new 0x6399 identifier while the
  old 0xfe31 identifier is available as tls.X25519Kyber768Draft00Old.
* Make sure that the kem.PrivateKey can always be mapped to the CurveID
  that was linked to it. This is needed since we now have two ID
  aliasing to the same scheme, and clients need to be able to detect
  whether the key share presented by the server actually matches the key
  share that the client originally sent.
* Update tests, add the new identifier and remove unnecessary code.

Link: https://mailarchive.ietf.org/arch/msg/tls/HAWpNpgptl--UZNSYuvsjB-Pc2k/
Link: https://datatracker.ietf.org/doc/draft-tls-westerbaan-xyber768d00/02/
Co-Authored-By: Peter Wu <peter@lekensteyn.nl>
Co-Authored-By: Bas Westerbaan <bas@westerbaan.name>

---------

Co-authored-by: Bas Westerbaan <bas@westerbaan.name>
Co-authored-by: Christopher Patton <3453007+cjpatton@users.noreply.github.com>
Co-authored-by: Peter Wu <peter@lekensteyn.nl>
2023-08-26 14:23:54 -06:00

66 lines
1.9 KiB
Go

// Copyright 2021 Cloudflare, Inc. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
package tls
import (
circlPki "github.com/cloudflare/circl/pki"
circlSign "github.com/cloudflare/circl/sign"
"github.com/cloudflare/circl/sign/eddilithium3"
)
// To add a signature scheme from Circl
//
// 1. make sure it implements TLSScheme and CertificateScheme,
// 2. follow the instructions in crypto/x509/x509_cf.go
// 3. add a signature<NameOfAlg> to the iota in common.go
// 4. add row in the circlSchemes lists below
var circlSchemes = [...]struct {
sigType uint8
scheme circlSign.Scheme
}{
{signatureEdDilithium3, eddilithium3.Scheme()},
}
func circlSchemeBySigType(sigType uint8) circlSign.Scheme {
for _, cs := range circlSchemes {
if cs.sigType == sigType {
return cs.scheme
}
}
return nil
}
func sigTypeByCirclScheme(scheme circlSign.Scheme) uint8 {
for _, cs := range circlSchemes {
if cs.scheme == scheme {
return cs.sigType
}
}
return 0
}
var supportedSignatureAlgorithmsWithCircl []SignatureScheme
// supportedSignatureAlgorithms returns enabled signature schemes. PQ signature
// schemes are only included when tls.Config#PQSignatureSchemesEnabled is set
// and FIPS-only mode is not enabled.
func (c *Config) supportedSignatureAlgorithms() []SignatureScheme {
// If FIPS-only mode is requested, do not add other algos.
if needFIPS() {
return supportedSignatureAlgorithms()
}
if c != nil && c.PQSignatureSchemesEnabled {
return supportedSignatureAlgorithmsWithCircl
}
return defaultSupportedSignatureAlgorithms
}
func init() {
supportedSignatureAlgorithmsWithCircl = append([]SignatureScheme{}, defaultSupportedSignatureAlgorithms...)
for _, cs := range circlSchemes {
supportedSignatureAlgorithmsWithCircl = append(supportedSignatureAlgorithmsWithCircl,
SignatureScheme(cs.scheme.(circlPki.TLSScheme).TLSIdentifier()))
}
}