tiran / pysha3

Backport of hashlib.sha3 for 2.7 to 3.5

Home Page:https://docs.python.org/3/library/hashlib.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alignment problem

mchabrecek opened this issue · comments

After porting python to our new platform (which forces data type alignment to their size) we have alignment problems with your library. Python3 ptests (Yocto) are failing.

The root cause seems to be in the function int SpongeAbsorb(SpongeInstance *instance, const unsigned char *data, size_t dataByteLen)
(Python-3.9.9/Modules/_sha3/kcp/KeccakSponge.inc)

In this part:

#ifdef SnP_FastLoop_Absorb
            /* processing full blocks first */

            if ((rateInBytes % (SnP_width/200)) == 0) {
                /* fast lane: whole lane rate */

                j = SnP_FastLoop_Absorb(instance->state, rateInBytes/(SnP_width/200), curData, dataByteLen - i);
                i += j;
                curData += j;
            }
            else {
#endif

curData is char pointer, ao it it goes to SnP_FastLoop_Absorb function, which is defined to KeccakF1600_FastLoop_Absorb(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen) (Python-3.9.9/Modules/_sha3/kcp/KeccakP-1600-opt64.c)

There it is re-typed to UINT64* (UINT64 inDataAsLanes = (UINT64)data;), then data are load from inDataAsLanes addres. There we got sigbus error, because compiler uses aligned load.

Can you make hint to compiler that this data can be unaligned or force the aligment?

Hi,

this project is no longer under development. It was a backport / standalone version of the _sha3 module before Python 3.6. I recommend that you build Python without the SHA-3 module (see ./configure --with-builtin-hashlib-hashes=...) and use the SHA-3 code from OpenSSL 1.1.1+.

pysha3 is no longer supported. Please use SHA-3 from Python's hashlib module.