Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

How to calculate SHA for unsigned int instead of string with ippcp

Sapir_R_Intel
Employee
426 Views

I am trying to calculate SHA256 and SHA384 for message of type unsigned integer, but from the Intel® Integrated Performance
Primitives Cryptography Developer Reference I see that all the relevant functions receive only pointer to octet string (Ipp8u*) as message.

How can I use it with pointer to unsigned int message (Ipp32u and Ipp64u)?

Thanks

0 Kudos
2 Replies
Alice_H_Intel
Employee
426 Views

Hello,

Thanks for your question. I will investigate it and get back to you soon.

Thanks,

Alice

0 Kudos
Yuriy_N_Intel
Employee
426 Views

Hello!

Actually, Ipp32u is just 4 bytes or 4 Ipp8u and all that we need to do is to represent Ipp32u as an array of Ipp8u elements and pass it to the hashing method.

This can be done in two ways:

1) Manually convert Ipp32u to 4 Ipp8u to ensure consistent endianness across all available architectures

For example, Ipp32u to 4 Ipp8u BigEndian conversion (8, 16, 24 are bits offsets):

BigEndian.png

2) Rely on existing endianness. This way is less portable, but much easier:

Simply create an Ipp8u pointer and set it to Ipp32u address - Ipp8u* ptr = (Ipp8u*)&ipp32uVariable (length = 4)

 

To hash an array of Ipp32u's, each of them should be converted with method #1 or reinterpreted pointer on the beginning can be used: Ipp8u* ptr = (Ipp8u*)sourceIpp32uArray. Resulting array will have x4 length.

Also, you can check endianness at compilation time and use faster and easier #2 or #1 depending on the detected value.

Best regards,

Yuriy

0 Kudos
Reply