1

This year AMD has released a new series of x86-64 CPUs named RyZen for desktop. RyZen's specification shows it provides new SSE based SHA1 and SHA-256 instructions wiki: Intel SHA extension:

  • sha1 instructions: SHA1RNDS4, SHA1NEXTE, SHA1MSG1, SHA1MSG2;
  • sha-256 instructions: SHA256RNDS2, SHA256MSG1, SHA256MSG2

I am curious, Do any of the APIs/Libraries already exist that are able to laverage these instruction for ultra fast hashing to be used in PHP or other server side languages, when you use AMD RyZen CPU ? If not, when should we expect it to be available ?

Since Intel has provided specification for hardware SHA around year 2013, it seems at least a couple of compilers must have provied support for it.

falero80s
  • 368
  • 6
  • 12
  • 1
    You may try search of the instruction names (from wiki like `sha256msg1` or in _mm form "`_mm_sha256msg1_epu32`" from `shaintrin.h` or `__builtin_ia32_sha256msg1`) in popular repository like github (or in internet) and exclude gcc/llvm/compiler tests. SHA256 extension support was added into openssl (https://github.com/openssl/openssl/blob/master/crypto/sha/asm/sha256-mb-x86_64.pl), so any php/c lib using openssl for sha256 will benefit from hardware acceleration with recent enough openssl and recent CPU. – osgx May 31 '17 at 19:34

1 Answers1

3

Support of hardware-accelerated SHA256 was added to openssl 1.0.2 [22 Jan 2015]: https://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=CHANGES

1962  Changes between 1.0.1l and 1.0.2 [22 Jan 2015]

2012   *) Support for new and upcoming Intel processors, including AVX2,
2013      BMI and SHA ISA extensions. This includes additional "stitched"
2014      implementations, AESNI-SHA256 and GCM, and multi-buffer support
2015      for TLS encrypt.

So, with enabled hardware and recent openssl, any php/python library which uses openssl to compute SHA256 may use hardware accelerated SHA256 digest computation (if enabled in the openssl and if this implementation will be selected by the library). And command-line too: openssl dgst -sha256 -binary file_to_be_hashed.

There are some raw bindings of openssl library in php: http://php.net/manual/en/function.openssl-digest.php and OPENSSL_ALGO_SHA256 is there since PHP 5.5: which openssl version support for sha256 in php

Linux Kernel CryptoAPI may use hardware SHA1/SHA2 since 4.4 version: https://www.phoronix.com/scan.php?page=news_item&px=Linux-4.4-Crypto (http://lkml.iu.edu/hypermail/linux/kernel/1511.0/00383.html); but it is unlikely that PHP/other scripting library will use kernel cryptoapi.

osgx
  • 90,338
  • 53
  • 357
  • 513
  • 1
    You can profile any SHA256-heavy computing code (in linux - with `perf record -e cycles:u ./program; perf report`) and check which instructions were used inside sha1/sha256 computing functions. – osgx May 31 '17 at 19:45
  • Thanks for the openssl link, this is very informative. – falero80s May 31 '17 at 20:03