|
10 | 10 |
|
11 | 11 | #define SIGTYPE_ALL (WALLY_SIGTYPE_PRE_SW | WALLY_SIGTYPE_SW_V0 | WALLY_SIGTYPE_SW_V1) |
12 | 12 |
|
| 13 | +#if defined(CCAN_CRYPTO_SHA256_USE_OPENSSL) || defined(CCAN_CRYPTO_SHA256_USE_MBEDTLS) |
| 14 | +/* For external sha256 implementations, we cannot cache the sha256 context as |
| 15 | + * they require extra setup before use that only sha256_init() provides. |
| 16 | + */ |
| 17 | +#define TXIO_CTX_CACHEABLE 0 |
| 18 | +#else |
| 19 | +/* For our built-in sha256 implementation we can cache and use the context */ |
| 20 | +#define TXIO_CTX_CACHEABLE 1 |
| 21 | +#endif |
| 22 | + |
13 | 23 | /* Cache keys for data that is constant while signing a given tx. |
14 | 24 | * We also cache other data keyed by their binary value directly. |
15 | 25 | */ |
@@ -761,20 +771,22 @@ static int bip143_signature_hash( |
761 | 771 | static void txio_bip341_init(cursor_io *io, |
762 | 772 | const unsigned char *genesis_blockhash, size_t genesis_blockhash_len) |
763 | 773 | { |
764 | | - const struct wally_map_item *item; |
765 | | - item = io->cache ? wally_map_get_integer(io->cache, TXIO_SHA_TAPSIGHASH_CTX) : NULL; |
766 | | - if (item) { |
767 | | - /* Note we hash the intial sha256_ctx itself here and so memcpy it */ |
768 | | - memcpy(&io->ctx, item->value, item->value_len); |
769 | | - return; |
| 774 | + if (TXIO_CTX_CACHEABLE && io->cache) { |
| 775 | + const struct wally_map_item *item = NULL; |
| 776 | + item = wally_map_get_integer(io->cache, TXIO_SHA_TAPSIGHASH_CTX); |
| 777 | + if (item) { |
| 778 | + /* Note we cached the intial sha256_ctx itself here and so memcpy it */ |
| 779 | + memcpy(&io->ctx, item->value, item->value_len); |
| 780 | + return; |
| 781 | + } |
770 | 782 | } |
771 | 783 |
|
772 | 784 | tagged_hash_init(&io->ctx, TAPSIGHASH_SHA256(genesis_blockhash != NULL), SHA256_LEN); |
773 | 785 | if (genesis_blockhash) { |
774 | 786 | hash_bytes(&io->ctx, genesis_blockhash, genesis_blockhash_len); |
775 | 787 | hash_bytes(&io->ctx, genesis_blockhash, genesis_blockhash_len); |
776 | 788 | } |
777 | | - if (io->cache) |
| 789 | + if (TXIO_CTX_CACHEABLE && io->cache) |
778 | 790 | wally_map_add_integer(io->cache, TXIO_SHA_TAPSIGHASH_CTX, |
779 | 791 | (const unsigned char*)&io->ctx, sizeof(io->ctx)); |
780 | 792 | } |
|
0 commit comments