diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-05 16:55:39 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-05 16:55:39 +0100 |
commit | 0bb601e113bc543c9de648199a22337f8fdd6999 (patch) | |
tree | c9867a2d35544d275d1303a92cb4cdf38d569105 | |
parent | add sha3 test cases, they failed (diff) | |
download | libkeccak-0bb601e113bc543c9de648199a22337f8fdd6999.tar.gz libkeccak-0bb601e113bc543c9de648199a22337f8fdd6999.tar.bz2 libkeccak-0bb601e113bc543c9de648199a22337f8fdd6999.tar.xz |
m
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | src/test/test.c | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/src/test/test.c b/src/test/test.c index ac03bb0..d2009d6 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -68,6 +68,63 @@ static int test_hex(void) /** + * Test functions in <libkeccak/state.h> + * + * @param spec The specifications for the state + * @return Zero on success, -1 on error + */ +static int test_state(libkeccak_spec_t* restrict spec) +{ + libkeccak_state_t* restrict state; + libkeccak_state_t* restrict state2; + size_t marshal_size, marshalled_size, i, n; + char* restrict marshalled_data; + + if (state = libkeccak_state_create(spec), state == NULL) + return perror("libkeccak_state_initialise"), -1; + + n = state->mlen / 2; + for (i = 0; i < n; i++) + state->M[state->mptr++] = (char)(i & 255); + + if (state2 = libkeccak_state_duplicate(state), state2 == NULL) + return perror("libkeccak_state_duplicate"), -1; + + if (state->M[state->mptr - 1] != state2->M[state2->mptr - 1]) + return printf("Inconsistency found between original state and duplicate state.\n"), -1; + + marshal_size = libkeccak_state_marshal_size(state2); + if (marshalled_data = malloc(marshal_size), marshalled_data == NULL) + return perror("malloc"), -1; + + marshalled_size = libkeccak_state_marshal(state2, marshalled_data); + if (marshalled_size != marshal_size) + return printf("libkeccak_state_marshal returned an unexpected value.\n"), -1; + + libkeccak_state_free(state); + + if (state = malloc(sizeof(libkeccak_state_t)), state == NULL) + return perror("malloc"), -1; + marshalled_size = libkeccak_state_unmarshal(state, marshalled_data); + if (marshalled_size == 0) + return perror("libkeccak_state_unmarshal"), -1; + if (marshalled_size != marshal_size) + return printf("libkeccak_state_unmarshal returned an unexpected value.\n"), -1; + + if (libkeccak_state_unmarshal_skip(marshalled_data) != marshal_size) + return printf("libkeccak_state_unmarshal_skip returned an unexpected value.\n"), -1; + + if (state->M[state->mptr - 1] != state2->M[state2->mptr - 1]) + return printf("Inconsistency found between original state and unmarshalled state.\n"), -1; + + free(marshalled_data); + libkeccak_state_free(state); + libkeccak_state_free(state2); + return 0; +} + + +/** * Run a test case for `libkeccak_digest` * * @param spec The specification for the hashing @@ -144,63 +201,6 @@ static int test_digest(void) } -/** - * Test functions in <libkeccak/state.h> - * - * @param spec The specifications for the state - * @return Zero on success, -1 on error - */ -static int test_state(libkeccak_spec_t* restrict spec) -{ - libkeccak_state_t* restrict state; - libkeccak_state_t* restrict state2; - size_t marshal_size, marshalled_size, i, n; - char* restrict marshalled_data; - - if (state = libkeccak_state_create(spec), state == NULL) - return perror("libkeccak_state_initialise"), -1; - - n = state->mlen / 2; - for (i = 0; i < n; i++) - state->M[state->mptr++] = (char)(i & 255); - - if (state2 = libkeccak_state_duplicate(state), state2 == NULL) - return perror("libkeccak_state_duplicate"), -1; - - if (state->M[state->mptr - 1] != state2->M[state2->mptr - 1]) - return printf("Inconsistency found between original state and duplicate state.\n"), -1; - - marshal_size = libkeccak_state_marshal_size(state2); - if (marshalled_data = malloc(marshal_size), marshalled_data == NULL) - return perror("malloc"), -1; - - marshalled_size = libkeccak_state_marshal(state2, marshalled_data); - if (marshalled_size != marshal_size) - return printf("libkeccak_state_marshal returned an unexpected value.\n"), -1; - - libkeccak_state_free(state); - - if (state = malloc(sizeof(libkeccak_state_t)), state == NULL) - return perror("malloc"), -1; - marshalled_size = libkeccak_state_unmarshal(state, marshalled_data); - if (marshalled_size == 0) - return perror("libkeccak_state_unmarshal"), -1; - if (marshalled_size != marshal_size) - return printf("libkeccak_state_unmarshal returned an unexpected value.\n"), -1; - - if (libkeccak_state_unmarshal_skip(marshalled_data) != marshal_size) - return printf("libkeccak_state_unmarshal_skip returned an unexpected value.\n"), -1; - - if (state->M[state->mptr - 1] != state2->M[state2->mptr - 1]) - return printf("Inconsistency found between original state and unmarshalled state.\n"), -1; - - free(marshalled_data); - libkeccak_state_free(state); - libkeccak_state_free(state2); - return 0; -} - - int main(void) { libkeccak_generalised_spec_t gspec; |