From 02b44b3af62f094175bc695f9b4ea315b1abc578 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 3 May 2022 15:25:14 -0700 Subject: [PATCH] Switch hash algorithm from MD5 to SHA256 Even though this use of MD5 isn't for security purposes, MD5 may not be allowed at all on FIPS-compliant systems. Switch to SHA256 to comply with FIPS 140-2 standards. --- lib/stackprof/report.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stackprof/report.rb b/lib/stackprof/report.rb index 9a499a83..419630bc 100644 --- a/lib/stackprof/report.rb +++ b/lib/stackprof/report.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'pp' -require 'digest/md5' +require 'digest/sha2' require 'json' module StackProf @@ -52,7 +52,7 @@ def frames(sort_by_total=false) def normalized_frames id2hash = {} @data[:frames].each do |frame, info| - id2hash[frame.to_s] = info[:hash] = Digest::MD5.hexdigest("#{info[:name]}#{info[:file]}#{info[:line]}") + id2hash[frame.to_s] = info[:hash] = Digest::SHA256.hexdigest("#{info[:name]}#{info[:file]}#{info[:line]}") end @data[:frames].inject(Hash.new) do |hash, (frame, info)| info = hash[id2hash[frame.to_s]] = info.dup