HMAC 的 OpenSSL 速度命令

OpenSSL speed command for HMAC

OpenSSL 提供了 convenient command 基准算法。

据我了解,它只允许基准测试加密和哈希函数。有没有办法从命令行对 HMAC 进行基准测试(比如 hmac-sha256)?

hmac(md5)md5 的结果非常相似。

所以我想要进行基准测试 hmac(sha256) 你只需要获取 sha256 哈希函数的结果。

  % openssl speed hmac md5 sha256 sha512
  Doing md5 for 3s on 16 size blocks: 13715628 md5's in 2.99s
  Doing md5 for 3s on 64 size blocks: 10361234 md5's in 2.99s
  Doing md5 for 3s on 256 size blocks: 5689195 md5's in 2.99s
  Doing md5 for 3s on 1024 size blocks: 1990236 md5's in 2.99s
  Doing md5 for 3s on 8192 size blocks: 293475 md5's in 2.99s
  Doing hmac(md5) for 3s on 16 size blocks: 13368283 hmac(md5)'s in 2.99s
  Doing hmac(md5) for 3s on 64 size blocks: 9924043 hmac(md5)'s in 2.99s
  Doing hmac(md5) for 3s on 256 size blocks: 5593989 hmac(md5)'s in 2.99s
  Doing hmac(md5) for 3s on 1024 size blocks: 1964644 hmac(md5)'s in 2.99s
  Doing hmac(md5) for 3s on 8192 size blocks: 292363 hmac(md5)'s in 2.99s
  Doing sha256 for 3s on 16 size blocks: 14201213 sha256's in 2.99s
  Doing sha256 for 3s on 64 size blocks: 7570892 sha256's in 2.99s
  Doing sha256 for 3s on 256 size blocks: 3138350 sha256's in 2.99s
  Doing sha256 for 3s on 1024 size blocks: 939177 sha256's in 2.99s
  Doing sha256 for 3s on 8192 size blocks: 126911 sha256's in 2.99s
  Doing sha512 for 3s on 16 size blocks: 11391648 sha512's in 2.99s
  Doing sha512 for 3s on 64 size blocks: 11011678 sha512's in 2.98s
  Doing sha512 for 3s on 256 size blocks: 3895326 sha512's in 2.98s
  Doing sha512 for 3s on 1024 size blocks: 1303197 sha512's in 2.98s
  Doing sha512 for 3s on 8192 size blocks: 189750 sha512's in 2.98s
  LibreSSL 2.8.3
  built on: date not available
  options:bn(64,64) rc4(16x,int) des(idx,cisc,16,int) aes(partial) blowfish(idx) 
  compiler: information not available
  The 'numbers' are in 1000s of bytes per second processed.
  type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
  md5              73410.89k   221714.56k   486819.65k   681496.50k   803485.66k
  hmac(md5)        71518.45k   212298.15k   478869.83k   672032.15k   800279.37k
  sha256           75974.89k   162043.05k   268412.75k   321679.74k   347906.04k
  sha512           60963.26k   236450.99k   335184.41k   447599.24k   521495.30k

发布更新的答案,因为我自己正在看这个!

从 OpenSSL 3.0.0 the speed utility 已更新为包含 -hmac 选项,因此您可以使用选择的摘要对 hmac 进行基准测试:

% openssl speed -hmac sha256
Doing hmac(sha256) for 3s on 16 size blocks: 8128050 hmac(sha256)'s in 2.99s
Doing hmac(sha256) for 3s on 64 size blocks: 6008552 hmac(sha256)'s in 2.99s
Doing hmac(sha256) for 3s on 256 size blocks: 3546506 hmac(sha256)'s in 2.99s
Doing hmac(sha256) for 3s on 1024 size blocks: 1278147 hmac(sha256)'s in 2.99s
Doing hmac(sha256) for 3s on 8192 size blocks: 192561 hmac(sha256)'s in 2.99s
Doing hmac(sha256) for 3s on 16384 size blocks: 96923 hmac(sha256)'s in 2.99s
version: 3.0.0-beta2
built on: built on: Mon Aug  2 17:30:29 2021 UTC
options:bn(64,64)
compiler: clang -fPIC -pthread -m64 -Wa,--noexecstack -Qunused-arguments -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
CPUINFO: ...
The 'numbers' are in 1000s of bytes per second processed.
type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes  16384 bytes
hmac(sha256)     43494.58k   128611.15k   303647.34k   437733.29k   527578.50k   531099.14k