diff --git a/.gitignore b/.gitignore index ea8c4bf..c3c6f30 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,23 @@ /target +### Rust template +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# RustRover +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 17d57c1..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,1440 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "aead" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" -dependencies = [ - "crypto-common", - "generic-array", -] - -[[package]] -name = "aes" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures", -] - -[[package]] -name = "aes-gcm" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" -dependencies = [ - "aead", - "aes", - "cipher", - "ctr", - "ghash", - "subtle", -] - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - -[[package]] -name = "anstyle" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" - -[[package]] -name = "anyhow" -version = "1.0.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" - -[[package]] -name = "async-trait" -version = "0.1.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - -[[package]] -name = "bitflags" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bumpalo" -version = "3.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" - -[[package]] -name = "bytes" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" - -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - -[[package]] -name = "cc" -version = "1.2.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739eb0f94557554b3ca9a86d2d37bebd49c5e6d0c1d2bda35ba5bdac830befc2" -dependencies = [ - "find-msvc-tools", - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "chrono" -version = "0.4.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-traits", - "serde", - "wasm-bindgen", - "windows-link", -] - -[[package]] -name = "ciborium" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" - -[[package]] -name = "ciborium-ll" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" -dependencies = [ - "ciborium-io", - "half", -] - -[[package]] -name = "cipher" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" -dependencies = [ - "crypto-common", - "inout", -] - -[[package]] -name = "clap" -version = "4.5.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c2cfd7bf8a6017ddaa4e32ffe7403d547790db06bd171c1c53926faab501623" -dependencies = [ - "clap_builder", -] - -[[package]] -name = "clap_builder" -version = "4.5.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4c05b9e80c5ccd3a7ef080ad7b6ba7d6fc00a985b8b157197075677c82c7a0" -dependencies = [ - "anstyle", - "clap_lex", -] - -[[package]] -name = "clap_lex" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - -[[package]] -name = "criterion" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" -dependencies = [ - "anes", - "cast", - "ciborium", - "clap", - "criterion-plot", - "is-terminal", - "itertools", - "num-traits", - "once_cell", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" - -[[package]] -name = "crunchy" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "rand_core", - "typenum", -] - -[[package]] -name = "ctr" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" -dependencies = [ - "cipher", -] - -[[package]] -name = "dashmap" -version = "6.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" -dependencies = [ - "cfg-if", - "crossbeam-utils", - "hashbrown", - "lock_api", - "once_cell", - "parking_lot_core", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - -[[package]] -name = "find-msvc-tools" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" - -[[package]] -name = "futures" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" - -[[package]] -name = "futures-executor" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" - -[[package]] -name = "futures-macro" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" - -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "generic-array" -version = "0.14.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "ghash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" -dependencies = [ - "opaque-debug", - "polyval", -] - -[[package]] -name = "half" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" -dependencies = [ - "cfg-if", - "crunchy", - "zerocopy", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - -[[package]] -name = "hermit-abi" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" - -[[package]] -name = "iana-time-zone" -version = "0.1.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "inout" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" -dependencies = [ - "generic-array", -] - -[[package]] -name = "inventory" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc61209c082fbeb19919bee74b176221b27223e27b65d781eb91af24eb1fb46e" -dependencies = [ - "rustversion", -] - -[[package]] -name = "is-terminal" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.61.2", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - -[[package]] -name = "js-sys" -version = "0.3.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" -dependencies = [ - "once_cell", - "wasm-bindgen", -] - -[[package]] -name = "lagrange-core" -version = "0.1.0" -dependencies = [ - "aes-gcm", - "anyhow", - "async-trait", - "bytes", - "chrono", - "dashmap", - "futures", - "getrandom", - "inventory", - "lagrange-macros", - "lagrange-proto", - "md5", - "num-bigint", - "rand", - "serde", - "serde_bytes", - "sha1", - "sha2", - "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "lagrange-macros" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "lagrange-proto" -version = "0.1.0" -dependencies = [ - "bytes", - "criterion", - "lagrange-proto-derive", - "serde", - "thiserror", -] - -[[package]] -name = "lagrange-proto-derive" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "libc" -version = "0.2.177" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" - -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" - -[[package]] -name = "md5" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" - -[[package]] -name = "memchr" -version = "2.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" - -[[package]] -name = "mio" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.61.2", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" - -[[package]] -name = "oorandom" -version = "11.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" - -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - -[[package]] -name = "parking_lot" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-link", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "plotters" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" - -[[package]] -name = "plotters-svg" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" -dependencies = [ - "plotters-backend", -] - -[[package]] -name = "polyval" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" -dependencies = [ - "cfg-if", - "cpufeatures", - "opaque-debug", - "universal-hash", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rayon" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -dependencies = [ - "bitflags", -] - -[[package]] -name = "regex" -version = "1.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" - -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "serde" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" -dependencies = [ - "serde_core", - "serde_derive", -] - -[[package]] -name = "serde_bytes" -version = "0.11.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" -dependencies = [ - "serde", - "serde_core", -] - -[[package]] -name = "serde_core" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.145" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", - "serde_core", -] - -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "signal-hook-registry" -version = "1.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" - -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - -[[package]] -name = "socket2" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" -dependencies = [ - "libc", - "windows-sys 0.60.2", -] - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.108" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "2.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - -[[package]] -name = "tokio" -version = "1.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" -dependencies = [ - "bytes", - "libc", - "mio", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.61.2", -] - -[[package]] -name = "tokio-macros" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing" -version = "0.1.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" -dependencies = [ - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" -dependencies = [ - "once_cell", -] - -[[package]] -name = "typenum" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" - -[[package]] -name = "unicode-ident" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06" - -[[package]] -name = "universal-hash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" -dependencies = [ - "crypto-common", - "subtle", -] - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - -[[package]] -name = "wasm-bindgen" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" -dependencies = [ - "cfg-if", - "once_cell", - "rustversion", - "wasm-bindgen-macro", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "web-sys" -version = "0.3.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "winapi-util" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" - -[[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-sys" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - -[[package]] -name = "zerocopy" -version = "0.8.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/crates/lagrange-core/Cargo.toml b/crates/lagrange-core/Cargo.toml index 6c30dd7..c2abdf5 100644 --- a/crates/lagrange-core/Cargo.toml +++ b/crates/lagrange-core/Cargo.toml @@ -27,6 +27,7 @@ lagrange-proto = { workspace = true, features = ["derive"] } aes-gcm = "0.10" sha1 = "0.10" sha2 = "0.10" -md5 = "0.7" +md5 = "0.8.0" num-bigint = "0.4" +crypto-bigint = "0.6.1" getrandom = "0.2" diff --git a/crates/lagrange-core/src/internal/packets/login/wtlogin.rs b/crates/lagrange-core/src/internal/packets/login/wtlogin.rs index 189edae..52b5fc3 100644 --- a/crates/lagrange-core/src/internal/packets/login/wtlogin.rs +++ b/crates/lagrange-core/src/internal/packets/login/wtlogin.rs @@ -1,12 +1,14 @@ use super::{tlv::Tlv, tlv_qrcode::TlvQrCode}; +use crate::utils::crypto::ecdh::SECP192K1; use crate::{ common::AppInfo, keystore::BotKeystore, utils::{ binary::{BinaryPacket, Prefix}, - crypto::{EcdhProvider, EllipticCurveType, TeaProvider}, + crypto::{EcdhProvider, TeaProvider}, }, }; +use crypto_bigint::Uint; use std::time::{SystemTime, UNIX_EPOCH}; const SERVER_PUBLIC_KEY: [u8; 49] = [ @@ -29,17 +31,17 @@ pub struct WtLogin<'a> { share_key: Vec, keystore: &'a BotKeystore, app_info: &'a AppInfo, - ecdh_provider: EcdhProvider, + ecdh_provider: EcdhProvider<3, 6, 5>, } impl<'a> WtLogin<'a> { pub fn new(keystore: &'a BotKeystore, app_info: &'a AppInfo) -> Result { - let ecdh_provider = EcdhProvider::new(EllipticCurveType::Secp192K1); + let ecdh_provider = EcdhProvider::new(SECP192K1); // Get the secret key from keystore state // For now, we'll generate a new one if not available let secret = if let Some(ref exchange_key) = keystore.state.exchange_key { - exchange_key.clone() + Uint::<3>::from_be_slice(exchange_key.as_slice()) } else { ecdh_provider.generate_secret() }; diff --git a/crates/lagrange-core/src/utils.rs b/crates/lagrange-core/src/utils.rs index b953df7..e53c57c 100644 --- a/crates/lagrange-core/src/utils.rs +++ b/crates/lagrange-core/src/utils.rs @@ -3,6 +3,6 @@ pub mod crypto; pub use binary::{BinaryPacket, Prefix}; pub use crypto::{ - AesGcmProvider, EcdhProvider, EllipticCurve, EllipticCurveType, EllipticPoint, PowProvider, - Sha1Stream, TeaProvider, TriSha1Provider, + AesGcmProvider, EcdhProvider, EllipticCurve, EllipticPoint, PowProvider, Sha1Stream, + TeaProvider, TriSha1Provider, }; diff --git a/crates/lagrange-core/src/utils/crypto.rs b/crates/lagrange-core/src/utils/crypto.rs index 4396370..787e61b 100644 --- a/crates/lagrange-core/src/utils/crypto.rs +++ b/crates/lagrange-core/src/utils/crypto.rs @@ -6,7 +6,7 @@ pub mod tea; pub mod tri_sha1; pub use aes_gcm::AesGcmProvider; -pub use ecdh::{EcdhProvider, EllipticCurve, EllipticCurveType, EllipticPoint}; +pub use ecdh::{EcdhProvider, EllipticCurve, EllipticPoint}; pub use pow::PowProvider; pub use sha1_stream::Sha1Stream; pub use tea::TeaProvider; diff --git a/crates/lagrange-core/src/utils/crypto/ecdh.rs b/crates/lagrange-core/src/utils/crypto/ecdh.rs index 17e397d..980905d 100644 --- a/crates/lagrange-core/src/utils/crypto/ecdh.rs +++ b/crates/lagrange-core/src/utils/crypto/ecdh.rs @@ -1,117 +1,75 @@ -use num_bigint::{BigInt, Sign}; -use rand::Rng; +use crypto_bigint::modular::SafeGcdInverter; +use crypto_bigint::rand_core::OsRng; +use crypto_bigint::{ + Concat, Encoding, Integer, Limb, NonZero, Odd, PrecomputeInverter, RandomMod, Split, Uint, + U192, U256, +}; /// Elliptic curve parameters #[derive(Debug, Clone)] -pub struct EllipticCurve { +pub struct EllipticCurve +where + Uint: Concat> + Encoding, + Uint: Split> + Encoding, + Odd>: PrecomputeInverter>, +{ /// Prime modulus - pub p: BigInt, + pub p: NonZero>, /// Curve parameter a - pub a: BigInt, + pub a: Uint, /// Curve parameter b - pub b: BigInt, + pub b: Uint, /// Generator point - pub g: EllipticPoint, + pub g: EllipticPoint, /// Order of the generator - pub n: BigInt, + pub n: NonZero>, } -impl EllipticCurve { - /// Creates the Secp192K1 curve (192-bit Koblitz curve) - pub fn secp192k1() -> Self { - let p = - BigInt::parse_bytes(b"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37", 16).unwrap(); - - let a = BigInt::from(0); - let b = BigInt::from(3); - - let gx = - BigInt::parse_bytes(b"DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D", 16).unwrap(); - - let gy = - BigInt::parse_bytes(b"9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D", 16).unwrap(); - - let n = - BigInt::parse_bytes(b"FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D", 16).unwrap(); - - Self { - p, - a, - b, - g: EllipticPoint { x: gx, y: gy }, - n, - } - } - - /// Creates the Prime256V1 curve (NIST P-256) - pub fn prime256v1() -> Self { - let p = BigInt::parse_bytes( - b"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", - 16, - ) - .unwrap(); - - let a = BigInt::parse_bytes( - b"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", - 16, - ) - .unwrap(); - - let b = BigInt::parse_bytes( - b"5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", - 16, - ) - .unwrap(); - - let gx = BigInt::parse_bytes( - b"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", - 16, - ) - .unwrap(); - - let gy = BigInt::parse_bytes( - b"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", - 16, - ) - .unwrap(); - - let n = BigInt::parse_bytes( - b"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", - 16, - ) - .unwrap(); - - Self { - p, - a, - b, - g: EllipticPoint { x: gx, y: gy }, - n, - } - } - - /// Modular reduction ensuring positive result - fn mod_positive(&self, value: &BigInt) -> BigInt { - let mut result = value % &self.p; - if result.sign() == Sign::Minus { - result += &self.p; - } - result - } - - /// Modular inverse using Fermat's Little Theorem: a^(p-2) mod p - fn mod_inverse(&self, a: &BigInt) -> BigInt { - if a.sign() == Sign::Minus { - let pos = self.mod_positive(a); - return &self.p - self.mod_inverse(&pos); - } - - // Use Fermat's little theorem: a^(p-2) mod p - a.modpow(&(&self.p - 2), &self.p) - } - +/// The Prime256V1 curve (NIST P-256) +pub const PRIME256V1: EllipticCurve<4, 8, 6> = EllipticCurve { + p: NonZero::>::new_unwrap(U256::from_be_hex( + "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff", + )), + a: U256::from_be_hex("ffffffff00000001000000000000000000000000fffffffffffffffffffffffc"), + b: U256::from_be_hex("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"), + g: EllipticPoint { + x: U256::from_be_hex("6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"), + y: U256::from_be_hex("4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"), + }, + n: NonZero::>::new_unwrap(U256::from_be_hex( + "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", + )), +}; + +/// The Secp192K1 curve (192-bit Koblitz curve) +pub const SECP192K1: EllipticCurve<3, 6, 5> = EllipticCurve { + p: NonZero::>::new_unwrap(U192::from_be_hex( + "fffffffffffffffffffffffffffffffffffffffeffffee37", + )), + a: U192::from_be_hex("000000000000000000000000000000000000000000000000"), + b: U192::from_be_hex("000000000000000000000000000000000000000000000003"), + g: EllipticPoint { + x: U192::from_be_hex("db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d"), + y: U192::from_be_hex("9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"), + }, + n: NonZero::>::new_unwrap(U192::from_be_hex( + "fffffffffffffffffffffffe26f2fc170f69466a74defd8d", + )), +}; + +impl + EllipticCurve +where + Uint: Concat> + Encoding, + Uint: Split> + Encoding, + Odd>: PrecomputeInverter>, +{ /// Adds two points on the elliptic curve - fn point_add(&self, p1: &EllipticPoint, p2: &EllipticPoint) -> EllipticPoint { + fn point_add( + &self, + p1: &EllipticPoint, + p2: &EllipticPoint, + ) -> EllipticPoint { // Identity element checks if p1.is_identity() { return p2.clone(); @@ -129,87 +87,107 @@ impl EllipticCurve { let m = if x1 == x2 { if y1 == y2 { // Point doubling: m = (3x₁² + a) / (2y₁) - let numerator = self.mod_positive(&(3 * x1 * x1 + &self.a)); - let denominator = self.mod_positive(&(2 * y1)); - let denominator_inv = self.mod_inverse(&denominator); - self.mod_positive(&(numerator * denominator_inv)) + let three_x1_sq = x1.mul_mod(x1, &self.p).mul_mod(&Uint::from(3u8), &self.p); + let numerator = three_x1_sq.add_mod(&self.a, &self.p); + let denominator = y1.mul_mod(&Uint::from(2u8), &self.p); + let denominator_inv = denominator.inv_mod(&self.p).unwrap(); + numerator.mul_mod(&denominator_inv, &self.p) } else { // Points are inverses, result is identity return EllipticPoint::identity(); } } else { // Point addition: m = (y₁ - y₂) / (x₁ - x₂) - let numerator = self.mod_positive(&(y1 - y2)); - let denominator = self.mod_positive(&(x1 - x2)); - let denominator_inv = self.mod_inverse(&denominator); - self.mod_positive(&(numerator * denominator_inv)) + let numerator = y1.sub_mod(y2, &self.p); + let denominator = x1.sub_mod(x2, &self.p); + let denominator_inv = denominator.inv_mod(&self.p).unwrap(); + numerator.mul_mod(&denominator_inv, &self.p) }; // Calculate result point // xᵣ = m² - x₁ - x₂ - let xr = self.mod_positive(&(&m * &m - x1 - x2)); + let xr = m + .mul_mod(&m, &self.p) + .sub_mod(x1, &self.p) + .sub_mod(x2, &self.p); // yᵣ = m(x₁ - xᵣ) - y₁ - let yr = self.mod_positive(&(&m * (x1 - &xr) - y1)); + let yr = m + .mul_mod(&x1.sub_mod(&xr, &self.p), &self.p) + .sub_mod(y1, &self.p); EllipticPoint { x: xr, y: yr } } /// Scalar multiplication using double-and-add algorithm - fn scalar_multiply(&self, point: &EllipticPoint, scalar: &BigInt) -> EllipticPoint { + fn scalar_multiply( + &self, + point: &EllipticPoint, + scalar: &Uint, + ) -> EllipticPoint { let mut result = EllipticPoint::identity(); let mut temp = point.clone(); - let mut k = scalar.clone(); - while k > BigInt::from(0) { - if &k % 2 == BigInt::from(1) { + for i in 0..LIMBS * Limb::BITS as usize - 1 { + if scalar.bit(i as u32).into() { result = self.point_add(&result, &temp); } temp = self.point_add(&temp, &temp); - k >>= 1; } - result } /// Verifies that a point lies on the curve - pub fn verify_point(&self, point: &EllipticPoint) -> bool { + pub fn verify_point(&self, point: &EllipticPoint) -> bool { if point.is_identity() { return true; } // Verify: y² = x³ + ax + b (mod p) - let left = self.mod_positive(&(&point.y * &point.y)); - let right = - self.mod_positive(&(&point.x * &point.x * &point.x + &self.a * &point.x + &self.b)); + let left = point.y.mul_mod(&point.y, &self.p); + let x3 = point + .x + .mul_mod(&point.x, &self.p) + .mul_mod(&point.x, &self.p); + let ax = self.a.mul_mod(&point.x, &self.p); + let right = x3.add_mod(&ax, &self.p).add_mod(&self.b, &self.p); left == right } } /// Elliptic curve point #[derive(Debug, Clone, PartialEq)] -pub struct EllipticPoint { - pub x: BigInt, - pub y: BigInt, +pub struct EllipticPoint +where + Uint: Encoding, +{ + pub x: Uint, + pub y: Uint, } -impl EllipticPoint { +impl EllipticPoint +where + Uint: Concat> + Encoding, + Uint: Split> + Encoding, + Odd>: PrecomputeInverter>, +{ + const SIZE: usize = LIMBS * Limb::BYTES; /// Creates a new elliptic curve point - pub fn new(x: BigInt, y: BigInt) -> Self { + pub fn new(x: Uint, y: Uint) -> Self { Self { x, y } } /// Creates the identity (point at infinity) pub fn identity() -> Self { Self { - x: BigInt::from(0), - y: BigInt::from(0), + x: Uint::ZERO, + y: Uint::ZERO, } } /// Checks if this is the identity point pub fn is_identity(&self) -> bool { - self.x == BigInt::from(0) && self.y == BigInt::from(0) + self.x == Uint::ZERO && self.y == Uint::ZERO } /// Converts the point to compressed format (SEC1) @@ -218,20 +196,15 @@ impl EllipticPoint { let mut result = Vec::with_capacity(1 + coord_size); // Prefix: 0x02 if y is even, 0x03 if y is odd - let y_bytes = self.y.to_bytes_be().1; - let prefix = if y_bytes.last().map(|b| b & 1).unwrap_or(0) == 0 { - 0x02 - } else { - 0x03 - }; + let prefix = if self.y.is_even().into() { 0x02 } else { 0x03 }; result.push(prefix); // Add x coordinate (padded to coord_size) - let x_bytes = self.x.to_bytes_be().1; - let padding = coord_size.saturating_sub(x_bytes.len()); - result.extend(std::iter::repeat_n(0, padding)); - result.extend_from_slice(&x_bytes); + let x_bytes = Encoding::to_be_bytes(&self.x); + let padding = coord_size.saturating_sub(x_bytes.as_ref().len()); + result.extend(std::iter::repeat(0).take(padding)); + result.extend_from_slice(x_bytes.as_ref()); result } @@ -244,22 +217,25 @@ impl EllipticPoint { result.push(0x04); // Add x coordinate (padded to coord_size) - let x_bytes = self.x.to_bytes_be().1; - let x_padding = coord_size.saturating_sub(x_bytes.len()); - result.extend(std::iter::repeat_n(0, x_padding)); - result.extend_from_slice(&x_bytes); + let x_bytes = Encoding::to_be_bytes(&self.x); + let x_padding = coord_size.saturating_sub(x_bytes.as_ref().len()); + result.extend(std::iter::repeat(0).take(x_padding)); + result.extend_from_slice(x_bytes.as_ref()); // Add y coordinate (padded to coord_size) - let y_bytes = self.y.to_bytes_be().1; - let y_padding = coord_size.saturating_sub(y_bytes.len()); - result.extend(std::iter::repeat_n(0, y_padding)); - result.extend_from_slice(&y_bytes); + let y_bytes = Encoding::to_be_bytes(&self.y); + let y_padding = coord_size.saturating_sub(y_bytes.as_ref().len()); + result.extend(std::iter::repeat(0).take(y_padding)); + result.extend_from_slice(y_bytes.as_ref()); result } /// Parses a point from SEC1 format (compressed or uncompressed) - pub fn from_bytes(data: &[u8], _curve: &EllipticCurve) -> Result { + pub fn from_bytes( + data: &[u8], + _curve: &EllipticCurve, + ) -> Result { if data.is_empty() { return Err("Empty point data"); } @@ -267,13 +243,12 @@ impl EllipticPoint { match data[0] { 0x04 => { // Uncompressed format - if data.len() < 3 { + if data.len() != Self::SIZE * 2 + 1 { return Err("Invalid uncompressed point length"); } - let coord_size = (data.len() - 1) / 2; - let x = BigInt::from_bytes_be(Sign::Plus, &data[1..1 + coord_size]); - let y = BigInt::from_bytes_be(Sign::Plus, &data[1 + coord_size..]); + let x = Uint::::from_be_slice(&data[1..1 + Self::SIZE]); + let y = Uint::::from_be_slice(&data[1 + Self::SIZE..]); Ok(Self::new(x, y)) } @@ -289,48 +264,36 @@ impl EllipticPoint { } /// ECDH provider with manual elliptic curve implementation -pub struct EcdhProvider { - curve: EllipticCurve, - coord_size: usize, +pub struct EcdhProvider +where + Uint: Concat> + Encoding, + Uint: Split> + Encoding, + Odd>: PrecomputeInverter>, +{ + curve: EllipticCurve, } -impl EcdhProvider { +impl + EcdhProvider +where + Uint: Concat> + Encoding, + Uint: Split> + Encoding, + Odd>: PrecomputeInverter>, +{ + const SIZE: usize = LIMBS * Limb::BYTES; /// Creates a new ECDH provider with the specified curve - pub fn new(curve_type: EllipticCurveType) -> Self { - match curve_type { - EllipticCurveType::Secp192K1 => Self { - curve: EllipticCurve::secp192k1(), - coord_size: 24, // 192 bits = 24 bytes - }, - EllipticCurveType::Prime256V1 => Self { - curve: EllipticCurve::prime256v1(), - coord_size: 32, // 256 bits = 32 bytes - }, - } - } - - /// Creates a provider for Prime256V1 (P-256) curve - pub fn prime256v1() -> Self { - Self::new(EllipticCurveType::Prime256V1) - } - - /// Creates a provider for Secp192K1 curve - pub fn secp192k1() -> Self { - Self::new(EllipticCurveType::Secp192K1) + pub fn new(curve: EllipticCurve) -> Self { + Self { curve } } /// Generates a random secret key - pub fn generate_secret(&self) -> Vec { - let mut rng = rand::thread_rng(); - let mut secret = vec![0u8; self.coord_size]; - rng.fill(&mut secret[..]); - secret + pub fn generate_secret(&self) -> Uint { + Uint::::random_mod(&mut OsRng, &self.curve.n) } /// Computes the public key from a secret - pub fn get_public_key(&self, secret: &[u8]) -> EllipticPoint { - let secret_int = BigInt::from_bytes_be(Sign::Plus, secret); - self.curve.scalar_multiply(&self.curve.g, &secret_int) + pub fn get_public_key(&self, secret: &Uint) -> EllipticPoint { + self.curve.scalar_multiply(&self.curve.g, secret) } /// Generates a new key pair and returns the public key in specified format @@ -339,9 +302,9 @@ impl EcdhProvider { let public = self.get_public_key(&secret); if compressed { - public.to_compressed(self.coord_size) + public.to_compressed(Self::SIZE) } else { - public.to_uncompressed(self.coord_size) + public.to_uncompressed(Self::SIZE) } } @@ -351,7 +314,7 @@ impl EcdhProvider { /// - hash_with_md5: If true, returns MD5 hash of the shared x-coordinate pub fn key_exchange( &self, - secret: &[u8], + secret: &Uint, peer_public: &[u8], hash_with_md5: bool, ) -> Result, &'static str> { @@ -364,62 +327,52 @@ impl EcdhProvider { } // Perform scalar multiplication - let secret_int = BigInt::from_bytes_be(Sign::Plus, secret); - let shared_point = self.curve.scalar_multiply(&peer_point, &secret_int); + let shared_point = self.curve.scalar_multiply(&peer_point, secret); // Use x-coordinate as shared secret - let shared_secret = shared_point.x.to_bytes_be().1; + let shared_secret = Encoding::to_be_bytes(&shared_point.x); if hash_with_md5 { - Ok(md5::compute(&shared_secret).0.to_vec()) + Ok(md5::compute(shared_secret).0.to_vec()) } else { - Ok(shared_secret) + Ok(shared_secret.as_ref().to_vec()) } } /// Packs a public key point into bytes - pub fn pack_public_key(&self, point: &EllipticPoint, compressed: bool) -> Vec { + pub fn pack_public_key(&self, point: &EllipticPoint, compressed: bool) -> Vec { if compressed { - point.to_compressed(self.coord_size) + point.to_compressed(Self::SIZE) } else { - point.to_uncompressed(self.coord_size) + point.to_uncompressed(Self::SIZE) } } /// Unpacks a public key from bytes into a point - pub fn unpack_public_key(&self, data: &[u8]) -> Result { + pub fn unpack_public_key(&self, data: &[u8]) -> Result, &'static str> { EllipticPoint::from_bytes(data, &self.curve) } } -/// Elliptic curve type selector -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum EllipticCurveType { - /// Secp192K1 (192-bit Koblitz curve) - Secp192K1, - /// Prime256V1 (NIST P-256) - Prime256V1, -} - #[cfg(test)] mod tests { use super::*; #[test] fn test_curve_point_validation() { - let curve = EllipticCurve::prime256v1(); + let curve = PRIME256V1; // Generator should be on the curve assert!(curve.verify_point(&curve.g)); // Random point should not be on the curve - let random_point = EllipticPoint::new(BigInt::from(12345), BigInt::from(67890)); + let random_point = EllipticPoint::new(Uint::from(12345u32), Uint::from(67890u32)); assert!(!curve.verify_point(&random_point)); } #[test] fn test_point_addition() { - let curve = EllipticCurve::prime256v1(); + let curve = PRIME256V1; // G + G = 2G let doubled = curve.point_add(&curve.g, &curve.g); @@ -433,20 +386,20 @@ mod tests { #[test] fn test_scalar_multiplication() { - let curve = EllipticCurve::prime256v1(); + let curve = PRIME256V1; // 1 * G = G - let result = curve.scalar_multiply(&curve.g, &BigInt::from(1)); + let result = curve.scalar_multiply(&curve.g, &Uint::from(1u32)); assert_eq!(result, curve.g); // 2 * G should be on the curve - let result = curve.scalar_multiply(&curve.g, &BigInt::from(2)); + let result = curve.scalar_multiply(&curve.g, &Uint::from(2u32)); assert!(curve.verify_point(&result)); } #[test] fn test_ecdh_key_exchange() { - let provider = EcdhProvider::prime256v1(); + let provider = EcdhProvider::new(PRIME256V1); // Generate Alice's keypair let alice_secret = provider.generate_secret(); @@ -475,7 +428,7 @@ mod tests { #[test] fn test_point_serialization() { - let curve = EllipticCurve::prime256v1(); + let curve = PRIME256V1; // Test uncompressed format let uncompressed = curve.g.to_uncompressed(32); @@ -490,8 +443,8 @@ mod tests { #[test] fn test_point_deserialization() { - let curve = EllipticCurve::prime256v1(); - let provider = EcdhProvider::prime256v1(); + let curve = PRIME256V1; + let provider = EcdhProvider::new(PRIME256V1); // Serialize and deserialize let original = curve.g.clone();