RustCrypto / asm-hashes

Assembly implementations of cryptographic hash functions
46 stars 26 forks source link

sha1: Apple M1 build failures #28

Closed tarcieri closed 3 years ago

tarcieri commented 3 years ago

As discovered on #27, the aarch64 assembly for the sha1 and sha2 (edit: SHA-256 support added in #35) crates does not compile on macOS/M1:

Compiling sha2-asm v0.5.4
The following warnings were emitted during compilation:

warning: src/sha256_aarch64.S:64:2: error: ADR/ADRP relocations must be GOT relative
warning:  adrp x2, .K
warning:  ^
warning: src/sha256_aarch64.S:64:2: error: unknown AArch64 fixup kind!
warning:  adrp x2, .K
warning:  ^
warning: src/sha256_aarch64.S:65:2: error: unknown AArch64 fixup kind!
warning:  add x2, x2, :lo12:.K
warning:  ^

error: failed to run custom build command for `sha2-asm v0.5.4`
tarcieri commented 3 years ago

I wonder if we could cross-compile to aarch64 on a (x86) macOS CI instance to test this...

lonnylot commented 3 years ago

I'm currently trying to install fil-ocl-core and this seems to be throwing an error.

Any update on this or any way I could help make progress?

tarcieri commented 3 years ago

@lonnylot for now the asm is incompatible with macOS/M4. If fil-ocl-core is enabling it, they should probably gate it on e.g. Linux/ARM64 targets

tarcieri commented 3 years ago

Note that overall I think the best way forward here on the M1 is to use stdarch to leverage the ARMv8 Cryptography Extensions, although unfortunately due to a recent regression the necessary intrinsics are no longer exposed

Byron commented 3 years ago

The related issue is now this one and a PR is in the making to clean it up. I am hoping that this will provide the required intrinsics to eventually get fast SHA1 on M1's.

tarcieri commented 3 years ago

FWIW, here is the assembly generated by a Rust wrapper for the ARMv8 Cryptography Extensions:

https://godbolt.org/z/P8oje3EfK

See also my comment here:

https://github.com/RustCrypto/asm-hashes/issues/5#issuecomment-812890980

tarcieri commented 3 years ago

I opened a tracking issue for stdarch-based intrinsic implementations of hash functions here, which is probably the best way to tackle this particular problem: https://github.com/RustCrypto/hashes/issues/257

dignifiedquire commented 3 years ago

Given that the intrinsic solution is still a little out there, could we add a second aarch64 implementation for M1 here?

tarcieri commented 3 years ago

Yeah, that's why I provided the assembly output above, unless someone knows of something better for this purpose.