Skip to content

Commit 7d55601

Browse files
committed
ethash: Expose hash() function in C API
1 parent 83fdaab commit 7d55601

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

include/ethash/ethash.h

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ const struct ethash_epoch_context* ethash_get_global_epoch_context(int epoch_num
113113
const struct ethash_epoch_context_full* ethash_get_global_epoch_context_full(
114114
int epoch_number) NOEXCEPT;
115115

116+
117+
struct ethash_result ethash_hash(const struct ethash_epoch_context* context,
118+
const union ethash_hash256* header_hash, uint64_t nonce) NOEXCEPT;
119+
116120
#ifdef __cplusplus
117121
}
118122
#endif

include/ethash/ethash.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ inline epoch_context_full_ptr create_epoch_context_full(int epoch_number) noexce
120120
}
121121

122122

123-
result hash(const epoch_context& context, const hash256& header_hash, uint64_t nonce) noexcept;
123+
inline result hash(
124+
const epoch_context& context, const hash256& header_hash, uint64_t nonce) noexcept
125+
{
126+
return ethash_hash(&context, &header_hash, nonce);
127+
}
124128

125129
result hash(const epoch_context_full& context, const hash256& header_hash, uint64_t nonce) noexcept;
126130

lib/ethash/ethash.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,6 @@ inline hash256 hash_kernel(
303303
}
304304
} // namespace
305305

306-
result hash(const epoch_context& context, const hash256& header_hash, uint64_t nonce) noexcept
307-
{
308-
const hash512 seed = hash_seed(header_hash, nonce);
309-
const hash256 mix_hash = hash_kernel(context, seed, calculate_dataset_item_1024);
310-
return {hash_final(seed, mix_hash), mix_hash};
311-
}
312-
313306
result hash(const epoch_context_full& context, const hash256& header_hash, uint64_t nonce) noexcept
314307
{
315308
static const auto lazy_lookup = [](const epoch_context& ctx, uint32_t index) noexcept
@@ -438,4 +431,12 @@ void ethash_destroy_epoch_context(epoch_context* context) noexcept
438431
std::free(context);
439432
}
440433

434+
ethash_result ethash_hash(
435+
const epoch_context* context, const hash256* header_hash, uint64_t nonce) noexcept
436+
{
437+
const hash512 seed = hash_seed(*header_hash, nonce);
438+
const hash256 mix_hash = hash_kernel(*context, seed, calculate_dataset_item_1024);
439+
return {hash_final(seed, mix_hash), mix_hash};
440+
}
441+
441442
} // extern "C"

0 commit comments

Comments
 (0)