Skip to content

Commit

Permalink
ethash: Expose hash() function in C API
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jun 11, 2019
1 parent 83fdaab commit 7d55601
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions include/ethash/ethash.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ const struct ethash_epoch_context* ethash_get_global_epoch_context(int epoch_num
const struct ethash_epoch_context_full* ethash_get_global_epoch_context_full(
int epoch_number) NOEXCEPT;


struct ethash_result ethash_hash(const struct ethash_epoch_context* context,
const union ethash_hash256* header_hash, uint64_t nonce) NOEXCEPT;

#ifdef __cplusplus
}
#endif
6 changes: 5 additions & 1 deletion include/ethash/ethash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ inline epoch_context_full_ptr create_epoch_context_full(int epoch_number) noexce
}


result hash(const epoch_context& context, const hash256& header_hash, uint64_t nonce) noexcept;
inline result hash(
const epoch_context& context, const hash256& header_hash, uint64_t nonce) noexcept
{
return ethash_hash(&context, &header_hash, nonce);
}

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

Expand Down
15 changes: 8 additions & 7 deletions lib/ethash/ethash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,6 @@ inline hash256 hash_kernel(
}
} // namespace

result hash(const epoch_context& context, const hash256& header_hash, uint64_t nonce) noexcept
{
const hash512 seed = hash_seed(header_hash, nonce);
const hash256 mix_hash = hash_kernel(context, seed, calculate_dataset_item_1024);
return {hash_final(seed, mix_hash), mix_hash};
}

result hash(const epoch_context_full& context, const hash256& header_hash, uint64_t nonce) noexcept
{
static const auto lazy_lookup = [](const epoch_context& ctx, uint32_t index) noexcept
Expand Down Expand Up @@ -438,4 +431,12 @@ void ethash_destroy_epoch_context(epoch_context* context) noexcept
std::free(context);
}

ethash_result ethash_hash(
const epoch_context* context, const hash256* header_hash, uint64_t nonce) noexcept
{
const hash512 seed = hash_seed(*header_hash, nonce);
const hash256 mix_hash = hash_kernel(*context, seed, calculate_dataset_item_1024);
return {hash_final(seed, mix_hash), mix_hash};
}

} // extern "C"

0 comments on commit 7d55601

Please sign in to comment.