Skip to content

feat: add SHA-1 hash function implementation#1030

Open
AliAlimohammadi wants to merge 1 commit intoTheAlgorithms:masterfrom
AliAlimohammadi:add-sha1
Open

feat: add SHA-1 hash function implementation#1030
AliAlimohammadi wants to merge 1 commit intoTheAlgorithms:masterfrom
AliAlimohammadi:add-sha1

Conversation

@AliAlimohammadi
Copy link
Contributor

@AliAlimohammadi AliAlimohammadi commented Mar 24, 2026

Description

Adds a pure-Rust implementation of the SHA-1 cryptographic hash function, producing a 160-bit (20-byte) digest from an arbitrary-length byte slice.

SHA-1 is specified in NIST FIPS 180-4. The implementation follows the spec directly:

  1. Padding — appends 0x80, zero bytes, and the 64-bit big-endian message length so the total length is a multiple of 512 bits.
  2. Message schedule — expands 16 big-endian words per block to 80 via ROTL₁(wₜ₋₃ ⊕ wₜ₋₈ ⊕ wₜ₋₁₄ ⊕ wₜ₋₁₆).
  3. Compression — 80 rounds across four 20-round stages, each with its own mixing function (Ch, Parity, Maj) and round constant.
  4. Serialisation — five 32-bit state words written back as big-endian bytes.

⚠️ SHA-1 is cryptographically broken and should not be used for security-sensitive purposes. This implementation is provided for educational and algorithmic completeness only.

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.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 98.92473% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.06%. Comparing base (1c7738e) to head (56e6709).

Files with missing lines Patch % Lines
src/ciphers/sha1.rs 98.92% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1030   +/-   ##
=======================================
  Coverage   96.06%   96.06%           
=======================================
  Files         388      389    +1     
  Lines       29468    29561   +93     
=======================================
+ Hits        28309    28399   +90     
- Misses       1159     1162    +3     

☔ 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.

@AliAlimohammadi
Copy link
Contributor Author

@siriak, this is ready to be merged.

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.

2 participants