bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2014-2018 Dovecot authors, see the included COPYING file */
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen#include "test-lib.h"
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen#include "mmap-util.h"
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen#include "hash-method.h"
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
1b6228f23fb87733da13ac1057cf70fe513d30a0Timo Sirainen#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
1b6228f23fb87733da13ac1057cf70fe513d30a0Timo Sirainen# define MAP_ANONYMOUS MAP_ANON
1b6228f23fb87733da13ac1057cf70fe513d30a0Timo Sirainen#endif
1b6228f23fb87733da13ac1057cf70fe513d30a0Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainenstatic unsigned char *buf;
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainenstatic unsigned int buf_size;
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainenstatic void test_hash_method_one(const struct hash_method *method)
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen{
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen unsigned char *ctx, *digest;
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen unsigned int i;
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen test_begin(t_strdup_printf("hash method %s", method->name));
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen ctx = i_malloc(method->context_size);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen digest = i_malloc(method->digest_size);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen method->init(ctx);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen /* make sure the code doesn't try to access data past boundaries */
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen for (i = 0; i < buf_size; i++)
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen method->loop(ctx, buf + buf_size - i, i);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen method->result(ctx, digest);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen i_free(ctx);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen i_free(digest);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen test_end();
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen}
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomistatic void test_hash_method_boundary(void)
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen{
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen unsigned int i;
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen buf_size = mmap_get_page_size();
1b6228f23fb87733da13ac1057cf70fe513d30a0Timo Sirainen#ifdef MAP_ANONYMOUS
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen buf = mmap(NULL, buf_size*2, PROT_READ | PROT_WRITE,
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen mprotect(buf + buf_size, buf_size, PROT_NONE);
1b6228f23fb87733da13ac1057cf70fe513d30a0Timo Sirainen#else
1b6228f23fb87733da13ac1057cf70fe513d30a0Timo Sirainen buf = i_malloc(buf_size);
1b6228f23fb87733da13ac1057cf70fe513d30a0Timo Sirainen#endif
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen memset(buf, 0, buf_size);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen for (i = 0; hash_methods[i] != NULL; i++)
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen test_hash_method_one(hash_methods[i]);
b0114f9348060796a29a9042af757e8f99cdd422Timo Sirainen}
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomistatic void test_hash_methods_fips() {
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi const char *last_method = NULL;
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi struct {
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi const char *method;
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi const void *input;
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi size_t ilen;
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi size_t rounds;
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi const void *output;
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi size_t olen;
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi } test_vectors[] =
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi {
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "md4",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 0,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 128 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "md4",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "abc",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 3,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa4\x48\x01\x7a\xaf\x21\xd8\x52"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 128 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "md4",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "ghijklmnopqrstuvwxyz0123456789",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 62,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x04\x3f\x85\x82\xf2\x41\xdb\x35"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 128 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "md5",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 0,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe9\x80\x09\x98\xec\xf8\x42\x7e",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 128 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "md5",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "abc",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 3,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x90\x01\x50\x98\x3c\xd2\x4f\xb0"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 128 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "md5",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "ghijklmnopqrstuvwxyz0123456789",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 62,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xd1\x74\xab\x98\xd2\x77\xd9\xf5"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 128 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha1",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 0,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xda\x39\xa3\xee\x5e\x6b\x4b\x0d"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x32\x55\xbf\xef\x95\x60\x18\x90"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xaf\xd8\x07\x09",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 160 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha1",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "abc",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 3,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa9\x99\x3e\x36\x47\x06\x81\x6a"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xba\x3e\x25\x71\x78\x50\xc2\x6c"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x9c\xd0\xd8\x9d",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 160 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha1",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "abcdbcdecdefdefgefghfghighijhijk"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "ijkljklmklmnlmnomnopnopq",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 56,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xba\xae\x4a\xa1\xf9\x51\x29\xe5"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe5\x46\x70\xf1",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 160 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha3-256",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 0,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x51\xc1\x47\x56\xa0\x61\xd6\x62"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xf5\x80\xff\x4d\xe4\x3b\x49\xfa"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x82\xd8\x0a\x4b\x80\xf8\x43\x4a",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 256 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha3-256",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xb7\x71\xd5\xce\xf5\xd1\xa4\x1a"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x93\xd1\x56\x43\xd7\x18\x1d\x2a"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x2e\xf0\xa8\xe8\x4d\x91\x81\x2f"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x20\xed\x21\xf1\x47\xbe\xf7\x32"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xbf\x3a\x60\xef\x40\x67\xc3\x73"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x4b\x85\xbc\x8c\xd4\x71\x78\x0f"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x10\xdc\x9e\x82\x91\xb5\x83\x39"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa6\x77\xb9\x60\x21\x8f\x71\xe7"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x93\xf2\x79\x7a\xea\x34\x94\x06"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x51\x28\x29\x06\x5d\x37\xbb\x55"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xea\x79\x6f\xa4\xf5\x6f\xd8\x89"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x6b\x49\xb2\xcd\x19\xb4\x32\x15"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xad\x96\x7c\x71\x2b\x24\xe5\x03"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x2d\x06\x52\x32\xe0\x2c\x12\x74"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x09\xd2\xed\x41\x46\xb9\xd7\x5d"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x76\x3d\x52\xdb\x98\xd9\x49\xd3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xb0\xfe\xd6\xa8\x05\x2f\xbb",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1080 / 8,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa1\x9e\xee\x92\xbb\x20\x97\xb6"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x4e\x82\x3d\x59\x77\x98\xaa\x18"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xbe\x9b\x7c\x73\x6b\x80\x59\xab"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xfd\x67\x79\xac\x35\xac\x81\xb5",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 256 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha3-256",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 200,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x79\xf3\x8a\xde\xc5\xc2\x03\x07"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa9\x8e\xf7\x6e\x83\x24\xaf\xbf"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xd4\x6c\xfd\x81\xb2\x2e\x39\x73"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xc6\x5f\xa1\xbd\x9d\xe3\x17\x87",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 256 / 8,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha3-256",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 200,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x79\xf3\x8a\xde\xc5\xc2\x03\x07"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa9\x8e\xf7\x6e\x83\x24\xaf\xbf"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xd4\x6c\xfd\x81\xb2\x2e\x39\x73"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xc6\x5f\xa1\xbd\x9d\xe3\x17\x87",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 256 / 8,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha3-512",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 0,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xc8\xb5\x67\xdc\x18\x5a\x75\x6e"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x97\xc9\x82\x16\x4f\xe2\x58\x59"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe0\xd1\xdc\xc1\x47\x5c\x80\xa6"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x15\xb2\x12\x3a\xf1\xf5\xf9\x4c"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x11\xe3\xe9\x40\x2c\x3a\xc5\x58"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xf5\x00\x19\x9d\x95\xb6\xd3\xe3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x01\x75\x85\x86\x28\x1d\xcd\x26",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 512 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha3-512",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xb7\x71\xd5\xce\xf5\xd1\xa4\x1a"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x93\xd1\x56\x43\xd7\x18\x1d\x2a"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x2e\xf0\xa8\xe8\x4d\x91\x81\x2f"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x20\xed\x21\xf1\x47\xbe\xf7\x32"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xbf\x3a\x60\xef\x40\x67\xc3\x73"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x4b\x85\xbc\x8c\xd4\x71\x78\x0f"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x10\xdc\x9e\x82\x91\xb5\x83\x39"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa6\x77\xb9\x60\x21\x8f\x71\xe7"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x93\xf2\x79\x7a\xea\x34\x94\x06"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x51\x28\x29\x06\x5d\x37\xbb\x55"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xea\x79\x6f\xa4\xf5\x6f\xd8\x89"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x6b\x49\xb2\xcd\x19\xb4\x32\x15"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xad\x96\x7c\x71\x2b\x24\xe5\x03"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x2d\x06\x52\x32\xe0\x2c\x12\x74"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x09\xd2\xed\x41\x46\xb9\xd7\x5d"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x76\x3d\x52\xdb\x98\xd9\x49\xd3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xb0\xfe\xd6\xa8\x05\x2f\xbb",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1080 / 8,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x75\x75\xa1\xfb\x4f\xc9\xa8\xf9"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xc0\x46\x6b\xd5\xfc\xa4\x96\xd1"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xcb\x78\x69\x67\x73\xa2\x12\xa5"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xf6\x2d\x02\xd1\x4e\x32\x59\xd1"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x92\xa8\x7e\xba\x44\x07\xdd\x83"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x89\x35\x27\x33\x14\x07\xb6\xda"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xda\xad\x92\x0d\xbc\x46\x48\x9b"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x67\x74\x93\xce\x5f\x20\xb5\x95",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 512 / 8
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha3-512",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3\xa3\xa3\xa3\xa3\xa3\xa3\xa3",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 200,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe7\x6d\xfa\xd2\x20\x84\xa8\xb1"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x46\x7f\xcf\x2f\xfa\x58\x36\x1b"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xec\x76\x28\xed\xf5\xf3\xfd\xc0"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe4\x80\x5d\xc4\x8c\xae\xec\xa8"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x1b\x7c\x13\xc3\x0a\xdf\x52\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x65\x95\x84\x73\x9a\x2d\xf4\x6b"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe5\x89\xc5\x1c\xa1\xa4\xa8\x41"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x6d\xf6\x54\x5a\x1c\xe8\xba\x00",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 512 / 8,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi { "sha3-512",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xa3",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 1,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 200,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe7\x6d\xfa\xd2\x20\x84\xa8\xb1"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x46\x7f\xcf\x2f\xfa\x58\x36\x1b"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xec\x76\x28\xed\xf5\xf3\xfd\xc0"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe4\x80\x5d\xc4\x8c\xae\xec\xa8"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x1b\x7c\x13\xc3\x0a\xdf\x52\xa3"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x65\x95\x84\x73\x9a\x2d\xf4\x6b"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\xe5\x89\xc5\x1c\xa1\xa4\xa8\x41"
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi "\x6d\xf6\x54\x5a\x1c\xe8\xba\x00",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi 512 / 8,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi },
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi };
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi for(size_t i = 0; i < N_ELEMENTS(test_vectors); i++) {
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi if (last_method == NULL ||
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi strcmp(last_method, test_vectors[i].method) != 0) {
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi if (last_method != NULL)
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_end();
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi last_method = test_vectors[i].method;
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_begin(t_strdup_printf("hash method %s (test vectors)",
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi last_method));
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi }
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi const struct hash_method *method =
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi hash_method_lookup(test_vectors[i].method);
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi unsigned char context[method->context_size];
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi unsigned char result[method->digest_size];
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_assert_idx(method->digest_size == test_vectors[i].olen, i);
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi method->init(context);
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi for(size_t n = 0; n < test_vectors[i].rounds; n++)
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi method->loop(context, test_vectors[i].input,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_vectors[i].ilen);
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi method->result(context, result);
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_assert_idx(memcmp(result, test_vectors[i].output,
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_vectors[i].olen) == 0, i);
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi }
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_end();
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi}
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomivoid test_hash_method(void)
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi{
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_hash_method_boundary();
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi test_hash_methods_fips();
4217dcdec011f674ff30613ba3add9418db07d58Aki Tuomi}