rustcrypto / asm-hashes Goto Github PK
View Code? Open in Web Editor NEWAssembly implementations of cryptographic hash functions
Assembly implementations of cryptographic hash functions
env: Windows 10 x86_64, Rust nightly-gnu [rustc 1.55.0-nightly (539d7bd39 2021-06-14)]
❯ cargo +nightly-gnu bench -vvv
Fresh cc v1.0.61
Fresh md5-asm v0.5.0 (C:\workspace\repos\github.com\RustCrypto\asm-hashes\md5)
Finished bench [optimized] target(s) in 0.04s
Running `C:\workspace\repos\github.com\RustCrypto\asm-hashes\target\release\deps\md5_asm-4aede987d9726e5b.exe --bench`
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running `C:\workspace\repos\github.com\RustCrypto\asm-hashes\target\release\deps\lib-dab98c6ec0ebcfb5.exe --bench`
running 1 test
error: bench failed
How can I fix this?
Output of cargo run --release
in a project using md5-asm via md-5:
Compiling md5-asm v0.4.3
The following warnings were emitted during compilation:
warning: cl : Command line warning D9024 : unrecognized source file type 'src/x64.S', object file assumed
warning: cl : Command line warning D9027 : source file 'src/x64.S' ignored
error: failed to run custom build command for `md5-asm v0.4.3`
Caused by:
process didn't exit successfully: `K:\Code\project\target\release\build\md5-asm-2f85d6e6f786c14b\build-script-build` (exit code: 1)
--- stdout
TARGET = Some("x86_64-pc-windows-msvc")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-msvc")
CC_x86_64-pc-windows-msvc = None
CC_x86_64_pc_windows_msvc = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-msvc = None
CFLAGS_x86_64_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
DEBUG = Some("false")
running: "K:\\Code\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-O2" "-Brepro" "-W4" "-c" "-FoK:\\Code\\project\\target\\release\\build\\md5-asm-86902935336c4579\\out\\src/x64.o" "-c" "src/x64.S"
cargo:warning=cl : Command line warning D9024 : unrecognized source file type 'src/x64.S', object file assumed
cargo:warning=cl : Command line warning D9027 : source file 'src/x64.S' ignored
cl : Command line warning D9021 : no action performed
exit code: 0
AR_x86_64-pc-windows-msvc = None
AR_x86_64_pc_windows_msvc = None
HOST_AR = None
AR = None
running: "K:\\Code\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX64\\x64\\lib.exe" "-out:K:\\Code\\project\\target\\release\\build\\md5-asm-86902935336c4579\\out\\libmd5.a" "-nologo" "K:\\Code\\project\\target\\release\\build\\md5-asm-86902935336c4579\\out\\src/x64.o"
LINK : fatal error LNK1181: cannot open input file 'K:\Code\project\target\release\build\md5-asm-86902935336c4579\out\src\x64.o'
exit code: 1181
--- stderr
error occurred: Command "K:\\Code\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX64\\x64\\lib.exe" "-out:K:\\Code\\project\\target\\release\\build\\md5-asm-86902935336c4579\\out\\libmd5.a" "-nologo" "K:\\Code\\project\\target\\release\\build\\md5-asm-86902935336c4579\\out\\src/x64.o" with args "lib.exe" did not execute successfully (status code exit code: 1181).
Based on the .S files I don't think this project intends to support Windows. In that case it'd be nice if the project just gave a compile error saying Windows isn't supported rather than a confusing MSVC failure log.
Hello,
While building https://github.com/filecoin-project/lotus on s390x platform on a Big Endian architecture, saw an error message filecoin-project/lotus#1779 and I followed the suggestions to build libfilcrypto.so
from the source.
While doing so, the build failed because it was depending on asm-hashes
and it did not have support for s390x
platform.
To get going, we have generated .S based on the https://www.nayuki.io/res/fast-sha2-hashes-in-x86-assembly/sha256.c for example. This got us going with building libfilcrypto
for s390x
. However, not sure if this is the right thing to do since we could have used .c file directly anyway.
Would you have any plans on providing an implementation for s390x ?
With the forthcoming release of Rust 1.59 at the end of February, which stabilizes inline assembly, I think it's time to start planning on eventually retiring this repo and migrating to inline assembly instead.
This should simplify a number of things like linking, testing, and overall crate/repo structure.
thread 'main' has overflowed its stack
md-5 = { version = "0.10.5", features = ["oid", "asm"] }
[env]
CC = "clang"
clang version 16.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
use ::md5::{Digest, Md5};
fn main() {
println!("start md5");
let mut m5: Md5 = Md5::new();
m5.update(
b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
);
println!("{:x}", m5.finalize())
}
Apologies, I'm unsure if this is specifically an issue with hashes
or maybe has something to do with an interaction with cross
, but when I attempt to cross-compile to aarch64-unknown-linux-gnu
it seems to chose invalid assembly instructions.
Part of the output of:
Compiling sha1-asm v0.4.4
The following warnings were emitted during compilation:
warning: src/x64.S: Assembler messages:
warning: src/x64.S:111: Error: unknown mnemonic `movq' -- `movq %rbx,%xmm0'
warning: src/x64.S:112: Error: unknown mnemonic `movq' -- `movq %rbp,%xmm1'
warning: src/x64.S:113: Error: unknown mnemonic `subq' -- `subq $64,%rsp'
warning: src/x64.S:116: Error: unknown mnemonic `movq' -- `movq %rdi,%r8'
warning: src/x64.S:117: Error: unknown mnemonic `movl' -- `movl 0(%rdi),%eax'
warning: src/x64.S:118: Error: unknown mnemonic `movl' -- `movl 4(%rdi),%ebx'
warning: src/x64.S:119: Error: unknown mnemonic `movl' -- `movl 8(%rdi),%ecx'
warning: src/x64.S:120: Error: unknown mnemonic `movl' -- `movl 12(%rdi),%edx'
warning: src/x64.S:121: Error: unknown mnemonic `movl' -- `movl 16(%rdi),%ebp'
warning: src/x64.S:122: Error: unknown mnemonic `movq' -- `movq %rsi,%rdi'
See full output here along with Cargo.toml and src/main.rs here: https://gist.github.com/jszwedko/9d0cfb8db04fdeffb83cae1f1e2acec4
Ran into a build failure of starship over in msys2/MINGW-packages#17831. It seems to me that sha1/src/x86.S needs to prefix the symbol with _
on Windows as it does for Apple. This would at least fix the build error.
_
for i686 Windows.def _sha1_compress; .scl 2; .type 32; .endef
I plan to open a pull request with these changes, once I figure out how to test them (insights into this would be appreciated). I also want to test aarch64-pc-windows-gnullvm target, as I bet nobody has tried this yet.
KeccakCodePackage provides optimized assembly for various platform, which will allow us to get significant speed-up for algorithms based on Keccak functions.
Currently, the software implementation of sha256 suffers from a performance bug in code generation on RISC-V targets. Additionally, I think that a target-specific implementation has a lot of potential for improvement compared to the current generic implementation. (The generic implementation has a lot of manual loop unrolling and is primed for compiler autovectorization. RISC-V does not profit from these, as vector operations are still WIP. I suspect that a simpler implementation would have less register pressure and thus better performance, in addition to smaller code)
Initially crates in this repository were a simple proof-of-work experiment and assembly from Project Nayuki was taken without much consideration to performance. But some people use asm
feature and expect performance on par with OpenSSL which is obviously not true today.
So I think we should migrate to OpenSSL assembly and maybe rename this repository to openssl-asm or something. This will require some code refactoring as OpenSSL hash assembly processes several blocks at a time and for the best performance we will have to accommodate for it. My initial experiments with MD5 haven't found any difficult problems.
The main question I currently have is: should we pack Perl scripts into crates or generated assembly? First option will result in a lighter crates (especially considering various possible "flavors" which Perl scripts support), but will require Perl to be installed on the system. For Linux it's not a big deal, but I think for Windows it can be a problem.
It will allow us to prevent hasher state from spilling to memory after processing each block (e.g. by encoding tight loop inside assembly).
Hello,
I tried to cross compile the sha2
crate for aarch64-linux-android
as a dependency of sha2
. This failes because the build.rs uses target_arch
which is the host machine the build.rs
is built on in order to be run during the build process. I don't know how to check to the actual target in a build.rs
Here's a suggestion but open: rust-lang/cargo#4932
For now I sadly kind of forked and patched but I'm happy to implement a suggestion and test...
cheers,
The new Intel Skylake architecture introduces SHA1 and SHA2 specific instructions that should speed up computation of these two primitives:
https://software.intel.com/en-us/articles/intel-sha-extensions
There is sample code in C for these that uses intrinsics to do this:
https://github.com/noloader/SHA-Intrinsics
It would be great to have an implementation of these in this library so that we can have blazingly fast hash functions.
As discovered on #27, the aarch64
assembly for the sha1
and (edit: SHA-256 support added in #35) crates does not compile on macOS/M1:sha2
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`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.