Skip to content

Commit

Permalink
docs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
detherminal committed Apr 5, 2024
1 parent 135f06e commit e98ed16
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 34 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 23 additions & 25 deletions src/crypt/cryptonight/slow_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,37 @@ const SCRATCHPAD_SIZE: usize = 2 * 1024 * 1024; // 2 MiB

/// EXPERIMENTAL! Main CryptoNight function defined in: <https://web.archive.org/web/20190911221902/https://cryptonote.org/cns/cns008.txt>
///
/// 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];
Expand Down
5 changes: 2 additions & 3 deletions src/keys/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>> = 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<bool> = Vec::with_capacity(11);
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) -> String`](keys/fn.derive_hex_seed.html)
Expand All @@ -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<String>`](keys/fn.generate_seed.html)
//! - Utils
//!
//! - [`is_valid_addr(address: &str) -> bool`](utils/fn.is_valid_addr.html)


Expand Down
1 change: 1 addition & 0 deletions src/mnemonics/polyseed/languages/english.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::mnemonics::polyseed::wordsets::WordsetPolyseed;

pub(crate) const ENGLISHPOLYSEED: WordsetPolyseed = WordsetPolyseed {
name: "en",
prefix_length: 4,
words: [
"abandon",
"ability",
Expand Down
1 change: 1 addition & 0 deletions src/mnemonics/polyseed/wordsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}

Expand Down
6 changes: 3 additions & 3 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e98ed16

Please sign in to comment.