diff --git a/Cargo.lock b/Cargo.lock index 3f2a23d..aed333b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,10 +31,10 @@ dependencies = [ "hex-literal", "itertools", "lazy_static", + "md-5", "pico-args", "regex", "reqwest", - "rust-crypto", "serde_json", ] @@ -56,6 +56,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.11.1" @@ -96,6 +105,26 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -156,12 +185,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futures-channel" version = "0.3.25" @@ -211,10 +234,14 @@ dependencies = [ ] [[package]] -name = "gcc" -version = "0.3.55" +name = "generic-array" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] [[package]] name = "h2" @@ -416,6 +443,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "md-5" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" +dependencies = [ + "digest", +] + [[package]] name = "memchr" version = "2.5.0" @@ -436,7 +472,7 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.42.0", ] @@ -567,53 +603,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.3.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" -dependencies = [ - "libc", - "rand 0.4.6", -] - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -686,25 +675,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "rust-crypto" -version = "0.2.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" -dependencies = [ - "gcc", - "libc", - "rand 0.3.23", - "rustc-serialize", - "time", -] - -[[package]] -name = "rustc-serialize" -version = "0.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" - [[package]] name = "ryu" version = "1.0.11" @@ -817,17 +787,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -916,6 +875,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + [[package]] name = "unicode-bidi" version = "0.3.8" @@ -970,12 +935,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 3965ae0..6f4ed64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,8 @@ hashbrown = "0.13.1" hex-literal = "0.3.4" itertools = "0.10.5" lazy_static = "1.4.0" +md-5 = "0.10.5" pico-args = "0.5.0" regex = "1.7.0" reqwest = { version = "0.11.13", features = ["blocking"] } -rust-crypto = "0.2.36" serde_json = "1.0.89" diff --git a/src/bin/04.rs b/src/bin/04.rs index 27796a2..c901566 100644 --- a/src/bin/04.rs +++ b/src/bin/04.rs @@ -1,40 +1,32 @@ -use crypto::digest::Digest; -use crypto::md5::Md5; +use md5::{Digest, Md5}; pub fn part_one(input: &str) -> Option { let key = input.trim().as_bytes(); let mut hasher = Md5::new(); for x in 0..std::u64::MAX { - hasher.input(key); - hasher.input(x.to_string().as_bytes()); + hasher.update(key); + hasher.update(x.to_string().as_bytes()); + let output = hasher.finalize_reset(); - let mut output = [0; 16]; - hasher.result(&mut output); - - let first_five = output[0] as u32 + output[1] as u32 + (output[2] >> 4) as u32; - if first_five == 0 { + if output.starts_with(&[0, 0]) && output[2] <= 0x0F { return Some(x as u32); } - hasher.reset(); } - None + unreachable!() } pub fn part_two(input: &str) -> Option { let key = input.trim().as_bytes(); let mut hasher = Md5::new(); for x in 0..std::u64::MAX { - hasher.input(key); - hasher.input(x.to_string().as_bytes()); - - let mut output = [0; 16]; - hasher.result(&mut output); + hasher.update(key); + hasher.update(x.to_string().as_bytes()); + let output = hasher.finalize_reset(); if output.starts_with(&[0, 0, 0]) { return Some(x as u32); } - hasher.reset(); } - None + unreachable!() } fn main() { let input = &aoc::read_file("inputs", 4);