Source file src/crypto/internal/fips140only/fips140only.go

     1  // Copyright 2024 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  package fips140only
     6  
     7  import (
     8  	"crypto/fips140"
     9  	"crypto/internal/fips140/drbg"
    10  	"crypto/internal/fips140/sha256"
    11  	"crypto/internal/fips140/sha3"
    12  	"crypto/internal/fips140/sha512"
    13  	"hash"
    14  	"io"
    15  )
    16  
    17  // Enforced reports whether FIPS 140-only mode is enabled and enforced, in which non-approved
    18  // cryptography returns an error or panics.
    19  func Enforced() bool {
    20  	return fips140.Enforced()
    21  }
    22  
    23  func ApprovedHash(h hash.Hash) bool {
    24  	switch h.(type) {
    25  	case *sha256.Digest, *sha512.Digest, *sha3.Digest:
    26  		return true
    27  	default:
    28  		return false
    29  	}
    30  }
    31  
    32  func ApprovedRandomReader(r io.Reader) bool {
    33  	_, ok := r.(drbg.DefaultReader)
    34  	return ok
    35  }
    36  

View as plain text