1

Can anyone please explain the code below with comments?

What are pbegin & pend ?

What is ( I believe it is data, where it comes from ?): (pbegin == pend ? pblank : static_cast<const void*>(&pbegin[0]))

What is (I believe it is the size of data 80?) : (pend - pbegin) * sizeof(pbegin[0])

What is : pblank[1]

template<typename T1>
inline uint256 HashShabal(const T1 pbegin, const T1 pend)
{    
    sph_shabal256_context ctx_shabal;
    static unsigned char pblank[1];
    uint256 hash[1];
    sph_shabal256_init(&ctx_shabal);
    // ZSHABAL;
    sph_shabal256 (&ctx_shabal, (pbegin == pend ? pblank : static_cast<const void*>(&pbegin[0])), (pend - pbegin) * sizeof(pbegin[0]));
    sph_shabal256_close(&ctx_shabal, static_cast<void*>(&hash[0]));

    return hash[0];
}
  • Out of curiosity, where'd you find this? – Nick ODell Aug 29 '15 at 5:15
  • @NickODell this can be found in most alt-coins that uses sphlib – Hanoosh Aug 29 '15 at 8:02
0

What are pbegin & pend ?

Pointers to the beginning of the data and one byte past the end of the data, respectively. The function it's wrapping takes a pointer to the beginning plus the the size, so it needs to do some math with the pointers.

What is (I believe it is data, where it comes from ?)

Presumably, if you found this code in a Bitcoin derivative, the data is a block header. This function might also be used to build a merkle tree. (Shabal256 appears to be fast enough for that.)

What is : pblank[1]

A zero-length string. Presumably, sometimes this function gets called as HashShabal(NULL, NULL), so this is for avoiding a null pointer exception.

Can anyone please explain the code below with comments?

The purpose of this function appears to be to wrap the Shabal256 functions from Projet RNRT SAPHIR to make them easier to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.