forked from refraction-networking/utls
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tls_cf.go
66 lines (57 loc) · 1.92 KB
/
tls_cf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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()))
}
}