aboutsummaryrefslogtreecommitdiffstats
path: root/libkeccak_state_marshal.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libkeccak_state_marshal.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/libkeccak_state_marshal.c b/libkeccak_state_marshal.c
index e4d2efa..6563038 100644
--- a/libkeccak_state_marshal.c
+++ b/libkeccak_state_marshal.c
@@ -17,24 +17,30 @@
size_t
libkeccak_state_marshal(const struct libkeccak_state *restrict state, void *restrict data_)
{
-#define set(type, var) *((type *)data) = state->var, data += sizeof(type)
- unsigned char *restrict data = data_;
- 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);
- set(size_t, mptr);
- set(size_t, mlen);
- memcpy(data, state->M, state->mptr * sizeof(char));
- data += state->mptr;
+#define set(type, var) *(type *)data = state->var, data += sizeof(type)
+ unsigned char *restrict start = data_;
+ unsigned char *restrict data = start;
+ if (!data) {
+ return 7 * sizeof(long int) +
+ 1 * sizeof(int64_t) +
+ sizeof(state->S) +
+ 2 * sizeof(size_t) +
+ state->mptr;
}
- return sizeof(struct libkeccak_state) - sizeof(char *) + state->mptr * sizeof(char);
+ 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);
+ set(size_t, mptr);
+ set(size_t, mlen);
+ memcpy(data, state->M, state->mptr * sizeof(char));
+ data += state->mptr;
+ return (size_t)(data - start);
#undef set
}