Skip to content

Higher-level SHA-256 wrapper over Ctx8 primitives #374

Description

@LesterEvSe

Project

compiler

Context

The current way to hash a value in SimplicityHL uses the raw context API:

let ctx1 = jet::sha_256_ctx_8_init();
let ctx2 = jet::sha_256_ctx_8_add_2(ctx1, 0x5120);
let ctx3 = jet::sha_256_ctx_8_add_32(ctx2, tweaked_key);
let hash = jet::sha_256_ctx_8_finalize(ctx3);

Every hash of a compound value spans several lines of ctx-threading. This is noisy in application code.

Available primitives

sha_256_ctx_8_add_N exists for N ∈ {2, 4, 8, 16, 32, 64, 128, 256, 512}
plus sha_256_ctx_8_add_buffer_511. Any wrapper has to dispatch across
this set based on the static size of its input.

Wanted

An ergonomic wrapper, ideally something like:

let hash = sha_256(tweaked_key);
let hash = sha_256((0x5120, tweaked_key));

so that "init, add, finalize" collapses into one call.

Open question

Input shape: fixed-size type, tuple of fixed-size types, both? What is rejected and how does a user handle it?

Deliverable

Design proposal answering the questions above, reviewed on this issue, then implementation.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions