Is calculating an MD5 hash less CPU intensive than SHA family functions?

后端 未结 6 1205
傲寒
傲寒 2020-11-28 06:48

Is calculating an MD5 hash less CPU intensive than SHA-1 or SHA-2 on \"standard\" laptop x86 hardware? I\'m interested in general information, not specific to a certain chip

6条回答
  •  情书的邮戳
    2020-11-28 07:21

    The real answer is : It depends

    There are a couple factors to consider, the most obvious are : the cpu you are running these algorithms on and the implementation of the algorithms.

    For instance, me and my friend both run the exact same openssl version and get slightly different results with different Intel Core i7 cpus.

    My test at work with an Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz

    The 'numbers' are in 1000s of bytes per second processed.
    type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
    md5              64257.97k   187370.26k   406435.07k   576544.43k   649827.67k
    sha1             73225.75k   202701.20k   432679.68k   601140.57k   679900.50k
    

    And his with an Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz

    The 'numbers' are in 1000s of bytes per second processed.
    type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
    md5              51859.12k   156255.78k   350252.00k   513141.73k   590701.52k
    sha1             56492.56k   156300.76k   328688.76k   452450.92k   508625.68k
    

    We both are running the exact same binaries of OpenSSL 1.0.1j 15 Oct 2014 from the ArchLinux official package.

    My opinion on this is that with the added security of sha1, cpu designers are more likely to improve the speed of sha1 and more programmers will be working on the algorithm's optimization than md5sum.

    I guess that md5 will no longer be used some day since it seems that it has no advantage over sha1. I also tested some cases on real files and the results were always the same in both cases (likely limited by disk I/O).

    md5sum of a large 4.6GB file took the exact same time than sha1sum of the same file, same goes with many small files (488 in the same directory). I ran the tests a dozen times and they were consitently getting the same results.

    --

    It would be very interesting to investigate this further. I guess there are some experts around that could provide a solid answer to why sha1 is getting faster than md5 on newer processors.

提交回复
热议问题