Skip to content

Implement SHA-256 (SHA-2) cryptographic hash function#1

Merged
AndreaCicca merged 5 commits into
mainfrom
copilot/implement-sha2-algorithm
Nov 17, 2025
Merged

Implement SHA-256 (SHA-2) cryptographic hash function#1
AndreaCicca merged 5 commits into
mainfrom
copilot/implement-sha2-algorithm

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 17, 2025

Adds SHA-256 implementation to complement existing SHA-0 and SHA-1 algorithms.

Implementation

  • sha256.hh/sha256.cc (410 lines): Complete SHA-256 algorithm following NIST FIPS 180-4

    • 8 state registers (h0-h7) for 256-bit digest
    • 64 compression rounds with K constants derived from cube roots of first 64 primes
    • Message schedule expansion using σ0/σ1 functions
    • Right rotate/shift operations for SHA-256 specifics
  • common_hash.hh: Added cripto_test_sha256() and openssl_test_sha256() wrapper functions

  • ut_sha_functions.cc: 10 unit tests covering empty strings, special characters, non-ASCII, 1M character strings, randomized inputs, determinism, and avalanche effect

  • main.cc/sha_cli.cc: Integrated SHA-256 alongside SHA-1 in test harness and CLI tool

Usage

cripto::SHA256 sha256;
uint8_t digest[cripto::SHA256_DIGEST_SIZE];

sha256.initialization(reinterpret_cast<const uint8_t*>(data), length);
sha256.final(digest);

std::string hash = cripto::SHA256::toHexString(digest, cripto::SHA256_DIGEST_SIZE);
// SHA256("abc") = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

Verified against standard NIST test vectors. All outputs match OpenSSL implementation.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • center2.conan.io
    • Triggering command: /usr/bin/python3 /home/REDACTED/.local/bin/conan install . --output-folder=build --build=missing (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Implementa SHA2


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 17, 2025 15:21
Co-authored-by: AndreaCicca <58073848+AndreaCicca@users.noreply.github.com>
Co-authored-by: AndreaCicca <58073848+AndreaCicca@users.noreply.github.com>
Co-authored-by: AndreaCicca <58073848+AndreaCicca@users.noreply.github.com>
Co-authored-by: AndreaCicca <58073848+AndreaCicca@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement SHA2 hashing algorithm Implement SHA-256 (SHA-2) cryptographic hash function Nov 17, 2025
Copilot AI requested a review from AndreaCicca November 17, 2025 15:31
@AndreaCicca AndreaCicca marked this pull request as ready for review November 17, 2025 15:42
@AndreaCicca AndreaCicca merged commit 38fa891 into main Nov 17, 2025
2 of 3 checks passed
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