openvm_sha2_circuit/sha2_chips/main_chip/
config.rs

1use openvm_sha2_air::{Sha256Config, Sha384Config, Sha512Config};
2use openvm_sha2_transpiler::Rv32Sha2Opcode;
3
4use crate::{Sha2ColsRef, SHA2_READ_SIZE, SHA2_REGISTER_READS, SHA2_WRITE_SIZE};
5
6pub trait Sha2MainChipConfig: Send + Sync + Clone {
7    // --- Required ---
8    /// Number of bytes in a SHA block (sometimes referred to as message bytes in the code)
9    const BLOCK_BYTES: usize;
10    /// Number of bytes in a SHA state
11    const STATE_BYTES: usize;
12    /// OpenVM Opcode for the instruction
13    const OPCODE: Rv32Sha2Opcode;
14
15    // --- Provided ---
16    const BLOCK_READS: usize = Self::BLOCK_BYTES / SHA2_READ_SIZE;
17    const STATE_READS: usize = Self::STATE_BYTES / SHA2_READ_SIZE;
18    const STATE_WRITES: usize = Self::STATE_BYTES / SHA2_WRITE_SIZE;
19
20    const TIMESTAMP_DELTA: usize =
21        Self::BLOCK_READS + Self::STATE_READS + Self::STATE_WRITES + SHA2_REGISTER_READS;
22
23    const MAIN_CHIP_WIDTH: usize = Sha2ColsRef::<u8>::width::<Self>();
24}
25
26impl Sha2MainChipConfig for Sha256Config {
27    const BLOCK_BYTES: usize = 64;
28    const STATE_BYTES: usize = 32;
29    const OPCODE: Rv32Sha2Opcode = Rv32Sha2Opcode::SHA256;
30}
31
32impl Sha2MainChipConfig for Sha512Config {
33    const BLOCK_BYTES: usize = 128;
34    const STATE_BYTES: usize = 64;
35    const OPCODE: Rv32Sha2Opcode = Rv32Sha2Opcode::SHA512;
36}
37
38impl Sha2MainChipConfig for Sha384Config {
39    const BLOCK_BYTES: usize = Sha512Config::BLOCK_BYTES;
40    const STATE_BYTES: usize = Sha512Config::STATE_BYTES;
41    const OPCODE: Rv32Sha2Opcode = Sha512Config::OPCODE;
42}