Skip to content

Commit e27df87

Browse files
Rename SHA-256 to SHA-2
1 parent e927567 commit e27df87

File tree

50 files changed

+231
-211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+231
-211
lines changed

.github/workflows/extension-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- { name: "rv32im", path: "rv32im" }
2929
- { name: "native", path: "native" }
3030
- { name: "keccak256", path: "keccak256" }
31-
- { name: "sha256", path: "sha256" }
31+
- { name: "sha2", path: "sha2" }
3232
- { name: "bigint", path: "bigint" }
3333
- { name: "algebra", path: "algebra" }
3434
- { name: "ecc", path: "ecc" }

.github/workflows/primitives.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
paths:
99
- "crates/circuits/primitives/**"
1010
- "crates/circuits/poseidon2-air/**"
11-
- "crates/circuits/sha-air/**"
11+
- "crates/circuits/sha2-air/**"
1212
- "crates/circuits/mod-builder/**"
1313
- "Cargo.toml"
1414
- ".github/workflows/primitives.yml"
@@ -47,8 +47,8 @@ jobs:
4747
run: |
4848
cargo nextest run --cargo-profile fast --features parallel
4949
50-
- name: Run tests for sha-air
51-
working-directory: crates/circuits/sha-air
50+
- name: Run tests for sha2-air
51+
working-directory: crates/circuits/sha2-air
5252
run: |
5353
cargo nextest run --cargo-profile fast --features parallel
5454

Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ members = [
5151
"extensions/keccak256/transpiler",
5252
"extensions/keccak256/guest",
5353
"extensions/keccak256/tests",
54-
"extensions/sha256/circuit",
55-
"extensions/sha256/transpiler",
56-
"extensions/sha256/guest",
57-
"extensions/sha256/tests",
54+
"extensions/sha2/circuit",
55+
"extensions/sha2/transpiler",
56+
"extensions/sha2/guest",
57+
"extensions/sha2/tests",
5858
"extensions/ecc/circuit",
5959
"extensions/ecc/transpiler",
6060
"extensions/ecc/guest",
@@ -112,7 +112,7 @@ openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", ta
112112
openvm-sdk = { path = "crates/sdk", default-features = false }
113113
openvm-mod-circuit-builder = { path = "crates/circuits/mod-builder", default-features = false }
114114
openvm-poseidon2-air = { path = "crates/circuits/poseidon2-air", default-features = false }
115-
openvm-sha-air = { path = "crates/circuits/sha-air", default-features = false }
115+
openvm-sha2-air = { path = "crates/circuits/sha2-air", default-features = false }
116116
openvm-sha-macros = { path = "crates/circuits/sha-macros", default-features = false }
117117
openvm-circuit-primitives = { path = "crates/circuits/primitives", default-features = false }
118118
openvm-circuit-primitives-derive = { path = "crates/circuits/primitives/derive", default-features = false }
@@ -141,9 +141,9 @@ openvm-native-recursion = { path = "extensions/native/recursion", default-featur
141141
openvm-keccak256-circuit = { path = "extensions/keccak256/circuit", default-features = false }
142142
openvm-keccak256-transpiler = { path = "extensions/keccak256/transpiler", default-features = false }
143143
openvm-keccak256-guest = { path = "extensions/keccak256/guest", default-features = false }
144-
openvm-sha256-circuit = { path = "extensions/sha256/circuit", default-features = false }
145-
openvm-sha256-transpiler = { path = "extensions/sha256/transpiler", default-features = false }
146-
openvm-sha256-guest = { path = "extensions/sha256/guest", default-features = false }
144+
openvm-sha2-circuit = { path = "extensions/sha2/circuit", default-features = false }
145+
openvm-sha2-transpiler = { path = "extensions/sha2/transpiler", default-features = false }
146+
openvm-sha2-guest = { path = "extensions/sha2/guest", default-features = false }
147147
openvm-bigint-circuit = { path = "extensions/bigint/circuit", default-features = false }
148148
openvm-bigint-transpiler = { path = "extensions/bigint/transpiler", default-features = false }
149149
openvm-bigint-guest = { path = "extensions/bigint/guest", default-features = false }
@@ -212,7 +212,7 @@ rrs-lib = "0.1.0"
212212
rand = { version = "0.8.5", default-features = false }
213213
hex = { version = "0.4.3", default-features = false }
214214
serde-big-array = "0.5.1"
215-
ndarray = "0.16.1"
215+
ndarray = { version = "0.16.1", default-features = false }
216216

217217
# default-features = false for no_std for use in guest programs
218218
itertools = { version = "0.14.0", default-features = false }

benchmarks/programs/kitchen-sink/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ openvm-pairing-guest = { path = "../../../extensions/pairing/guest", default-fea
1818
"bls12_381",
1919
] }
2020
openvm-keccak256-guest = { path = "../../../extensions/keccak256/guest", default-features = false }
21-
openvm-sha256-guest = { path = "../../../extensions/sha256/guest", default-features = false }
21+
openvm-sha2-guest = { path = "../../../extensions/sha2/guest", default-features = false }
2222
openvm-bigint-guest = { path = "../../../extensions/bigint/guest", default-features = false }
2323
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
2424
serde = "1.0"

benchmarks/programs/kitchen-sink/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{hint::black_box, mem::transmute};
33
use openvm_algebra_guest::IntMod;
44
use openvm_bigint_guest::I256;
55
use openvm_keccak256_guest::keccak256;
6-
use openvm_sha256_guest::sha256;
6+
use openvm_sha2_guest::sha256;
77
#[allow(unused_imports)]
88
use {
99
openvm_ecc_guest::{

benchmarks/src/bin/kitchen_sink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() -> Result<()> {
3030
.rv32m(Default::default())
3131
.io(Default::default())
3232
.keccak(Default::default())
33-
.sha256(Default::default())
33+
.sha2(Default::default())
3434
.bigint(Default::default())
3535
.modular(ModularExtension::new(vec![
3636
BigUint::from_str("1000000000000000003").unwrap(),

book/src/custom-extensions/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ You can seamlessly integrate certain performance-optimized extensions maintained
55
In this chapter, we will explain how to use the following existing extensions:
66

77
- [`openvm-keccak-guest`](./keccak.md) - Keccak256 hash function.
8-
- [`openvm-sha256-guest`](./sha256.md) - SHA2-256 hash function.
8+
- [`openvm-sha2-guest`](./sha2.md) - SHA2 hash functions.
99
- [`openvm-bigint-guest`](./bigint.md) - Big integer arithmetic for 256-bit signed and unsigned integers.
1010
- [`openvm-algebra-guest`](./algebra.md) - Modular arithmetic and complex field extensions.
1111
- [`openvm-ecc-guest`](./ecc.md) - Elliptic curve cryptography.
1212
- [`openvm-pairing-guest`](./pairing.md) - Elliptic curve optimal Ate pairings.
1313

14-
Some extensions such as `openvm-keccak-guest`, `openvm-sha256-guest`, and `openvm-bigint-guest` can be enabled without specifying any additional configuration.
14+
Some extensions such as `openvm-keccak-guest`, `openvm-sha2-guest`, and `openvm-bigint-guest` can be enabled without specifying any additional configuration.
1515

1616
On the other hand certain arithmetic operations, particularly modular arithmetic, can be optimized significantly when the modulus is known at compile time. This approach requires a framework to inform the compiler about all the moduli and associated arithmetic structures we intend to use. To achieve this, three steps are involved:
1717

crates/circuits/sha-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ itertools = "0.14"
1313
proc-macro2 = "1.0"
1414

1515
[dev-dependencies]
16-
openvm-sha-air = { workspace = true }
16+
openvm-sha2-air = { workspace = true }
1717
openvm-circuit-primitives-derive = { workspace = true }
1818
ndarray.workspace = true
1919

crates/circuits/sha-macros/tests/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use openvm_sha_air::{Sha256Config, ShaConfig};
1+
use openvm_sha2_air::{Sha256Config, Sha2Config};
22
use openvm_sha_macros::ColsRef;
33

44
#[repr(C)]
55
#[derive(Clone, Copy, Debug, ColsRef)]
6-
#[config(ShaConfig)]
6+
#[config(Sha2Config)]
77
pub struct ShaFlagsCols<T, const ROW_VAR_CNT: usize> {
88
pub is_round_row: T,
99
/// A flag that indicates if the current row is among the first 4 rows of a block

crates/circuits/sha-macros/tests/nested.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use openvm_sha_air::{Sha256Config, ShaConfig};
1+
use openvm_sha2_air::{Sha256Config, Sha2Config};
22
use openvm_sha_macros::ColsRef;
33

44
#[allow(dead_code)]
55
#[derive(ColsRef)]
6-
#[config(ShaConfig)]
6+
#[config(Sha2Config)]
77
struct Test1Cols<T, const WORD_BITS: usize> {
88
pub a: T,
99
pub nested: Test2Cols<T, WORD_BITS>,
1010
}
1111

1212
#[allow(dead_code)]
1313
#[derive(ColsRef)]
14-
#[config(ShaConfig)]
14+
#[config(Sha2Config)]
1515
struct Test2Cols<T, const WORD_BITS: usize> {
1616
pub b: T,
1717
pub c: [T; WORD_BITS],

crates/circuits/sha-macros/tests/simple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use openvm_sha_air::{Sha256Config, ShaConfig};
1+
use openvm_sha2_air::{Sha256Config, Sha2Config};
22
use openvm_sha_macros::ColsRef;
33

44
#[allow(dead_code)]
55
#[derive(ColsRef)]
6-
#[config(ShaConfig)]
6+
#[config(Sha2Config)]
77
struct Test<T, const WORD_BITS: usize, const ROUNDS_PER_ROW: usize, const WORD_U16S: usize> {
88
a: T,
99
b: [T; WORD_BITS],

crates/circuits/sha-macros/tests/work-vars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use openvm_sha_air::{Sha256Config, ShaConfig};
1+
use openvm_sha2_air::{Sha256Config, Sha2Config};
22
use openvm_sha_macros::ColsRef;
33

44
#[repr(C)]
55
#[derive(Clone, Copy, Debug, ColsRef)]
6-
#[config(ShaConfig)]
6+
#[config(Sha2Config)]
77
pub struct ShaWorkVarsCols<
88
T,
99
const WORD_BITS: usize,

crates/circuits/sha-air/Cargo.toml renamed to crates/circuits/sha2-air/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "openvm-sha-air"
2+
name = "openvm-sha2-air"
33
version.workspace = true
44
authors.workspace = true
55
edition.workspace = true

crates/circuits/sha-air/src/air.rs renamed to crates/circuits/sha2-air/src/air.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ use super::{
1919
small_sig1_field,
2020
};
2121
use crate::{
22-
constraint_word_addition, word_into_u16_limbs, ShaConfig, ShaDigestColsRef, ShaRoundColsRef,
22+
constraint_word_addition, word_into_u16_limbs, Sha2Config, ShaDigestColsRef, ShaRoundColsRef,
2323
};
2424

2525
/// Expects the message to be padded to a multiple of C::BLOCK_WORDS * C::WORD_BITS bits
2626
#[derive(Clone, Debug)]
27-
pub struct Sha2Air<C: ShaConfig> {
27+
pub struct Sha2Air<C: Sha2Config> {
2828
pub bitwise_lookup_bus: BitwiseOperationLookupBus,
2929
pub row_idx_encoder: Encoder,
3030
/// Internal bus for self-interactions in this AIR.
3131
bus: PermutationCheckBus,
3232
_phantom: PhantomData<C>,
3333
}
3434

35-
impl<C: ShaConfig> Sha2Air<C> {
35+
impl<C: Sha2Config> Sha2Air<C> {
3636
pub fn new(bitwise_lookup_bus: BitwiseOperationLookupBus, self_bus_idx: BusIndex) -> Self {
3737
Self {
3838
bitwise_lookup_bus,
@@ -43,13 +43,13 @@ impl<C: ShaConfig> Sha2Air<C> {
4343
}
4444
}
4545

46-
impl<F, C: ShaConfig> BaseAir<F> for Sha2Air<C> {
46+
impl<F, C: Sha2Config> BaseAir<F> for Sha2Air<C> {
4747
fn width(&self) -> usize {
4848
max(C::ROUND_WIDTH, C::DIGEST_WIDTH)
4949
}
5050
}
5151

52-
impl<AB: InteractionBuilder, C: ShaConfig> SubAir<AB> for Sha2Air<C> {
52+
impl<AB: InteractionBuilder, C: Sha2Config> SubAir<AB> for Sha2Air<C> {
5353
/// The start column for the sub-air to use
5454
type AirContext<'a>
5555
= usize
@@ -69,7 +69,7 @@ impl<AB: InteractionBuilder, C: ShaConfig> SubAir<AB> for Sha2Air<C> {
6969
}
7070
}
7171

72-
impl<C: ShaConfig> Sha2Air<C> {
72+
impl<C: Sha2Config> Sha2Air<C> {
7373
/// Implements the single row constraints (i.e. imposes constraints only on local)
7474
/// Implements some sanity constraints on the row index, flags, and work variables
7575
fn eval_row<AB: InteractionBuilder>(&self, builder: &mut AB, start_col: usize) {

crates/circuits/sha-air/src/columns.rs renamed to crates/circuits/sha2-air/src/columns.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use openvm_circuit_primitives::utils::not;
44
use openvm_sha_macros::ColsRef;
55
use openvm_stark_backend::p3_field::FieldAlgebra;
66

7-
use crate::ShaConfig;
7+
use crate::Sha2Config;
88

99
/// In each SHA block:
1010
/// - First C::ROUND_ROWS rows use ShaRoundCols
@@ -20,7 +20,7 @@ use crate::ShaConfig;
2020
/// 2. Specific constraints to use the appropriate struct, with flags helping to do conditional constraints
2121
#[repr(C)]
2222
#[derive(Clone, Copy, Debug, ColsRef)]
23-
#[config(ShaConfig)]
23+
#[config(Sha2Config)]
2424
pub struct ShaRoundCols<
2525
T,
2626
const WORD_BITS: usize,
@@ -30,16 +30,16 @@ pub struct ShaRoundCols<
3030
const ROUNDS_PER_ROW_MINUS_ONE: usize,
3131
const ROW_VAR_CNT: usize,
3232
> {
33-
pub flags: ShaFlagsCols<T, ROW_VAR_CNT>,
33+
pub flags: Sha2FlagsCols<T, ROW_VAR_CNT>,
3434
pub work_vars: ShaWorkVarsCols<T, WORD_BITS, ROUNDS_PER_ROW, WORD_U16S>,
3535
pub schedule_helper:
36-
ShaMessageHelperCols<T, WORD_U16S, ROUNDS_PER_ROW, ROUNDS_PER_ROW_MINUS_ONE>,
36+
Sha2MessageHelperCols<T, WORD_U16S, ROUNDS_PER_ROW, ROUNDS_PER_ROW_MINUS_ONE>,
3737
pub message_schedule: ShaMessageScheduleCols<T, WORD_BITS, ROUNDS_PER_ROW, WORD_U8S>,
3838
}
3939

4040
#[repr(C)]
4141
#[derive(Clone, Copy, Debug, ColsRef)]
42-
#[config(ShaConfig)]
42+
#[config(Sha2Config)]
4343
pub struct ShaDigestCols<
4444
T,
4545
const WORD_BITS: usize,
@@ -50,11 +50,11 @@ pub struct ShaDigestCols<
5050
const ROUNDS_PER_ROW_MINUS_ONE: usize,
5151
const ROW_VAR_CNT: usize,
5252
> {
53-
pub flags: ShaFlagsCols<T, ROW_VAR_CNT>,
53+
pub flags: Sha2FlagsCols<T, ROW_VAR_CNT>,
5454
/// Will serve as previous hash values for the next block
5555
pub hash: ShaWorkVarsCols<T, WORD_BITS, ROUNDS_PER_ROW, WORD_U16S>,
5656
pub schedule_helper:
57-
ShaMessageHelperCols<T, WORD_U16S, ROUNDS_PER_ROW, ROUNDS_PER_ROW_MINUS_ONE>,
57+
Sha2MessageHelperCols<T, WORD_U16S, ROUNDS_PER_ROW, ROUNDS_PER_ROW_MINUS_ONE>,
5858
/// The actual final hash values of the given block
5959
/// Note: the above `hash` will be equal to `final_hash` unless we are on the last block
6060
pub final_hash: [[T; WORD_U8S]; HASH_WORDS],
@@ -65,7 +65,7 @@ pub struct ShaDigestCols<
6565

6666
#[repr(C)]
6767
#[derive(Clone, Copy, Debug, ColsRef)]
68-
#[config(ShaConfig)]
68+
#[config(Sha2Config)]
6969
pub struct ShaMessageScheduleCols<
7070
T,
7171
const WORD_BITS: usize,
@@ -81,7 +81,7 @@ pub struct ShaMessageScheduleCols<
8181

8282
#[repr(C)]
8383
#[derive(Clone, Copy, Debug, ColsRef)]
84-
#[config(ShaConfig)]
84+
#[config(Sha2Config)]
8585
pub struct ShaWorkVarsCols<
8686
T,
8787
const WORD_BITS: usize,
@@ -100,8 +100,8 @@ pub struct ShaWorkVarsCols<
100100
/// Note: these need to be correctly assigned for every row even on padding rows
101101
#[repr(C)]
102102
#[derive(Clone, Copy, Debug, ColsRef)]
103-
#[config(ShaConfig)]
104-
pub struct ShaMessageHelperCols<
103+
#[config(Sha2Config)]
104+
pub struct Sha2MessageHelperCols<
105105
T,
106106
const WORD_U16S: usize,
107107
const ROUNDS_PER_ROW: usize,
@@ -119,8 +119,8 @@ pub struct ShaMessageHelperCols<
119119

120120
#[repr(C)]
121121
#[derive(Clone, Copy, Debug, ColsRef)]
122-
#[config(ShaConfig)]
123-
pub struct ShaFlagsCols<T, const ROW_VAR_CNT: usize> {
122+
#[config(Sha2Config)]
123+
pub struct Sha2FlagsCols<T, const ROW_VAR_CNT: usize> {
124124
pub is_round_row: T,
125125
/// A flag that indicates if the current row is among the first 4 rows of a block (the message rows)
126126
pub is_first_4_rows: T,
@@ -135,7 +135,7 @@ pub struct ShaFlagsCols<T, const ROW_VAR_CNT: usize> {
135135
}
136136

137137
impl<O, T: Copy + core::ops::Add<Output = O>, const ROW_VAR_CNT: usize>
138-
ShaFlagsCols<T, ROW_VAR_CNT>
138+
Sha2FlagsCols<T, ROW_VAR_CNT>
139139
{
140140
pub fn is_not_padding_row(&self) -> O {
141141
self.is_round_row + self.is_digest_row
@@ -149,7 +149,7 @@ impl<O, T: Copy + core::ops::Add<Output = O>, const ROW_VAR_CNT: usize>
149149
}
150150
}
151151

152-
impl<O, T: Copy + core::ops::Add<Output = O>> ShaFlagsColsRef<'_, T> {
152+
impl<O, T: Copy + core::ops::Add<Output = O>> Sha2FlagsColsRef<'_, T> {
153153
pub fn is_not_padding_row(&self) -> O {
154154
*self.is_round_row + *self.is_digest_row
155155
}

crates/circuits/sha-air/src/config.rs renamed to crates/circuits/sha2-air/src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
22

33
use crate::{ShaDigestColsRef, ShaRoundColsRef};
44

5-
pub trait ShaConfig: Send + Sync + Clone {
5+
pub trait Sha2Config: Send + Sync + Clone {
66
type Word: 'static
77
+ Shr<usize, Output = Self::Word>
88
+ Shl<usize, Output = Self::Word>
@@ -72,7 +72,7 @@ pub trait ShaConfig: Send + Sync + Clone {
7272
#[derive(Clone)]
7373
pub struct Sha256Config;
7474

75-
impl ShaConfig for Sha256Config {
75+
impl Sha2Config for Sha256Config {
7676
// ==== Do not change these constants! ====
7777
type Word = u32;
7878
/// Number of bits in a SHA256 word
@@ -136,7 +136,7 @@ pub const SHA256_H: [u32; 8] = [
136136
#[derive(Clone)]
137137
pub struct Sha512Config;
138138

139-
impl ShaConfig for Sha512Config {
139+
impl Sha2Config for Sha512Config {
140140
// ==== Do not change these constants! ====
141141
type Word = u64;
142142
/// Number of bits in a SHA512 word
@@ -282,7 +282,7 @@ pub const SHA512_H: [u64; 8] = [
282282
#[derive(Clone)]
283283
pub struct Sha384Config;
284284

285-
impl ShaConfig for Sha384Config {
285+
impl Sha2Config for Sha384Config {
286286
// ==== Do not change these constants! ====
287287
type Word = u64;
288288
/// Number of bits in a SHA384 word

0 commit comments

Comments
 (0)