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; */
| 131 | * Precondition: NULL != cmr; |
| 132 | */ |
| 133 | sha256_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 | * |
no test coverage detected