<p>Let's disect this function call:</p>

<p><code>void sha256(struct sha256 *sha, const void *p, size_t size)</code></p>

<p>First we realize that the return value is <code>void</code> which means the function does not return the sha256 of the data. However we see that the first argument <code>struct sha256 *sha</code> is a pointer to a <code>sha256 struct</code> with the name <code>sha</code>. This suggests that the pointer that we pass to the function will afterwards contain the computed hash. </p>

<p>The second argument <code>const void *p</code> is a constant void pointer. This means that the function does not care about the data type of the data for which it computes the hash and it will not be able to modify the memory to which the pointer points to. This makes sense when we want to compute the hash of some data we don't want this data to be changed. Also computing the hash is a binary operation which is possible on the binary representation of any datatype. </p>

<p>This brings us to the third argument <code>size_t size</code> which is supposed to be the size of the data the second argument points to. I assume there is somewhere a <code>typedef</code> statement defining <code>size_t</code> as an integer. As the second argument is just a pointer to the data struct for which to compute the hash the function needs to know how much memory to process.</p>

CC BY-SA 4.0
2019-06-02T14:33:40.777Z
The declaration for this function is at https://github.com/ElementsProject/lightning/blob/50efe34e3b247def991cd6bdd03deee1ce7d1b85/ccan/ccan/crypto/sha256/sha256.h#L29, and confirms Rene's answer, if that were needed...
X. N.
CC BY-SA 4.0
2019-05-31T09:08:13.630Z
2019-05-31T09:08:13.630Z
Rene Pickhardt
<pre><code>void sha256(struct sha256 *sha, const void *p, size_t size)
{
    struct sha256_ctx ctx;

    sha256_init(&amp;ctx);
    sha256_update(&amp;ctx, p, size);
    sha256_done(&amp;ctx, sha);
}
</code></pre>

<p>I'm trying to call this function in c-lightning but I'm confused to what the function arguments are.</p>

<cryptography><sha256><core-lightning>
What are the 3 arguments called in function SHA256?
kcalvinalvin
# What are the 3 arguments called in function SHA256?

(Asked by: username_0 on 2019-05-31)

```
void sha256(struct sha256 *sha, const void *p, size_t size)
{
    struct sha256_ctx ctx;

    sha256_init(&ctx);
    sha256_update(&ctx, p, size);
    sha256_done(&ctx, sha);
}

```

I'm trying to call this function in c-lightning but I'm confused to what the function arguments are.

**Tags:** cryptography, sha256, core-lightning


---

## 1 answers

### Answer by username_1 on 2019-05-31. Score: 7 | Accepted answer

Let's disect this function call:

`void sha256(struct sha256 *sha, const void *p, size_t size)`

First we realize that the return value is `void` which means the function does not return the sha256 of the data. However we see that the first argument `struct sha256 *sha` is a pointer to a `sha256 struct` with the name `sha`. This suggests that the pointer that we pass to the function will afterwards contain the computed hash.

The second argument `const void *p` is a constant void pointer. This means that the function does not care about the data type of the data for which it computes the hash and it will not be able to modify the memory to which the pointer points to. This makes sense when we want to compute the hash of some data we don't want this data to be changed. Also computing the hash is a binary operation which is possible on the binary representation of any datatype.

This brings us to the third argument `size_t size` which is supposed to be the size of the data the second argument points to. I assume there is somewhere a `typedef` statement defining `size_t` as an integer. As the second argument is just a pointer to the data struct for which to compute the hash the function needs to know how much memory to process.

> **Comments:**
> **username_2**: The declaration for this function is at https://github.com/ElementsProject/lightning/blob/50efe34e3b247def991cd6bdd03deee1ce7d1b85/ccan/ccan/crypto/sha256/sha256.h#L29, and confirms username_1's answer, if that were needed...  

---

