File tree Expand file tree Collapse file tree
cuda/core/utils/_program_cache Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -422,11 +422,17 @@ def _path_for_key(self, key: object) -> Path:
422422 k = _as_key_bytes (key )
423423 # Hash the key to a fixed-length identifier so arbitrary-length user
424424 # keys never exceed per-component filename limits (typically 255 on
425- # ext4 / NTFS). With a 256-bit blake2b digest, the cache relies on
426- # cryptographic collision resistance for key uniqueness -- two
427- # distinct keys hashing to the same path is astronomically unlikely
428- # (~2^-128 with the 32-byte digest in use here).
429- digest = hashlib .blake2b (k , digest_size = 32 ).hexdigest ()
425+ # ext4 / NTFS).
426+ #
427+ # FIPS: must use a FIPS-approved hash algorithm. FIPS-enforcing
428+ # systems can disable non-approved hashlib algorithms (for example
429+ # blake2b) at the OpenSSL level. See #2043.
430+ #
431+ # With a 256-bit SHA-256 digest, the cache relies on collision
432+ # resistance for key uniqueness -- two distinct keys hashing to the
433+ # same path is astronomically unlikely (~2^128 practical collision
434+ # work).
435+ digest = hashlib .sha256 (k , usedforsecurity = False ).hexdigest ()
430436 return self ._entries / digest [:2 ] / digest [2 :]
431437
432438 # -- mapping API ---------------------------------------------------------
Original file line number Diff line number Diff line change 3535)
3636
3737# Bump when the key schema changes in a way that invalidates existing caches.
38- _KEY_SCHEMA_VERSION = 1
38+ _KEY_SCHEMA_VERSION = 2
3939
4040_VALID_CODE_TYPES = frozenset ({"c++" , "ptx" , "nvvm" })
4141_VALID_TARGET_TYPES = frozenset ({"ptx" , "cubin" , "ltoir" })
@@ -768,7 +768,10 @@ def make_program_cache_key(
768768 option_bytes = backend .option_fingerprint (options , target_type )
769769 name_tags = backend .encode_name_expressions (name_expressions )
770770
771- hasher = hashlib .blake2b (digest_size = 32 )
771+ # IMPORTANT: Must use a FIPS-approved hash algorithm (SHA-2 family).
772+ # FIPS-enforcing systems can disable non-approved hashlib algorithms
773+ # (for example blake2b) at the OpenSSL level. See #2043.
774+ hasher = hashlib .sha256 (usedforsecurity = False )
772775
773776 def _update (label : str , payload : bytes ) -> None :
774777 hasher .update (label .encode ("ascii" ))
Original file line number Diff line number Diff line change @@ -1773,7 +1773,7 @@ def test_filestream_cache_size_cap_counts_tmp_files(tmp_path):
17731773
17741774def test_filestream_cache_handles_long_keys (tmp_path ):
17751775 """Arbitrary-length keys must not overflow per-component filename limits.
1776- The filename is a fixed-length 256-bit blake2b digest; key uniqueness
1776+ The filename is a fixed-length 256-bit digest; key uniqueness
17771777 relies on the digest's collision resistance."""
17781778 from cuda .core .utils import FileStreamProgramCache
17791779
You can’t perform that action at this time.
0 commit comments