tls_cf.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2021 Cloudflare, Inc. All rights reserved. Use of this source code
  2. // is governed by a BSD-style license that can be found in the LICENSE file.
  3. package tls
  4. import (
  5. circlPki "github.com/cloudflare/circl/pki"
  6. circlSign "github.com/cloudflare/circl/sign"
  7. "github.com/cloudflare/circl/sign/eddilithium3"
  8. )
  9. // To add a signature scheme from Circl
  10. //
  11. // 1. make sure it implements TLSScheme and CertificateScheme,
  12. // 2. follow the instructions in crypto/x509/x509_cf.go
  13. // 3. add a signature<NameOfAlg> to the iota in common.go
  14. // 4. add row in the circlSchemes lists below
  15. var circlSchemes = [...]struct {
  16. sigType uint8
  17. scheme circlSign.Scheme
  18. }{
  19. {signatureEdDilithium3, eddilithium3.Scheme()},
  20. }
  21. func circlSchemeBySigType(sigType uint8) circlSign.Scheme {
  22. for _, cs := range circlSchemes {
  23. if cs.sigType == sigType {
  24. return cs.scheme
  25. }
  26. }
  27. return nil
  28. }
  29. func sigTypeByCirclScheme(scheme circlSign.Scheme) uint8 {
  30. for _, cs := range circlSchemes {
  31. if cs.scheme == scheme {
  32. return cs.sigType
  33. }
  34. }
  35. return 0
  36. }
  37. var supportedSignatureAlgorithmsWithCircl []SignatureScheme
  38. // supportedSignatureAlgorithms returns enabled signature schemes. PQ signature
  39. // schemes are only included when tls.Config#PQSignatureSchemesEnabled is set
  40. // and FIPS-only mode is not enabled.
  41. func (c *Config) supportedSignatureAlgorithms() []SignatureScheme {
  42. // If FIPS-only mode is requested, do not add other algos.
  43. if needFIPS() {
  44. return supportedSignatureAlgorithms()
  45. }
  46. if c != nil && c.PQSignatureSchemesEnabled {
  47. return supportedSignatureAlgorithmsWithCircl
  48. }
  49. return defaultSupportedSignatureAlgorithms
  50. }
  51. func init() {
  52. supportedSignatureAlgorithmsWithCircl = append([]SignatureScheme{}, defaultSupportedSignatureAlgorithms...)
  53. for _, cs := range circlSchemes {
  54. supportedSignatureAlgorithmsWithCircl = append(supportedSignatureAlgorithmsWithCircl,
  55. SignatureScheme(cs.scheme.(circlPki.TLSScheme).TLSIdentifier()))
  56. }
  57. }