intel / intel-ipsec-mb

Intel(R) Multi-Buffer Crypto for IPSec
BSD 3-Clause "New" or "Revised" License
288 stars 87 forks source link

Generic SHA one block initializes digest #86

Closed edtubbs closed 3 years ago

edtubbs commented 3 years ago

https://github.com/intel/intel-ipsec-mb/blob/857ba1c0ec32088bfe7413de9da69fb3494a6692/lib/include/sha_generic.h#L311

This call overwrites any digest passed by reference by the caller of the function. Suggest removal to support references of an initial digest.

tkanteck commented 3 years ago

This SHA API usage is limited to a few use case and this is why digest is always initialized. Would multi-buffer SHA implementation with asynchronous API fit into dogecoin application? It is lot faster than the single buffer one.

edtubbs commented 3 years ago

@tkanteck “_oneblock” inline functions fit into the dogecoin mainnet fairly easily with this change. Are the “_ONE_BLOCK” functions (link below) the equivalent in the asynchronous API you’d recommend? What are the trade offs in terms of performance for a use case involving only single block transforms. https://github.com/intel/intel-ipsec-mb/blob/857ba1c0ec32088bfe7413de9da69fb3494a6692/lib/intel-ipsec-mb.h#L1254 https://github.com/intel/intel-ipsec-mb/blob/857ba1c0ec32088bfe7413de9da69fb3494a6692/lib/intel-ipsec-mb.h#L1221

tkanteck commented 3 years ago

Thanks Ed

Did you consider using openssl SHA API? Not that I want to divert you away from intel-ipsec-mb but the single buffer SHA compute part is not fully optimized in our library. We mainly use it for key reduction where performance is not critical.

OpenSSL has pretty well optimized SHA single buffer implementations and it will also take advantage of SHANI extension. We don't leverage this extension under this API

HMAC-SHA compute is highly optimized in intel-ipsec-mb. This is multi-buffer implementation and it requires multiple independent buffers to operate on at the same time (wrapped under asynchronous API).

edtubbs commented 3 years ago

Thanks Tomasz. I think I will try openssl SHA1. I am interested in the HMAC and SHA quad/dual implementations in intel-ipsec-mb, are they all highly optimized as well?

https://github.com/intel/intel-ipsec-mb/blob/857ba1c0ec32088bfe7413de9da69fb3494a6692/lib/sse/sha1_mult_sse.asm https://github.com/intel/intel-ipsec-mb/blob/857ba1c0ec32088bfe7413de9da69fb3494a6692/lib/sse/sha_256_mult_sse.asm https://github.com/intel/intel-ipsec-mb/blob/857ba1c0ec32088bfe7413de9da69fb3494a6692/lib/sse/sha512_x2_sse.asm

tkanteck commented 3 years ago

Thanks. I think openssl may be a better fit for dogecoin application.

Yep, the links point to multi-buffer SHA implementations for SSE architecture that are used under HMAC scheduler.

Plus the SHANI implementations for SHA1 and SHA256: https://github.com/intel/intel-ipsec-mb/blob/master/lib/sse/sha1_ni_x2_sse.asm https://github.com/intel/intel-ipsec-mb/blob/master/lib/sse/sha256_ni_x2_sse.asm

edtubbs commented 3 years ago

I think I agree; not all chipsets support the SHA (NI) extension though, right? Multi buffer implementations of SHA transforms that use streaming and/or vector instructions seem ideal.

tkanteck commented 3 years ago

This is correct but multi-buffer implementation may require changes to application software to work with asynchronous API (or at least group the operations).

OpenSSL seems like best fit for dogecoin without making substantial changes in this application to enable work with async API.

Let me close this issue. Feel free to come back if OpenSSL efforts are not successful.