Skip to main content

sha256_fixed

Function sha256_fixed 

Source
pub fn sha256_fixed(
    builder: &CircuitBuilder,
    message: &[Wire],
    len_bytes: usize,
) -> [Wire; 8]
Expand description

Computes SHA-256 hash of a fixed-length message.

This function creates a subcircuit that computes the SHA-256 hash of a message with a compile-time known length. Unlike sha256_varlen, which handles variable-length inputs, this function is optimized for fixed-length inputs where the length is known at circuit construction time.

§Arguments

  • builder - Circuit builder for constructing constraints
  • message - Input message as 32-bit words (4 bytes per wire) in big-endian format. Each wire must have the high 32 bits set to zero (enforced as a precondition).
  • len_bytes - The fixed length of the message in bytes (known at compile time)

§Returns

  • [Wire; 8] - The SHA-256 digest as 8 wires, each containing a 32-bit word in the low 32 bits (high 32 bits are zero) in big-endian order

§Panics

  • If message.len() does not equal exactly len_bytes.div_ceil(4)
  • If the message length in bits cannot fit in 32 bits

§Example

ⓘ
use binius_frontend::crate::sha256::sha256_fixed;
use binius_frontend::compiler::CircuitBuilder;

let mut builder = CircuitBuilder::new();

// Create input wires for a 32-byte message (8 32-bit words)
let message: Vec<_> = (0..8).map(|_| builder.add_witness()).collect();

// Compute SHA-256 of the 32-byte message
let digest = sha256_fixed(&builder, &message, 32);