md5-asm-0.5.0/.cargo_vcs_info.json0000644000000001120000000000000122720ustar { "git": { "sha1": "7e1e966f6d457897186318c770ddc56b152bdda2" } } md5-asm-0.5.0/Cargo.toml0000644000000016310000000000000102770ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "md5-asm" version = "0.5.0" authors = ["RustCrypto Developers"] description = "Assembly implementation of MD5 compression function" documentation = "https://docs.rs/md5-asm" keywords = ["crypto", "md5", "asm"] categories = ["cryptography", "no-std"] license = "MIT" repository = "https://github.com/RustCrypto/asm-hashes" [build-dependencies.cc] version = "1.0" md5-asm-0.5.0/Cargo.toml.orig000064400000000000000000000006050000000000000137360ustar 00000000000000[package] name = "md5-asm" version = "0.5.0" authors = ["RustCrypto Developers"] license = "MIT" description = "Assembly implementation of MD5 compression function" documentation = "https://docs.rs/md5-asm" repository = "https://github.com/RustCrypto/asm-hashes" keywords = ["crypto", "md5", "asm"] categories = ["cryptography", "no-std"] edition = "2018" [build-dependencies] cc = "1.0" md5-asm-0.5.0/LICENSE000064400000000000000000000021030000000000000120470ustar 00000000000000Copyright (c) 2016 Project Nayuki Copyright (c) 2017 Artyom Pavlov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. md5-asm-0.5.0/benches/lib.rs000064400000000000000000000004410000000000000135700ustar 00000000000000#![no_std] #![feature(test)] extern crate test; use test::Bencher; #[bench] fn bench_compress(b: &mut Bencher) { let mut state = Default::default(); let data = [0u8; 64]; b.iter(|| { md5_asm::compress(&mut state, &data); }); b.bytes = data.len() as u64; } md5-asm-0.5.0/build.rs000064400000000000000000000006040000000000000125130ustar 00000000000000fn main() { let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let asm_path = if target_arch == "x86" { "src/x86.S" } else if target_arch == "x86_64" { "src/x64.S" } else { panic!("Unsupported target architecture"); }; cc::Build::new() .flag("-c") .file(asm_path) .compile("libmd5.a"); } md5-asm-0.5.0/src/lib.rs000064400000000000000000000015440000000000000127550ustar 00000000000000//! Assembly implementation of the [MD5] compression function. //! //! This crate is not intended for direct use, most users should //! prefer the [`md5`] crate with enabled `asm` feature instead. //! //! Only x86 and x86-64 architectures are currently supported. //! //! [MD5]: https://en.wikipedia.org/wiki/MD5 //! [`md5`]: https://crates.io/crates/md5 #![no_std] #[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] compile_error!("crate can only be used on x86 and x86-64 architectures"); #[link(name = "md5", kind = "static")] extern "C" { fn md5_compress(state: &mut [u32; 4], block: &[u8; 64]); } /// Safe wrapper around assembly implementation of MD5 compression function #[inline] pub fn compress(state: &mut [u32; 4], blocks: &[[u8; 64]]) { for block in blocks { unsafe { md5_compress(state, block); } } } md5-asm-0.5.0/src/x64.S000064400000000000000000000161150000000000000124060ustar 00000000000000/* * MD5 hash in x86-64 assembly * * Copyright (c) 2016 Project Nayuki. (MIT License) * https://www.nayuki.io/page/fast-md5-hash-implementation-in-x86-assembly * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * - The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * - The Software is provided "as is", without warranty of any kind, express or * implied, including but not limited to the warranties of merchantability, * fitness for a particular purpose and noninfringement. In no event shall the * authors or copyright holders be liable for any claim, damages or other * liability, whether in an action of contract, tort or otherwise, arising from, * out of or in connection with the Software or the use or other dealings in the * Software. */ /* void md5_compress(uint32_t state[4], const uint8_t block[64]) */ #ifdef __APPLE__ .globl _md5_compress _md5_compress: #else .globl md5_compress md5_compress: #endif /* * Storage usage: * Bytes Location Description * 4 eax MD5 state variable A * 4 ebx MD5 state variable B * 4 ecx MD5 state variable C * 4 edx MD5 state variable D * 4 esi Temporary for calculation per round * 4 edi Temporary for calculation per round * 8 rbp Base address of block array argument (read-only) * 8 r8 Base address of state array argument (read-only) * 16 xmm0 Caller's value of rbx (only low 64 bits are used) * 16 xmm1 Caller's value of rbp (only low 64 bits are used) */ #define ROUND0(a, b, c, d, k, s, t) \ movl %c, %esi; \ addl (k*4)(%rbp), %a; \ xorl %d, %esi; \ andl %b, %esi; \ xorl %d, %esi; \ leal t(%esi,%a), %a; \ roll $s, %a; \ addl %b, %a; #define ROUND1(a, b, c, d, k, s, t) \ movl %d, %esi; \ movl %d, %edi; \ addl (k*4)(%rbp), %a; \ notl %esi; \ andl %b, %edi; \ andl %c, %esi; \ orl %edi, %esi; \ leal t(%esi,%a), %a; \ roll $s, %a; \ addl %b, %a; #define ROUND2(a, b, c, d, k, s, t) \ movl %c, %esi; \ addl (k*4)(%rbp), %a; \ xorl %d, %esi; \ xorl %b, %esi; \ leal t(%esi,%a), %a; \ roll $s, %a; \ addl %b, %a; #define ROUND3(a, b, c, d, k, s, t) \ movl %d, %esi; \ not %esi; \ addl (k*4)(%rbp), %a; \ orl %b, %esi; \ xorl %c, %esi; \ leal t(%esi,%a), %a; \ roll $s, %a; \ addl %b, %a; /* Save registers */ movq %rbx, %xmm0 movq %rbp, %xmm1 /* Load arguments */ movq %rsi, %rbp movl 0(%rdi), %eax /* a */ movl 4(%rdi), %ebx /* b */ movl 8(%rdi), %ecx /* c */ movl 12(%rdi), %edx /* d */ movq %rdi, %r8 /* 64 rounds of hashing */ ROUND0(eax, ebx, ecx, edx, 0, 7, -0x28955B88) ROUND0(edx, eax, ebx, ecx, 1, 12, -0x173848AA) ROUND0(ecx, edx, eax, ebx, 2, 17, 0x242070DB) ROUND0(ebx, ecx, edx, eax, 3, 22, -0x3E423112) ROUND0(eax, ebx, ecx, edx, 4, 7, -0x0A83F051) ROUND0(edx, eax, ebx, ecx, 5, 12, 0x4787C62A) ROUND0(ecx, edx, eax, ebx, 6, 17, -0x57CFB9ED) ROUND0(ebx, ecx, edx, eax, 7, 22, -0x02B96AFF) ROUND0(eax, ebx, ecx, edx, 8, 7, 0x698098D8) ROUND0(edx, eax, ebx, ecx, 9, 12, -0x74BB0851) ROUND0(ecx, edx, eax, ebx, 10, 17, -0x0000A44F) ROUND0(ebx, ecx, edx, eax, 11, 22, -0x76A32842) ROUND0(eax, ebx, ecx, edx, 12, 7, 0x6B901122) ROUND0(edx, eax, ebx, ecx, 13, 12, -0x02678E6D) ROUND0(ecx, edx, eax, ebx, 14, 17, -0x5986BC72) ROUND0(ebx, ecx, edx, eax, 15, 22, 0x49B40821) ROUND1(eax, ebx, ecx, edx, 1, 5, -0x09E1DA9E) ROUND1(edx, eax, ebx, ecx, 6, 9, -0x3FBF4CC0) ROUND1(ecx, edx, eax, ebx, 11, 14, 0x265E5A51) ROUND1(ebx, ecx, edx, eax, 0, 20, -0x16493856) ROUND1(eax, ebx, ecx, edx, 5, 5, -0x29D0EFA3) ROUND1(edx, eax, ebx, ecx, 10, 9, 0x02441453) ROUND1(ecx, edx, eax, ebx, 15, 14, -0x275E197F) ROUND1(ebx, ecx, edx, eax, 4, 20, -0x182C0438) ROUND1(eax, ebx, ecx, edx, 9, 5, 0x21E1CDE6) ROUND1(edx, eax, ebx, ecx, 14, 9, -0x3CC8F82A) ROUND1(ecx, edx, eax, ebx, 3, 14, -0x0B2AF279) ROUND1(ebx, ecx, edx, eax, 8, 20, 0x455A14ED) ROUND1(eax, ebx, ecx, edx, 13, 5, -0x561C16FB) ROUND1(edx, eax, ebx, ecx, 2, 9, -0x03105C08) ROUND1(ecx, edx, eax, ebx, 7, 14, 0x676F02D9) ROUND1(ebx, ecx, edx, eax, 12, 20, -0x72D5B376) ROUND2(eax, ebx, ecx, edx, 5, 4, -0x0005C6BE) ROUND2(edx, eax, ebx, ecx, 8, 11, -0x788E097F) ROUND2(ecx, edx, eax, ebx, 11, 16, 0x6D9D6122) ROUND2(ebx, ecx, edx, eax, 14, 23, -0x021AC7F4) ROUND2(eax, ebx, ecx, edx, 1, 4, -0x5B4115BC) ROUND2(edx, eax, ebx, ecx, 4, 11, 0x4BDECFA9) ROUND2(ecx, edx, eax, ebx, 7, 16, -0x0944B4A0) ROUND2(ebx, ecx, edx, eax, 10, 23, -0x41404390) ROUND2(eax, ebx, ecx, edx, 13, 4, 0x289B7EC6) ROUND2(edx, eax, ebx, ecx, 0, 11, -0x155ED806) ROUND2(ecx, edx, eax, ebx, 3, 16, -0x2B10CF7B) ROUND2(ebx, ecx, edx, eax, 6, 23, 0x04881D05) ROUND2(eax, ebx, ecx, edx, 9, 4, -0x262B2FC7) ROUND2(edx, eax, ebx, ecx, 12, 11, -0x1924661B) ROUND2(ecx, edx, eax, ebx, 15, 16, 0x1FA27CF8) ROUND2(ebx, ecx, edx, eax, 2, 23, -0x3B53A99B) ROUND3(eax, ebx, ecx, edx, 0, 6, -0x0BD6DDBC) ROUND3(edx, eax, ebx, ecx, 7, 10, 0x432AFF97) ROUND3(ecx, edx, eax, ebx, 14, 15, -0x546BDC59) ROUND3(ebx, ecx, edx, eax, 5, 21, -0x036C5FC7) ROUND3(eax, ebx, ecx, edx, 12, 6, 0x655B59C3) ROUND3(edx, eax, ebx, ecx, 3, 10, -0x70F3336E) ROUND3(ecx, edx, eax, ebx, 10, 15, -0x00100B83) ROUND3(ebx, ecx, edx, eax, 1, 21, -0x7A7BA22F) ROUND3(eax, ebx, ecx, edx, 8, 6, 0x6FA87E4F) ROUND3(edx, eax, ebx, ecx, 15, 10, -0x01D31920) ROUND3(ecx, edx, eax, ebx, 6, 15, -0x5CFEBCEC) ROUND3(ebx, ecx, edx, eax, 13, 21, 0x4E0811A1) ROUND3(eax, ebx, ecx, edx, 4, 6, -0x08AC817E) ROUND3(edx, eax, ebx, ecx, 11, 10, -0x42C50DCB) ROUND3(ecx, edx, eax, ebx, 2, 15, 0x2AD7D2BB) ROUND3(ebx, ecx, edx, eax, 9, 21, -0x14792C6F) /* Save updated state */ addl %eax, 0(%r8) addl %ebx, 4(%r8) addl %ecx, 8(%r8) addl %edx, 12(%r8) /* Restore registers */ movq %xmm0, %rbx movq %xmm1, %rbp retq md5-asm-0.5.0/src/x86.S000064400000000000000000000163530000000000000124160ustar 00000000000000/* * MD5 hash in x86 assembly * * Copyright (c) 2016 Project Nayuki. (MIT License) * https://www.nayuki.io/page/fast-md5-hash-implementation-in-x86-assembly * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * - The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * - The Software is provided "as is", without warranty of any kind, express or * implied, including but not limited to the warranties of merchantability, * fitness for a particular purpose and noninfringement. In no event shall the * authors or copyright holders be liable for any claim, damages or other * liability, whether in an action of contract, tort or otherwise, arising from, * out of or in connection with the Software or the use or other dealings in the * Software. */ /* void md5_compress(uint32_t state[4], const uint8_t block[64]) */ #ifdef __APPLE__ .globl _md5_compress _md5_compress: #else .globl md5_compress md5_compress: #endif /* * Storage usage: * Bytes Location Description * 4 eax MD5 state variable A * 4 ebx MD5 state variable B * 4 ecx MD5 state variable C * 4 edx MD5 state variable D * 4 esi Temporary for calculation per round * 4 edi Temporary for calculation per round * 4 ebp Base address of block array argument (read-only) * 4 esp x86 stack pointer * 4 [esp+ 0] Caller's value of ebx * 4 [esp+ 4] Caller's value of esi * 4 [esp+ 8] Caller's value of edi * 4 [esp+12] Caller's value of ebp */ #define ROUND0(a, b, c, d, k, s, t) \ movl %c, %esi; \ addl (k*4)(%ebp), %a; \ xorl %d, %esi; \ andl %b, %esi; \ xorl %d, %esi; \ leal t(%esi,%a), %a; \ roll $s, %a; \ addl %b, %a; #define ROUND1(a, b, c, d, k, s, t) \ movl %d, %esi; \ movl %d, %edi; \ addl (k*4)(%ebp), %a; \ notl %esi; \ andl %b, %edi; \ andl %c, %esi; \ orl %edi, %esi; \ leal t(%esi,%a), %a; \ roll $s, %a; \ addl %b, %a; #define ROUND2(a, b, c, d, k, s, t) \ movl %c, %esi; \ addl (k*4)(%ebp), %a; \ xorl %d, %esi; \ xorl %b, %esi; \ leal t(%esi,%a), %a; \ roll $s, %a; \ addl %b, %a; #define ROUND3(a, b, c, d, k, s, t) \ movl %d, %esi; \ not %esi; \ addl (k*4)(%ebp), %a; \ orl %b, %esi; \ xorl %c, %esi; \ leal t(%esi,%a), %a; \ roll $s, %a; \ addl %b, %a; /* Save registers */ subl $16, %esp movl %ebx, 0(%esp) movl %esi, 4(%esp) movl %edi, 8(%esp) movl %ebp, 12(%esp) /* Load arguments */ movl 20(%esp), %esi /* state */ movl 24(%esp), %ebp /* block */ movl 0(%esi), %eax /* a */ movl 4(%esi), %ebx /* b */ movl 8(%esi), %ecx /* c */ movl 12(%esi), %edx /* d */ /* 64 rounds of hashing */ ROUND0(eax, ebx, ecx, edx, 0, 7, 0xD76AA478) ROUND0(edx, eax, ebx, ecx, 1, 12, 0xE8C7B756) ROUND0(ecx, edx, eax, ebx, 2, 17, 0x242070DB) ROUND0(ebx, ecx, edx, eax, 3, 22, 0xC1BDCEEE) ROUND0(eax, ebx, ecx, edx, 4, 7, 0xF57C0FAF) ROUND0(edx, eax, ebx, ecx, 5, 12, 0x4787C62A) ROUND0(ecx, edx, eax, ebx, 6, 17, 0xA8304613) ROUND0(ebx, ecx, edx, eax, 7, 22, 0xFD469501) ROUND0(eax, ebx, ecx, edx, 8, 7, 0x698098D8) ROUND0(edx, eax, ebx, ecx, 9, 12, 0x8B44F7AF) ROUND0(ecx, edx, eax, ebx, 10, 17, 0xFFFF5BB1) ROUND0(ebx, ecx, edx, eax, 11, 22, 0x895CD7BE) ROUND0(eax, ebx, ecx, edx, 12, 7, 0x6B901122) ROUND0(edx, eax, ebx, ecx, 13, 12, 0xFD987193) ROUND0(ecx, edx, eax, ebx, 14, 17, 0xA679438E) ROUND0(ebx, ecx, edx, eax, 15, 22, 0x49B40821) ROUND1(eax, ebx, ecx, edx, 1, 5, 0xF61E2562) ROUND1(edx, eax, ebx, ecx, 6, 9, 0xC040B340) ROUND1(ecx, edx, eax, ebx, 11, 14, 0x265E5A51) ROUND1(ebx, ecx, edx, eax, 0, 20, 0xE9B6C7AA) ROUND1(eax, ebx, ecx, edx, 5, 5, 0xD62F105D) ROUND1(edx, eax, ebx, ecx, 10, 9, 0x02441453) ROUND1(ecx, edx, eax, ebx, 15, 14, 0xD8A1E681) ROUND1(ebx, ecx, edx, eax, 4, 20, 0xE7D3FBC8) ROUND1(eax, ebx, ecx, edx, 9, 5, 0x21E1CDE6) ROUND1(edx, eax, ebx, ecx, 14, 9, 0xC33707D6) ROUND1(ecx, edx, eax, ebx, 3, 14, 0xF4D50D87) ROUND1(ebx, ecx, edx, eax, 8, 20, 0x455A14ED) ROUND1(eax, ebx, ecx, edx, 13, 5, 0xA9E3E905) ROUND1(edx, eax, ebx, ecx, 2, 9, 0xFCEFA3F8) ROUND1(ecx, edx, eax, ebx, 7, 14, 0x676F02D9) ROUND1(ebx, ecx, edx, eax, 12, 20, 0x8D2A4C8A) ROUND2(eax, ebx, ecx, edx, 5, 4, 0xFFFA3942) ROUND2(edx, eax, ebx, ecx, 8, 11, 0x8771F681) ROUND2(ecx, edx, eax, ebx, 11, 16, 0x6D9D6122) ROUND2(ebx, ecx, edx, eax, 14, 23, 0xFDE5380C) ROUND2(eax, ebx, ecx, edx, 1, 4, 0xA4BEEA44) ROUND2(edx, eax, ebx, ecx, 4, 11, 0x4BDECFA9) ROUND2(ecx, edx, eax, ebx, 7, 16, 0xF6BB4B60) ROUND2(ebx, ecx, edx, eax, 10, 23, 0xBEBFBC70) ROUND2(eax, ebx, ecx, edx, 13, 4, 0x289B7EC6) ROUND2(edx, eax, ebx, ecx, 0, 11, 0xEAA127FA) ROUND2(ecx, edx, eax, ebx, 3, 16, 0xD4EF3085) ROUND2(ebx, ecx, edx, eax, 6, 23, 0x04881D05) ROUND2(eax, ebx, ecx, edx, 9, 4, 0xD9D4D039) ROUND2(edx, eax, ebx, ecx, 12, 11, 0xE6DB99E5) ROUND2(ecx, edx, eax, ebx, 15, 16, 0x1FA27CF8) ROUND2(ebx, ecx, edx, eax, 2, 23, 0xC4AC5665) ROUND3(eax, ebx, ecx, edx, 0, 6, 0xF4292244) ROUND3(edx, eax, ebx, ecx, 7, 10, 0x432AFF97) ROUND3(ecx, edx, eax, ebx, 14, 15, 0xAB9423A7) ROUND3(ebx, ecx, edx, eax, 5, 21, 0xFC93A039) ROUND3(eax, ebx, ecx, edx, 12, 6, 0x655B59C3) ROUND3(edx, eax, ebx, ecx, 3, 10, 0x8F0CCC92) ROUND3(ecx, edx, eax, ebx, 10, 15, 0xFFEFF47D) ROUND3(ebx, ecx, edx, eax, 1, 21, 0x85845DD1) ROUND3(eax, ebx, ecx, edx, 8, 6, 0x6FA87E4F) ROUND3(edx, eax, ebx, ecx, 15, 10, 0xFE2CE6E0) ROUND3(ecx, edx, eax, ebx, 6, 15, 0xA3014314) ROUND3(ebx, ecx, edx, eax, 13, 21, 0x4E0811A1) ROUND3(eax, ebx, ecx, edx, 4, 6, 0xF7537E82) ROUND3(edx, eax, ebx, ecx, 11, 10, 0xBD3AF235) ROUND3(ecx, edx, eax, ebx, 2, 15, 0x2AD7D2BB) ROUND3(ebx, ecx, edx, eax, 9, 21, 0xEB86D391) /* Save updated state */ movl 20(%esp), %esi addl %eax, 0(%esi) addl %ebx, 4(%esi) addl %ecx, 8(%esi) addl %edx, 12(%esi) /* Restore registers */ movl 0(%esp), %ebx movl 4(%esp), %esi movl 8(%esp), %edi movl 12(%esp), %ebp addl $16, %esp retl