Skip to main content

sha512_fixed

Function sha512_fixed 

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

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

This function creates a subcircuit that computes the SHA-512 hash of a message with a compile-time known length. Unlike sha512_varlen, which handles a runtime length, 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 packed 64-bit words (8 bytes per wire) in big-endian format. The words should already be encoded from bytes in big-endian order, matching SHA-512’s byte-to-word conversion.
  • len_bytes - The fixed length of the message in bytes (known at compile time)

§Returns

  • [Wire; 8] - The SHA-512 digest as 8 wires of 64 bits each in big-endian order

§Panics

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

§Example

ⓘ
use binius_frontend::crate::sha512::sha512_fixed;
use binius_frontend::compiler::CircuitBuilder;

let mut builder = CircuitBuilder::new();

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

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