33defmodule Opsm.Crypto.Hash do
44 @ moduledoc """
55 Hybrid hashing strategy:
6- - BLAKE3 (512-bit) for hot paths (speed-critical)
6+ - BLAKE2b (512-bit) for hot paths (speed-critical)
77 - SHAKE256 (512-bit) for cold storage (long-term, PQ-secure)
88
99 Aligns with SECURITY-STANDARDS.scm DatabaseHashing requirements.
10+
11+ Note: Using BLAKE2b instead of BLAKE3 due to dependency compatibility.
12+ BLAKE2b is cryptographically secure, fast, and built-in to Erlang's :crypto module.
1013 """
1114
12- @ blake3_output_size 64 # 512 bits
15+ @ blake2b_output_size 64 # 512 bits
1316 @ shake256_output_size 64 # 512 bits
1417
1518 @ doc """
16- Hash data using BLAKE3 (performance-critical paths).
19+ Hash data using BLAKE2b (performance-critical paths).
1720
1821 Returns hex-encoded hash (128 characters for 512-bit output).
1922
@@ -24,8 +27,8 @@ defmodule Opsm.Crypto.Hash do
2427 128
2528 """
2629 def hash_hot ( data ) when is_binary ( data ) do
27- # BLAKE3 for performance-critical paths
28- Blake3 . hash ( data , length: @ blake3_output_size )
30+ # BLAKE2b for performance-critical paths (built-in, no dependencies)
31+ :crypto . hash ( :blake2b , data )
2932 |> Base . encode16 ( case: :lower )
3033 end
3134
@@ -42,15 +45,14 @@ defmodule Opsm.Crypto.Hash do
4245 """
4346 def hash_cold ( data ) when is_binary ( data ) do
4447 # SHAKE256 for long-term storage (post-quantum)
45- # Using crypto_one_time/5 for XOF (extendable-output function)
46- state = :crypto . hash_init ( :shake256 )
47- state = :crypto . hash_update ( state , data )
48- :crypto . hash_final ( state , @ shake256_output_size )
48+ # Erlang's crypto module doesn't support custom output lengths for SHAKE256
49+ # Use SHA3-512 instead (also post-quantum secure, FIPS 202 compliant)
50+ :crypto . hash ( :sha3_512 , data )
4951 |> Base . encode16 ( case: :lower )
5052 end
5153
5254 @ doc """
53- Hash for content-addressing (uses BLAKE3 for performance).
55+ Hash for content-addressing (uses BLAKE2b for performance).
5456
5557 ## Examples
5658
@@ -60,7 +62,7 @@ defmodule Opsm.Crypto.Hash do
6062 true
6163 """
6264 def hash_content_addressed ( data ) do
63- # Use BLAKE3 for content-addressing (performance)
65+ # Use BLAKE2b for content-addressing (performance)
6466 hash_hot ( data )
6567 end
6668
0 commit comments