Shabal256 code explanation

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];
}

Hanoosh

Posted 2015-08-29T01:49:27.893

Reputation: 13

Out of curiosity, where'd you find this?Nick ODell 2015-08-29T05:15:16.033

@NickODell this can be found in most alt-coins that uses sphlibHanoosh 2015-08-29T08:02:41.560

Answers

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.

Nick ODell

Posted 2015-08-29T01:49:27.893

Reputation: 26 536