Skip to content

feat: move hash functions to dedicated hashing module and add MD5#1033

Merged
siriak merged 1 commit intoTheAlgorithms:masterfrom
AliAlimohammadi:add-MD5
Apr 8, 2026
Merged

feat: move hash functions to dedicated hashing module and add MD5#1033
siriak merged 1 commit intoTheAlgorithms:masterfrom
AliAlimohammadi:add-MD5

Conversation

@AliAlimohammadi
Copy link
Copy Markdown
Contributor

Description

Adds an MD5 hash function implementation (src/hashing/md5.rs) and moves all existing hash functions out of src/ciphers/ into a new dedicated src/hashing/ module.

Why the restructure: Hash functions are fundamentally different from ciphers — they are one-way and non-reversible. Keeping them in ciphers/ was misleading. This change mirrors how the repository already separates concerns into sorting/, graph/, data_structures/, etc.

MD5 implementation: A pure-Rust implementation following RFC 1321. It processes input in 512-bit blocks across four rounds of 16 operations each, using precomputed sine-derived constants (K table) and per-round bit-shift amounts (S table), producing a 128-bit (16-byte) little-endian digest.

⚠️ Note: MD5 is cryptographically broken and is included for educational/checksum purposes only.

Files changed:

  • src/hashing/md5.rs — new MD5 implementation
  • src/hashing/mod.rs — new module, re-exports all hash functions
  • src/ciphers/mod.rs — removed hashing entries
  • src/lib.rs — added pub mod hashing
  • Moved: blake2b.rs, sha1.rs, sha2.rs, sha3.rs, hashing_traits.rssrc/hashing/

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked CONTRIBUTING.md and my code follows its guidelines.

@AliAlimohammadi AliAlimohammadi requested a review from imp2002 as a code owner April 7, 2026 21:30
@AliAlimohammadi
Copy link
Copy Markdown
Contributor Author

@siriak, this is ready to be merged.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.00%. Comparing base (d3c9028) to head (5d3b356).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1033      +/-   ##
==========================================
+ Coverage   95.98%   96.00%   +0.01%     
==========================================
  Files         389      390       +1     
  Lines       29520    29605      +85     
==========================================
+ Hits        28335    28421      +86     
+ Misses       1185     1184       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a dedicated hashing/ module to separate one-way hash algorithms from reversible ciphers, and adds a new MD5 implementation alongside existing SHA/BLAKE hashing algorithms.

Changes:

  • Added src/hashing/ module and exposed it via src/lib.rs
  • Moved existing hash implementations (SHA-1/SHA-2/SHA-3/BLAKE2b + hashing traits) out of ciphers/ into hashing/
  • Added a pure-Rust MD5 implementation (plus hex helper) and updated DIRECTORY.md

Reviewed changes

Copilot reviewed 5 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/lib.rs Exposes the new hashing module from the crate root.
src/hashing/mod.rs Defines the hashing module and re-exports hashing APIs (including MD5).
src/hashing/md5.rs Adds MD5 + md5_hex with RFC test vectors.
src/hashing/sha1.rs SHA-1 implementation relocated under hashing.
src/hashing/sha2.rs SHA-2 family implementation relocated under hashing.
src/hashing/sha3.rs SHA-3 implementation relocated under hashing.
src/hashing/blake2b.rs BLAKE2b implementation relocated under hashing.
src/hashing/hashing_traits.rs Hashing traits + HMAC relocated under hashing.
src/ciphers/mod.rs Removes hashing modules/re-exports from ciphers.
DIRECTORY.md Updates directory listing to reflect the new hashing module and MD5.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@siriak siriak merged commit 6e42c38 into TheAlgorithms:master Apr 8, 2026
11 checks passed
@AliAlimohammadi AliAlimohammadi deleted the add-MD5 branch April 8, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants