Cyber Security News

SHA256 Hash Calculation from Data Chunks

The SHA256 algorithm, a cryptographic hash function, is widely used for securing data integrity and authenticity.

It processes input data in fixed-size chunks of 512 bits (64 bytes) and produces a unique 256-bit (32-byte) hash.

This property allows for incremental hashing, where data is processed in smaller chunks without requiring the entire dataset to be loaded into memory.

Such functionality is particularly beneficial for systems with limited resources, such as embedded devices or when handling large files.

Incremental hashing works by maintaining an internal state that updates with each chunk of data processed.

This state ensures that the final hash value remains consistent regardless of whether the data is hashed all at once or in smaller segments.

The algorithm’s design makes it impossible to combine partial hashes into a complete one, preserving its security against length-extension attacks.

Technical Workflow of SHA256

The input message undergoes preprocessing to ensure its length is a multiple of 512 bits.

Padding is applied, starting with a single ‘1’ bit followed by zeros, and the original message length is appended as a 64-bit value.

This ensures compatibility with the algorithm’s block-based processing.

According to the researchers, each 512-bit chunk is divided into 16 words of 32 bits each.

These words are expanded into 64 using logical operations such as bitwise shifts and XORs.

The algorithm then performs 64 rounds of computations using these words, constants derived from prime numbers, and eight working variables initialized with predefined values.

The operations include:

  • Logical functions like AND, OR, XOR, and NOT.
  • Modular addition to ensure results fit within 32 bits.
  • Right rotations and shifts to introduce non-linearity.

At the end of each round, the working variables are updated based on the results of these operations.

If multiple chunks are processed, the output hash values from one chunk serve as the input for the next.

After all chunks are processed, the eight working variables are concatenated to produce the final 256-bit hash value.

This value serves as a digital fingerprint of the input data and cannot be reversed to reveal the original content.

Applications and Advantages

Incremental hashing is particularly useful in scenarios where memory constraints or large datasets make it impractical to process all data at once.

Examples include:

  • Verifying file integrity during streaming or transmission.
  • Hashing firmware updates in embedded systems.
  • Blockchain applications where transactions are hashed incrementally.

Libraries implementing SHA256 typically provide functions like update for processing chunks and finalize for generating the final hash.

This approach ensures efficiency and consistency across various use cases.

Are you from SOC/DFIR Team? - Join 500,000+ Researchers to Analyze Cyber Threats with ANY.RUN Sandbox - Try for Free

Aman Mishra

Aman Mishra is a Security and privacy Reporter covering various data breach, cyber crime, malware, & vulnerability.

Recent Posts

Hackers Use ConnectWise SkyKick Credentials to Access Microsoft 365, Halting Cloud Backups

Attackers abused compromised ConnectWise Cloud Backup credentials to access Microsoft 365 customer environments, prompting ConnectWise…

1 day ago

Anthropic’s Claude AI Uncovers Origins of NSA-Provided Cryptographic Keys After 25 Years

Anthropic says an internal Claude research model reconstructed how the National Security Agency generated seeds…

1 day ago

Critical WordPress Flaws Allow Attackers to Execute Remote Code Without Authentication

Two WordPress Core vulnerabilities can be chained to execute remote code without authentication, according to…

1 day ago

OpenBSD Kernel Flaw Dating Back 37 Years Enables Local Privilege Escalation to Root

A newly disclosed OpenBSD kernel exploitation chain combines a shared memory accounting flaw with a…

1 day ago

GhostAction Hackers Hide Credential-Stealing Malware in Fake Font Files Across 94 GitHub Repositories

GhostAction attackers have expanded their GitHub credential theft campaign with a second stage that disguises…

1 day ago

SideCopy Hackers Target Indian Organizations With ReverseRAT Malware to Steal Data

Indian authorities have warned that SideCopy hackers are targeting Indian organizations, including academic institutions, with…

1 day ago