Skip to content

Commit

Permalink
cryptonight in pure Rust (#271)
Browse files Browse the repository at this point in the history
* removed FORCE_USE_HEAP to from c code

* removed unused headers

* simplifying C code to better understand it

* more c code simplifications

* removed conditional code for the v4 register size

* got one version of keccak working

* not so important hash_process unwound

* got keccak working using the sha3 lib

* hash state unions created

* slow hash through VARIANT1_PORTABLE_INIT is working

* variant 2 init working

* ported version of random_math_init compiling, but not yet passing tests

* fixed hash algorithm, tests working

* formatting

* more macro reduction

* monero AES working in Rust

* fixed AES key expansion expected key size

* first 75% of slow hash converted and working correctly

* adjusted key format for aesb_single_round

* converted some macros to functions

* variant2_integer_math working with test cases

* broke sqrt out of variant2_integer_math for code coverage

* variant2_portable_shuffle_add working with unit tests

* added skein and jh hashes

* 524287 iteration loop producing correct results

* all tests working in Rust

* subarray macros added

* aes simplifications

* code cleanups

* code cleanups part 2

* removed unused blake C code as prep for port to rust

* original blake algorithm in pure rust is working

* converted macro in compress to a lamda

* added module documentation for blake256

* Gave Blake256 a Digest trait

* adding more documentation

* more documentation and cleanup

* more slow hash tests

* removed C code

* misc refactoring

* fix

* lint fix

* additional linting

* downgraded deps to latest stable versions

* made thiserror a workspace dep

* removed commented dead code

* lint fixes

* fixed lint issues in test code

* limited util macro scopes to the crate

* Reformatted dependencies using:
group_imports = "StdExternalCrate"
reorder_modules = true
reorder_impl_items = true
imports_granularity = "crate"

* converted util macros to inline functions

* hex dep comes from workspace

Co-authored-by: hinto-janai <[email protected]>

* panic subarray tests

Co-authored-by: hinto-janai <[email protected]>

* updates to doc comments

* removes extra parens in hash_v4.rs

Co-authored-by: hinto-janai <[email protected]>

* early return to remove indentation in hash_v2.rs

Co-authored-by: hinto-janai <[email protected]>

* gropuing expect annotations in hash_v2.rs

Co-authored-by: hinto-janai <[email protected]>

* use matches macro to simplify code hash_v4.rs

Co-authored-by: hinto-janai <[email protected]>

* remove extra paren in hash_v4.rs

Co-authored-by: hinto-janai <[email protected]>

* eary return to remove indentation in hash_v2.rs

Co-authored-by: hinto-janai <[email protected]>

* minor comment fixes

* early loop continue to remove indentation in hash_v4.rs

Co-authored-by: hinto-janai <[email protected]>

* convert non-capturing llamda to fn in hash_v2.rs

Co-authored-by: hinto-janai <[email protected]>

* another lamda to fn conversion in hash_v2.rs

Co-authored-by: hinto-janai <[email protected]>

* llamda to fn conversion in cnaes.rs

Co-authored-by: hinto-janai <[email protected]>

* 2nd llamda to fn conversion in cnaes.rs

Co-authored-by: hinto-janai <[email protected]>

* test lamdas in lib.rs are now functions

* round_fwd optimized

* added myself as an author

* fixed place that needed wrapping_add

* clippy allow->expect change needed after merging master

* moving state to u128

* round_fwd changes sped up fuzzer by 10%

* 1st working version using u128 for long state

* text converted to u128 array

* removed LongState union

* simplified long_state's initialization

* aes round keys now use u128

* CRYPTONIGHT_SBOX is now u32 instead of u8

* cleaner hash_v4 loop unrolling semantics (same peformance)

* switched to a better maintained loop unrolling macro
  • Loading branch information
dimalinux authored Oct 8, 2024
1 parent ca88251 commit 00bdd6f
Show file tree
Hide file tree
Showing 45 changed files with 2,907 additions and 13,129 deletions.
50 changes: 49 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions cryptonight/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ version = "0.1.0"
edition = "2021"
description = "A wrapper around Monero's CryptoNight hash function."
license = "MIT"
authors = ["Boog900", "The Monero Project"]
authors = ["dimalinux", "Boog900", "The Monero Project"]
repository = "https://github.com/Cuprate/cuprate/tree/main/cryptonight"

[dependencies]
thiserror = "1"

[build-dependencies]
cc = "1"
thiserror = { workspace = true }
sha3 = "0.10.8"
groestl = "0.10.1"
skein = "0.1.0"
jh = "0.1.0"
keccak = "0.1.5"
digest = "0.10.7"
seq-macro = "0.3.5"

[dev-dependencies]
hex = "0.4"
hex = { workspace = true, features = ["std"] }

[lints]
workspace = true
52 changes: 0 additions & 52 deletions cryptonight/build.rs

This file was deleted.

123 changes: 0 additions & 123 deletions cryptonight/c/CryptonightR_JIT.c

This file was deleted.

22 changes: 0 additions & 22 deletions cryptonight/c/CryptonightR_JIT.h

This file was deleted.

Loading

0 comments on commit 00bdd6f

Please sign in to comment.