MCPcopy Create free account
hub / github.com/ElementsProject/elements / simplicity_make_tapleaf

Function simplicity_make_tapleaf

src/simplicity/elements/ops.c:133–151  ·  view source on GitHub ↗

Compute an Element's tapleaf hash from a tapleaf version and a 256-bit script value. * A reimplementation of ComputeTapleafHash from Element's 'interpreter.cpp'. * Only 256-bit script values are supported as that is the size used for Simplicity CMRs. * * Precondition: NULL != cmr; */

Source from the content-addressed store, hash-verified

131 * Precondition: NULL != cmr;
132 */
133sha256_midstate simplicity_make_tapleaf(unsigned char version, const sha256_midstate* cmr) {
134 sha256_midstate result;
135 sha256_midstate tapleafTag;
136 {
137 static unsigned char tagName[] = "TapLeaf/elements";
138 sha256_context ctx = sha256_init(tapleafTag.s);
139 sha256_uchars(&ctx, tagName, sizeof(tagName) - 1);
140 sha256_finalize(&ctx);
141 }
142 sha256_context ctx = sha256_init(result.s);
143 sha256_hash(&ctx, &tapleafTag);
144 sha256_hash(&ctx, &tapleafTag);
145 sha256_uchar(&ctx, version);
146 sha256_uchar(&ctx, 32);
147 sha256_hash(&ctx, cmr);
148 sha256_finalize(&ctx);
149
150 return result;
151}
152
153/* Compute an Element's tapbrach hash from two branches.
154 *

Calls 5

sha256_initFunction · 0.85
sha256_ucharsFunction · 0.85
sha256_finalizeFunction · 0.85
sha256_hashFunction · 0.85
sha256_ucharFunction · 0.85

Tested by

no test coverage detected