Source file src/crypto/tls/defaults_fips140.go

     1  // Copyright 2025 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !boringcrypto
     6  
     7  package tls
     8  
     9  import (
    10  	"crypto/ecdsa"
    11  	"crypto/ed25519"
    12  	"crypto/elliptic"
    13  	"crypto/internal/boring"
    14  	"crypto/mldsa"
    15  	"crypto/rsa"
    16  	"crypto/x509"
    17  )
    18  
    19  // These FIPS 140-3 policies allow anything approved by SP 800-140C
    20  // and SP 800-140D, and tested as part of the Go Cryptographic Module.
    21  //
    22  // Notably, not SHA-1, 3DES, RC4, ChaCha20Poly1305, RSA PKCS #1 v1.5 key
    23  // transport, or TLS 1.0—1.1 (because we don't test its KDF).
    24  //
    25  // These are not default lists, but filters to apply to the default or
    26  // configured lists. Missing items are treated as if they were not implemented.
    27  //
    28  // They are applied when the fips140 GODEBUG is "on" or "only".
    29  
    30  var (
    31  	allowedSupportedVersionsFIPS = []uint16{
    32  		VersionTLS12,
    33  		VersionTLS13,
    34  	}
    35  	allowedCurvePreferencesFIPS = []CurveID{
    36  		X25519MLKEM768,
    37  		SecP256r1MLKEM768,
    38  		SecP384r1MLKEM1024,
    39  		MLKEM1024,
    40  		CurveP256,
    41  		CurveP384,
    42  		CurveP521,
    43  	}
    44  	allowedSignatureAlgorithmsFIPS = []SignatureScheme{
    45  		PSSWithSHA256,
    46  		ECDSAWithP256AndSHA256,
    47  		Ed25519,
    48  		MLDSA44,
    49  		MLDSA65,
    50  		MLDSA87,
    51  		PSSWithSHA384,
    52  		PSSWithSHA512,
    53  		PKCS1WithSHA256,
    54  		PKCS1WithSHA384,
    55  		PKCS1WithSHA512,
    56  		ECDSAWithP384AndSHA384,
    57  		ECDSAWithP521AndSHA512,
    58  	}
    59  	allowedCipherSuitesFIPS = []uint16{
    60  		TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
    61  		TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
    62  		TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
    63  		TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
    64  		TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
    65  		TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
    66  	}
    67  	allowedCipherSuitesTLS13FIPS = []uint16{
    68  		TLS_AES_128_GCM_SHA256,
    69  		TLS_AES_256_GCM_SHA384,
    70  	}
    71  )
    72  
    73  func isCertificateAllowedFIPS(c *x509.Certificate) bool {
    74  	switch k := c.PublicKey.(type) {
    75  	case *rsa.PublicKey:
    76  		return k.N.BitLen() >= 2048
    77  	case *ecdsa.PublicKey:
    78  		return k.Curve == elliptic.P256() || k.Curve == elliptic.P384() || k.Curve == elliptic.P521()
    79  	case ed25519.PublicKey:
    80  		return true
    81  	case *mldsa.PublicKey:
    82  		// Only for the native module.
    83  		return !boring.Enabled
    84  	default:
    85  		return false
    86  	}
    87  }
    88  

View as plain text