<blockquote>
  <p>What are pbegin &amp; pend ?</p>
</blockquote>

<p>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.</p>

<blockquote>
  <p>What is (I believe it is data, where it comes from ?)</p>
</blockquote>

<p>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.)</p>

<blockquote>
  <p>What is : <code>pblank[1]</code></p>
</blockquote>

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

<blockquote>
  <p>Can anyone please explain the code below with comments?</p>
</blockquote>

<p>The purpose of this function appears to be to wrap the Shabal256 functions from <a href="http://www.saphir2.com/sphlib/" rel="nofollow">Projet RNRT SAPHIR</a> to make them easier to use.</p>

CC BY-SA 3.0
2015-08-29T03:38:46.800Z
2015-08-29T03:38:46.800Z
Nick ODell
<p>Can anyone please explain the code below with comments?</p>

<p>What are <code>pbegin</code> &amp; <code>pend</code> ?</p>

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

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

<p>What is : <code>pblank[1]</code></p>

<pre><code>template&lt;typename T1&gt;
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(&amp;ctx_shabal);
    // ZSHABAL;
    sph_shabal256 (&amp;ctx_shabal, (pbegin == pend ? pblank : static_cast&lt;const void*&gt;(&amp;pbegin[0])), (pend - pbegin) * sizeof(pbegin[0]));
    sph_shabal256_close(&amp;ctx_shabal, static_cast&lt;void*&gt;(&amp;hash[0]));

    return hash[0];
}
</code></pre>

CC BY-SA 3.0
2015-08-29T05:15:16.033Z
Out of curiosity, where'd you find this?
Nick ODell
CC BY-SA 3.0
2015-08-29T08:02:41.560Z
@NickODell this can be found in most alt-coins that uses sphlib
Hanoosh
<block><hash><algorithms>
Shabal256 code explanation
Hanoosh
# Shabal256 code explanation

(Asked by: username_0 on 2015-08-29)

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(&pbegin[0]))
What is (I believe it is the size of data 80?) : (pend - pbegin) * sizeof(pbegin[0])
What is : pblank[1]
template
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(&pbegin[0])), (pend - pbegin) * sizeof(pbegin[0]));
    sph_shabal256_close(&ctx_shabal, static_cast(&hash[0]));

    return hash[0];
}

**Tags:** block, hash, algorithms

> **Comments:**
> **username_1**: Out of curiosity, where'd you find this?  
> **username_0**: @NickODell this can be found in most alt-coins that uses sphlib  

---

## 1 answers

### Answer by username_1 on 2015-08-29. Score: 0 | Accepted answer

> 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](http://www.saphir2.com/sphlib/) to make them easier to use.


---

