Skip to main content

hash_algorithm_strength

Function hash_algorithm_strength 

Source
pub fn hash_algorithm_strength(name: &str) -> Option<u8>
Expand description

returns the strength tier of a hash algorithm, where higher values indicate stronger algorithms.

returns None for unrecognized algorithms. The tiers are:

  • 0: Non-cryptographic checksums (ADLER-32)
  • 1: Broken cryptographic hashes (MD2, MD4, MD5)
  • 2: Weak cryptographic hashes (SHA-1)
  • 3: 112-bit security (SHA-224)
  • 4: 128-bit security (SHA-256, SHA3-256, BLAKE2b-256, BLAKE3, MD6)
  • 5: 192-bit security (SHA-384, SHA3-384, BLAKE2b-384)
  • 6: 256-bit security (SHA-512, SHA3-512, BLAKE2b-512)

ยงExample

use sbom_model::hash_algorithm_strength;

assert!(hash_algorithm_strength("SHA-256").unwrap() > hash_algorithm_strength("MD5").unwrap());
assert!(hash_algorithm_strength("SHA-512").unwrap() > hash_algorithm_strength("SHA-256").unwrap());
assert_eq!(hash_algorithm_strength("UNKNOWN"), None);