solutions/zokrates_prover/.zokrates/stdlib/hashes/sha256/512bitPacked.zok

20 lines
771 B
Plaintext
Executable File

import "../../utils/pack/u32/pack128" as pack128;
import "../../utils/pack/u32/unpack128" as unpack128;
import "./512bitPadded" as sha256;
// A function that takes an array of 4 field elements as input, unpacks each of them to 128
// bits (big endian), concatenates them and applies sha256.
// It then returns an array of two field elements, each representing 128 bits of the result.
def main(field[4] preimage) -> field[2] {
u32[4] a_bits = unpack128(preimage[0]);
u32[4] b_bits = unpack128(preimage[1]);
u32[4] c_bits = unpack128(preimage[2]);
u32[4] d_bits = unpack128(preimage[3]);
u32[8] lhs = [...a_bits, ...b_bits];
u32[8] rhs = [...c_bits, ...d_bits];
u32[8] r = sha256(lhs, rhs);
return [pack128(r[0..4]), pack128(r[4..8])];
}