Closed noloader closed 6 years ago
Hi Jeff,
SHA256 is not used by any high-level APIs, it's not even compiled in minimal mode, which means that it will eventually be removed. So, I don't think we should add new implementations for it at this point.
SHA512 would be far more interesting. Where there are no dedicated opcodes for it, Intel provides some guidance for AVX implementations that might be worth checking out.
SHA512 would be far more interesting.
Ack. SHA-512 would be Power8 or ARMv8.4.
I have not done a Power8 SHA-512 yet. IBM has some of the worse docs on the planet and it takes me 3 times as long to cut something in. It is on my roadmap.
ARMv8.4 was announced recently; see Introducing 2017’s extensions to the Arm Architecture. There is no hardware in the field I am aware of. ARM FVP emulators provide it, but I have not jumped in yet. It is on my roadmap.
Saw that.
SHA512 will be great, but SHA3 support in ARMv8.4 is even more exciting.
Do you happen to know if all we will get is the hash function, or if they will actually expose the permutation? That would be a game changer.
This patch adds SHA-256 support using SHA extensions. It is a hack because of my lack of knowledge of libsodium. I don't know how to cut-in a new ISA or CPU feature, so I changed the SHA C code to SHA extensions for cut-in and testing. Someone more familiar with libsodium needs to take it further.
Credit should got to Sean Gulley of Intel. He wrote the article New Instructions Supporting the Secure Hash Algorithm on Intel® Architecture Processors. Later, I found his reference implementation at mitls | experimental | hash to fill in the missing pieces from the Intel blog. We deviated slightly by using unaligned loads and stores to avoid
SIGBUS
on unaligned buffers.SHA-256 will run at about 3.8 cpb using Intel extensions. SHA extensions are available on Goldmont and Goldmont+. The patch below was tested on a Celeron J3455, which is Goldmont. I purchased it specifically for testing SHA instructions. You can also test on the GCC Compile Farm. GCC67, which is the AMD Ryzen 1700x, has SHA extensions.
libsodium was configured with the following for testing. I did not feel like messing with someone else's
configure.ac
. Thanks for respecting myCFLAGS
andCXXFLAGS
. It made it very easy to test this patch. libsodium's 72 self tests pass with the patch in effect.Here is the diff shown below: sha.diff.tar.gz