From e98ed16d94059bb93c90d28164757a3a35d47343 Mon Sep 17 00:00:00 2001 From: dethe <76167420+detherminal@users.noreply.github.com> Date: Sat, 6 Apr 2024 02:52:38 +0300 Subject: [PATCH] docs fixes --- Cargo.toml | 1 - README.md | 2 +- src/crypt/cryptonight/slow_hash.rs | 48 ++++++++++----------- src/keys/keys.rs | 5 +-- src/lib.rs | 3 +- src/mnemonics/polyseed/languages/english.rs | 1 + src/mnemonics/polyseed/wordsets.rs | 1 + tests/integration_test.rs | 6 +-- 8 files changed, 33 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index efa38bf..fdd107d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,4 +35,3 @@ jh = "0.1.0" blake-hash = "0.4.1" # Hashes needed for implementing the final step (end) serde_json = "1.0.113" -reed-solomon = "0.2.1" diff --git a/README.md b/README.md index a5bef32..b76c5f5 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Add the library to your project and use the functions: \ ```cargo add libmonero``` For more details, please take a look at [docs](https://docs.rs/libmonero). -If you have any questions, you can ask either at the [discussions](https://github.com/monumexyz/libmonero/discussions) or [matrix room](https://matrix.to/#/#monume:matrix.org). +If you have any questions, you can ask either at the [discussions](https://github.com/monumexyz/libmonero/discussions) or [matrix channel](https://matrix.to/#/#monume:matrix.org). ## Supporting diff --git a/src/crypt/cryptonight/slow_hash.rs b/src/crypt/cryptonight/slow_hash.rs index 9b8c1e3..399cba3 100644 --- a/src/crypt/cryptonight/slow_hash.rs +++ b/src/crypt/cryptonight/slow_hash.rs @@ -16,39 +16,37 @@ const SCRATCHPAD_SIZE: usize = 2 * 1024 * 1024; // 2 MiB /// EXPERIMENTAL! Main CryptoNight function defined in: /// -/// Even though it's actually implemented in Rust for [Cuprate](https://github.com/Cuprate/cuprate), anyone can use it. -/// /// Example: /// ``` -/// use libmonero::crypt::cryptonight::cn_slow_hash; +/// use libmonero::crypt::cryptonight::cn_slow_hash_original; /// /// let input: &str = "This is a test"; -/// let output: String = cn_slow_hash(input.as_bytes()); +/// let output: String = cn_slow_hash_original(input.as_bytes()); /// assert_eq!(output, "a084f01d1437a09c6985401b60d43554ae105802c5f5d8a9b3253649c0be6605".to_string()); /// ``` -pub fn cn_slow_hash(input: &[u8]) -> String { +pub fn cn_slow_hash_original(input: &[u8]) -> String { // CryptoNight Step 1: Initialization Of Scratchpad - // First, the input is hashed using Keccak [KECCAK] with parameters b = - // 1600 and c = 512. The bytes 0..31 of the Keccak final state are - // interpreted as an AES-256 key [AES] and expanded to 10 round keys. A - // scratchpad of 2097152 bytes (2 MiB) is allocated. The bytes 64..191 - // are extracted from the Keccak final state and split into 8 blocks of - // 16 bytes each. Each block is encrypted using the following procedure: - - // for i = 0..9 do: - // block = aes_round(block, round_keys[i]) - - // Where aes_round function performs a round of AES encryption, which - // means that SubBytes, ShiftRows and MixColumns steps are performed on - // the block, and the result is XORed with the round key. Note that - // unlike in the AES encryption algorithm, the first and the last rounds - // are not special. The resulting blocks are written into the first 128 - // bytes of the scratchpad. Then, these blocks are encrypted again in - // the same way, and the result is written into the second 128 bytes of - // the scratchpad. Each time 128 bytes are written, they represent the - // result of the encryption of the previously written 128 bytes. The - // process is repeated until the scratchpad is fully initialized. + // First, the input is hashed using Keccak [KECCAK] with parameters b = + // 1600 and c = 512. The bytes 0..31 of the Keccak final state are + // interpreted as an AES-256 key [AES] and expanded to 10 round keys. A + // scratchpad of 2097152 bytes (2 MiB) is allocated. The bytes 64..191 + // are extracted from the Keccak final state and split into 8 blocks of + // 16 bytes each. Each block is encrypted using the following procedure: + + // for i = 0..9 do: + // block = aes_round(block, round_keys[i]) + + // Where aes_round function performs a round of AES encryption, which + // means that SubBytes, ShiftRows and MixColumns steps are performed on + // the block, and the result is XORed with the round key. Note that + // unlike in the AES encryption algorithm, the first and the last rounds + // are not special. The resulting blocks are written into the first 128 + // bytes of the scratchpad. Then, these blocks are encrypted again in + // the same way, and the result is written into the second 128 bytes of + // the scratchpad. Each time 128 bytes are written, they represent the + // result of the encryption of the previously written 128 bytes. The + // process is repeated until the scratchpad is fully initialized. // Step 1A: Initialize the scratchpad with empty data let mut scratchpad = [0u8; SCRATCHPAD_SIZE]; diff --git a/src/keys/keys.rs b/src/keys/keys.rs index fc1b2b9..4b32804 100644 --- a/src/keys/keys.rs +++ b/src/keys/keys.rs @@ -134,9 +134,8 @@ fn generate_polyseed_seed(language: &str) -> Vec<&str> { let seed_bits = get_random_bits(150); // Get 150 random bits let features_bits = [false; 5]; // We don't use any feature while generating the seed let mut words_bits: Vec> = Vec::with_capacity(16); // The seed of Polyseed is 16 words long - // Calulcate checksum bits - let checksum_bits = vec![false; 11]; - words_bits.push(checksum_bits); + // Add checksum bits to the seed + words_bits.push(vec![false; 11]); // Add secret seed and features bits for (index, item) in features_bits.iter().enumerate() { let mut word: Vec = Vec::with_capacity(11); diff --git a/src/lib.rs b/src/lib.rs index 2064834..242cda1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ //! - [`get_transaction_from_hash(node: DaemonNode, hash: &str) -> RawTx`](blocks/fn.get_transaction_from_hash.html) //! - Crypt //! - [`cryptonight`](crypt/cryptonight/index.html) -//! - [`cn_slow_hash(input: &[u8]) -> String`](crypt/cryptonight/fn.cn_slow_hash.html) - EXPERIMENTAL! +//! - [`cn_slow_hash_original(input: &[u8]) -> String`](crypt/cryptonight/fn.cn_slow_hash_original.html) - EXPERIMENTAL! //! - Keys //! - [`derive_address(public_spend_key: String, public_view_key: String, network: i8) -> String`](keys/fn.derive_address.html) //! - [`derive_hex_seed(mnemonic_seed: Vec) -> String`](keys/fn.derive_hex_seed.html) @@ -41,6 +41,7 @@ //! - [`derive_pub_key(private_key: String) -> String`](keys/fn.derive_pub_key.html) //! - [`generate_seed(language: &str, seed_type: &str) -> Vec`](keys/fn.generate_seed.html) //! - Utils +//! //! - [`is_valid_addr(address: &str) -> bool`](utils/fn.is_valid_addr.html) diff --git a/src/mnemonics/polyseed/languages/english.rs b/src/mnemonics/polyseed/languages/english.rs index c7d7b06..320245b 100644 --- a/src/mnemonics/polyseed/languages/english.rs +++ b/src/mnemonics/polyseed/languages/english.rs @@ -2,6 +2,7 @@ use crate::mnemonics::polyseed::wordsets::WordsetPolyseed; pub(crate) const ENGLISHPOLYSEED: WordsetPolyseed = WordsetPolyseed { name: "en", + prefix_length: 4, words: [ "abandon", "ability", diff --git a/src/mnemonics/polyseed/wordsets.rs b/src/mnemonics/polyseed/wordsets.rs index 0d38f38..5dbbace 100644 --- a/src/mnemonics/polyseed/wordsets.rs +++ b/src/mnemonics/polyseed/wordsets.rs @@ -2,6 +2,7 @@ use super::languages::english::ENGLISHPOLYSEED; pub(crate) struct WordsetPolyseed { pub name: &'static str, + pub prefix_length: u8, pub words: [&'static str; 2048], } diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 8b96ae1..6c60a5e 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { use libmonero::keys::{derive_address, derive_hex_seed, derive_priv_keys, derive_pub_key, generate_seed}; - use libmonero::crypt::cryptonight::cn_slow_hash; + use libmonero::crypt::cryptonight::cn_slow_hash_original; #[test] fn seed_generation() { @@ -30,9 +30,9 @@ mod tests { #[cfg(test)] #[allow(warnings)] - fn hashing_cn_slow() { + fn hashing_cn_slow_original() { let input = b"This is a test"; - let output = cn_slow_hash(input); + let output = cn_slow_hash_original(input); assert_eq!( output, "a084f01d1437a09c6985401b60d43554ae105802c5f5d8a9b3253649c0be6605".to_string()