From 47139985115e175ed9c3f7d648d6d9ec7c48b89b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 12 Feb 2019 18:46:12 +0100 Subject: Deprecate libkeccak_{state,hmac}_{unmarshal_skip,marshal_size} and replace with the functions without the _skip or _size suffix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libkeccak_state_marshal.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'libkeccak_state_marshal.c') 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 } -- cgit v1.2.3-70-g09d2