aboutsummaryrefslogtreecommitdiffstats
path: root/libkeccak_state_marshal.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-02-12 18:46:12 +0100
committerMattias Andrée <maandree@kth.se>2019-02-12 18:46:12 +0100
commit47139985115e175ed9c3f7d648d6d9ec7c48b89b (patch)
tree846111020e7a2bb3bcd85cf00ceb158d07dc0c28 /libkeccak_state_marshal.c
parentUpdate makefile (diff)
downloadlibkeccak-47139985115e175ed9c3f7d648d6d9ec7c48b89b.tar.gz
libkeccak-47139985115e175ed9c3f7d648d6d9ec7c48b89b.tar.bz2
libkeccak-47139985115e175ed9c3f7d648d6d9ec7c48b89b.tar.xz
Deprecate libkeccak_{state,hmac}_{unmarshal_skip,marshal_size} and replace with the functions without the _skip or _size suffix
Signed-off-by: Mattias Andrée <maandree@kth.se>
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
}