Skip to content

Commit b16f93e

Browse files
Update book
1 parent 7de0595 commit b16f93e

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
- [Overview](./custom-extensions/overview.md)
2121
- [Keccak](./custom-extensions/keccak.md)
22-
- [SHA-256](./custom-extensions/sha256.md)
22+
- [SHA-2](./custom-extensions/sha2.md)
2323
- [Big Integer](./custom-extensions/bigint.md)
2424
- [Algebra (Modular Arithmetic)](./custom-extensions/algebra.md)
2525
- [Elliptic Curve Cryptography](./custom-extensions/ecc.md)

book/src/custom-extensions/overview.md

Lines changed: 3 additions & 3 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) - SHA-2 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

@@ -35,7 +35,7 @@ The template `openvm.toml` file is as follows:
3535
[app_vm_config.rv32m]
3636
[app_vm_config.io]
3737
[app_vm_config.keccak]
38-
[app_vm_config.sha256]
38+
[app_vm_config.sha2]
3939
[app_vm_config.native]
4040
[app_vm_config.bigint]
4141
[app_vm_config.modular]

book/src/custom-extensions/sha2.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
1-
# SHA-256
1+
# SHA-2
22

3-
The OpenVM SHA-256 extension provides tools for using the SHA-256 hash function. Refer [here](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) for more details on SHA-256.
4-
The functional part is provided by the `openvm-sha256-guest` crate, which is a guest library that can be used in any OpenVM program.
3+
The OpenVM SHA-2 extension provides tools for using the SHA-256, SHA-512, and SHA-384 hash functions. Refer [here](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) for more details on the SHA-2 family of hash functions.
4+
The functional part is provided by the `openvm-sha2-guest` crate, which is a guest library that can be used in any OpenVM program.
55

66
## Functions for guest code
77

8-
The OpenVM SHA-256Guest extension provides two functions for using in your guest code:
8+
The OpenVM SHA-2 Guest extension provides three pairs of functions for using in your guest code:
99

1010
- `sha256(input: &[u8]) -> [u8; 32]`: Computes the SHA-256 hash of the input data and returns it as an array of 32 bytes.
11-
- `set_sha256(input: &[u8], output: &mut [u8; 32])`: Sets the output to the SHA-256 hash of the input data into the provided output buffer.
11+
- `set_sha256(input: &[u8], output: &mut [u8; 32])`: Sets the provided output buffer to the SHA-256 hash of the input data.
12+
- `sha512(input: &[u8]) -> [u8; 64]`: Computes the SHA-512 hash of the input data and returns it as an array of 64 bytes.
13+
- `set_sha512(input: &[u8], output: &mut [u8; 64])`: Sets the provided output buffer to the SHA-512 hash of the input data.
14+
- `sha384(input: &[u8]) -> [u8; 48]`: Computes the SHA-384 hash of the input data and returns it as an array of 48 bytes.
15+
- `set_sha384(input: &[u8], output: &mut [u8; 64])`: Sets the first 48 bytes of the provided output buffer to the SHA-384 hash of the input data and sets the rest of the buffer to zero.
1216

13-
See the full example [here](https://github.com/openvm-org/openvm/blob/main/examples/sha256/src/main.rs).
17+
See the full example [here](https://github.com/openvm-org/openvm/blob/main/examples/sha2/src/main.rs).
1418

1519
### Example
1620

1721
```rust,no_run,noplayground
18-
{{ #include ../../../examples/sha256/src/main.rs:imports }}
19-
{{ #include ../../../examples/sha256/src/main.rs:main }}
22+
{{ #include ../../../examples/sha2/src/main.rs:imports }}
23+
{{ #include ../../../examples/sha2/src/main.rs:main }}
2024
```
2125

22-
To be able to import the `sha256` function, add the following to your `Cargo.toml` file:
26+
To be able to import the `shaXXX` functions, add the following to your `Cargo.toml` file:
2327

2428
```toml
25-
openvm-sha256-guest = { git = "https://github.com/openvm-org/openvm.git" }
29+
openvm-sha2-guest = { git = "https://github.com/openvm-org/openvm.git" }
2630
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
2731
```
2832

2933
## External Linking
3034

31-
The SHA-256 guest extension also provides another way to use the intrinsic SHA-256 implementation. It provides a function that is meant to be linked to other external libraries. The external libraries can use this function as a hook for the SHA-256 intrinsic. This is enabled only when the target is `zkvm`.
35+
The SHA-2 guest extension also provides another way to use the intrinsic SHA-2 implementations. It provides functions that are meant to be linked to other external libraries. The external libraries can use these functions as hooks for the SHA-2 intrinsics. This is enabled only when the target is `zkvm`.
3236

33-
- `zkvm_sha256_impl(input: *const u8, len: usize, output: *mut u8)`: This function has `C` ABI. It takes in a pointer to the input, the length of the input, and a pointer to the output buffer.
37+
- `zkvm_shaXXX_impl(input: *const u8, len: usize, output: *mut u8)`: where `XXX` is `256`, `512`, or `384`. These functions have `C` ABI. They take in a pointer to the input, the length of the input, and a pointer to the output buffer.
3438

3539
In the external library, you can do the following:
3640

@@ -59,5 +63,5 @@ fn sha256(input: &[u8]) -> [u8; 32] {
5963
For the guest program to build successfully add the following to your `.toml` file:
6064

6165
```toml
62-
[app_vm_config.sha256]
66+
[app_vm_config.sha2]
6367
```

book/src/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ OpenVM is an open-source zero-knowledge virtual machine (zkVM) framework focused
1212

1313
- RISC-V support via RV32IM
1414
- A native field arithmetic extension for proof recursion and aggregation
15-
- The Keccak-256 and SHA2-256 hash functions
15+
- The Keccak-256, SHA-256, SHA-512, and SHA-384 hash functions
1616
- Int256 arithmetic
1717
- Modular arithmetic over arbitrary fields
1818
- Elliptic curve operations, including multi-scalar multiplication and ECDSA signature verification, including for the secp256k1 and secp256r1 curves.

0 commit comments

Comments
 (0)