|
8 | 8 | //! Accelerated today: |
9 | 9 | //! - `keccak256`: a sponge over the `keccak_permute` precompile (riscv64; on |
10 | 10 | //! host it falls back to software keccak for tests). |
| 11 | +//! - `sha256`: the padding wrapper over the SHA-256 compression precompile |
| 12 | +//! (riscv64; on host it falls back to the trait's own sha2 default). |
11 | 13 | //! - `secp256k1_ecrecover`: the ECDSA recovery's 2-term linear combination is |
12 | 14 | //! evaluated through the ECSM `ecsm_mul` precompile (riscv64), reconstructing |
13 | 15 | //! the full point from x-only queries; on host / degenerate inputs it falls |
@@ -63,6 +65,18 @@ impl Crypto for LambdaVmEcsmCrypto { |
63 | 65 | #[cfg(not(target_arch = "riscv64"))] |
64 | 66 | return keccak_hash(input); |
65 | 67 | } |
| 68 | + |
| 69 | + fn sha256(&self, input: &[u8]) -> [u8; 32] { |
| 70 | + // riscv64 guest: IV, padding and the length encoding in the wrapper, |
| 71 | + // the 64 rounds per block in the compression accelerator. |
| 72 | + #[cfg(target_arch = "riscv64")] |
| 73 | + return lambda_vm_syscalls::sha256::sha256(input); |
| 74 | + // host (tests / non-guest): the ecall isn't available off-target. |
| 75 | + // `NativeCrypto` takes every trait default, so this is the same sha2 |
| 76 | + // call the default `sha256` would have made, with no extra dependency. |
| 77 | + #[cfg(not(target_arch = "riscv64"))] |
| 78 | + return ethrex_crypto::NativeCrypto.sha256(input); |
| 79 | + } |
66 | 80 | } |
67 | 81 |
|
68 | 82 | // ── ECDSA secp256k1 recovery via the ECSM precompile ──────────────────────── |
|
0 commit comments