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

Function simplicity_nonce_hash

src/simplicity/elements/elementsJets.c:951–983  ·  view source on GitHub ↗

nonce_hash : CTX8 * S (Conf TWO^256) |- CTX8 */

Source from the content-addressed store, hash-verified

949
950/* nonce_hash : CTX8 * S (Conf TWO^256) |- CTX8 */
951bool simplicity_nonce_hash(frameItem* dst, frameItem src, const txEnv* env) {
952 (void) env; // env is unused.
953 sha256_midstate midstate;
954 unsigned char buf[32];
955 sha256_context ctx = {.output = midstate.s};
956
957 /* Read a SHA-256 context. */
958 if (!simplicity_read_sha256_context(&ctx, &src)) return false;
959
960 /* Read an optional nonce. (259 bits) */
961 if (readBit(&src)) {
962 /* Read a nonce prefix. (2 bits) */
963 if (readBit(&src)) {
964 /* Read an explicit none prefix. (1 bit) */
965 forwardBits(&src, 1);
966 sha256_uchar(&ctx, 0x01);
967 } else {
968 /* Read a confidential none prefix. (1 bit) */
969 if (readBit(&src)) {
970 sha256_uchar(&ctx, 0x03);
971 } else {
972 sha256_uchar(&ctx, 0x02);
973 }
974 }
975 /* Read a nonce id body (both confidential and explicit nonce bodies are the same size). (256 bits) */
976 read8s(buf, 32, &src);
977 sha256_uchars(&ctx, buf, 32);
978 } else {
979 sha256_uchar(&ctx, 0x00);
980 }
981
982 return simplicity_write_sha256_context(dst, &ctx);
983}
984
985/* annex_hash : CTX8 * S TWO^256 |- CTX8 */
986bool simplicity_annex_hash(frameItem* dst, frameItem src, const txEnv* env) {

Callers

nothing calls this directly

Calls 7

readBitFunction · 0.85
forwardBitsFunction · 0.85
sha256_ucharFunction · 0.85
read8sFunction · 0.85
sha256_ucharsFunction · 0.85

Tested by

no test coverage detected