Skip to content

Conversation

@mivds
Copy link
Contributor

@mivds mivds commented Aug 18, 2025

Resolves #2354

@mivds mivds force-pushed the 2354/blake2b-optional branch from 653c43d to da9574d Compare August 18, 2025 19:57
@sonarqubecloud
Copy link

@sumit-gupta-sgt
Copy link

Hi @mivds, Thank you for addressing the FIPS compatibility issue in soda-core by removing the digest_size argument from hashlib.blake2b(). This change is crucial for ensuring the library functions correctly in FIPS-enabled environments.

To further enhance compatibility and avoid potential issues with openssl_blake2b, I recommend implementing a fallback mechanism that attempts to use hashlib.blake2b() without the digest_size argument. If that fails, the system should gracefully fall back to hashlib.sha256() or return None if hashing isn't feasible. This approach ensures that the library remains functional across various environments, including those with strict cryptographic standards.

import hashlib
from typing import Optional

def get_identity(data: str, digest_size: int = 16) -> Optional[str]:
"""
Generate a FIPS-safe identity hash for the given data.

- Uses blake2b with digest_size if supported.
- Falls back to default blake2b if digest_size not supported.
- Falls back to SHA256 if blake2b is unavailable (e.g., FIPS mode).
- Returns None if no hash can be generated.
"""
encoded_data = data.encode("utf-8")

# Try blake2b with digest_size
try:
    return hashlib.blake2b(encoded_data, digest_size=digest_size).hexdigest()
except (TypeError, ValueError):
    pass  # Likely FIPS/OpenSSL restriction

# Try default blake2b
try:
    return hashlib.blake2b(encoded_data).hexdigest()
except (AttributeError, ValueError):
    pass  # Blake2b unavailable

# Fallback to SHA256 (FIPS-safe)
try:
    return hashlib.sha256(encoded_data).hexdigest()
except Exception:
    pass  # Extremely unlikely

# Return None if everything fails
return None

Implementing this fallback mechanism will enhance the robustness of soda-core in diverse environments. Please let me know if you need assistance integrating this solution or if you have any questions.

Comment on lines +88 to +89
if blake2b is None:
return

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the downside to none Identity ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Soda Core fails in FIPS-enabled environments due to use of hashlib.blake2b

4 participants