aboutsummaryrefslogtreecommitdiffstats
path: root/libkeccak_state_marshal.c
diff options
context:
space:
mode:
Diffstat (limited to 'libkeccak_state_marshal.c')
-rw-r--r--libkeccak_state_marshal.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/libkeccak_state_marshal.c b/libkeccak_state_marshal.c
index 00b54cc..c4ce7f6 100644
--- a/libkeccak_state_marshal.c
+++ b/libkeccak_state_marshal.c
@@ -6,7 +6,7 @@
* Marshal a `struct libkeccak_state` into a buffer
*
* @param state The state to marshal
- * @param data The output buffer
+ * @param data The output buffer, can be `NULL`
* @return The number of bytes stored to `data`
*/
size_t
@@ -14,20 +14,22 @@ libkeccak_state_marshal(const struct libkeccak_state *restrict state, void *rest
{
#define set(type, var) *((type *)data) = state->var, data += sizeof(type) / sizeof(char)
unsigned char *restrict data = data_;
- set(long int, r);
- set(long int, c);
- set(long int, n);
- set(long int, b);
- set(long int, w);
- set(int64_t, wmod);
- set(long int, l);
- set(long int, nr);
- memcpy(data, state->S, sizeof(state->S));
- data += sizeof(state->S) / sizeof(char);
- set(size_t, mptr);
- set(size_t, mlen);
- memcpy(data, state->M, state->mptr * sizeof(char));
- data += state->mptr;
+ if (data) {
+ set(long int, r);
+ set(long int, c);
+ set(long int, n);
+ set(long int, b);
+ set(long int, w);
+ set(int64_t, wmod);
+ set(long int, l);
+ set(long int, nr);
+ memcpy(data, state->S, sizeof(state->S));
+ data += sizeof(state->S) / sizeof(char);
+ set(size_t, mptr);
+ set(size_t, mlen);
+ memcpy(data, state->M, state->mptr * sizeof(char));
+ data += state->mptr;
+ }
return sizeof(struct libkeccak_state) - sizeof(char *) + state->mptr * sizeof(char);
#undef set
}