libtomcrypt/tests/multi_test.c

226 lines
9.1 KiB
C
Raw Normal View History

2004-12-30 23:55:53 +00:00
/* test the multi helpers... */
2017-04-23 20:04:39 +00:00
#include <tomcrypt_test.h>
2004-12-30 23:55:53 +00:00
2017-04-23 20:04:39 +00:00
int multi_test(void)
2004-12-30 23:55:53 +00:00
{
unsigned char key[32] = { 0 };
unsigned char buf[2][MAXBLOCKSIZE];
2004-12-30 23:55:53 +00:00
unsigned long len, len2;
/* register algos */
register_hash(&sha256_desc);
register_cipher(&aes_desc);
/* HASH testing */
len = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
hash_memory(find_hash("sha256"), (unsigned char*)"hello", 5, buf[0], &len);
2004-12-30 23:55:53 +00:00
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"hello", 5, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL, 0);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
hash_memory_multi(find_hash("sha256"), buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
2017-04-23 16:50:37 +00:00
#ifdef LTC_HMAC
2004-12-30 23:55:53 +00:00
len = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
hmac_memory(find_hash("sha256"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
2004-12-30 23:55:53 +00:00
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
2017-04-23 16:50:37 +00:00
#endif
2004-12-30 23:55:53 +00:00
#ifdef LTC_OMAC
2004-12-30 23:55:53 +00:00
len = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
omac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
2004-12-30 23:55:53 +00:00
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
#endif
2004-12-30 23:55:53 +00:00
#ifdef LTC_PMAC
2004-12-30 23:55:53 +00:00
len = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
pmac_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
2004-12-30 23:55:53 +00:00
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
len2 = sizeof(buf[0]);
2006-06-18 01:37:50 +00:00
pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
2004-12-30 23:55:53 +00:00
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2004-12-30 23:55:53 +00:00
}
#endif
2004-12-30 23:55:53 +00:00
2017-04-23 16:50:37 +00:00
#ifdef LTC_XCBC
len = sizeof(buf[0]);
xcbc_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
len2 = sizeof(buf[0]);
xcbc_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = sizeof(buf[0]);
xcbc_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = sizeof(buf[0]);
xcbc_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
#endif
#ifdef LTC_F9
len = sizeof(buf[0]);
f9_memory(find_cipher("aes"), key, 16, (unsigned char*)"hello", 5, buf[0], &len);
len2 = sizeof(buf[0]);
f9_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = sizeof(buf[0]);
f9_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = sizeof(buf[0]);
f9_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
#endif
#ifdef LTC_PELICAN
/* TODO: there is no pelican_memory_multi(..) */
#endif
#ifdef LTC_POLY1305
len = sizeof(buf[0]);
poly1305_memory(key, 32, (unsigned char*)"hello", 5, buf[0], &len);
len2 = sizeof(buf[0]);
poly1305_memory_multi(key, 32, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = sizeof(buf[0]);
poly1305_memory_multi(key, 32, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = sizeof(buf[0]);
poly1305_memory_multi(key, 32, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
#endif
#ifdef LTC_BLAKE2SMAC
len = 32;
blake2smac_memory(key, 16, (unsigned char*)"hello", 5, buf[0], &len);
len2 = 32;
blake2smac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = 32;
blake2smac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = 32;
blake2smac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
#endif
#ifdef LTC_BLAKE2BMAC
len = 64;
blake2bmac_memory(key, 16, (unsigned char*)"hello", 5, buf[0], &len);
len2 = 64;
blake2bmac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"hello", 5, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = 64;
blake2bmac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"he", 2UL, "llo", 3UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
len2 = 64;
blake2bmac_memory_multi(key, 16, buf[1], &len2, (unsigned char*)"h", 1UL, "e", 1UL, "l", 1UL, "l", 1UL, "o", 1UL, NULL);
if (len != len2 || memcmp(buf[0], buf[1], len)) {
printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
2017-04-23 20:04:39 +00:00
return CRYPT_FAIL_TESTVECTOR;
2017-04-23 16:50:37 +00:00
}
#endif
2017-04-23 20:04:39 +00:00
return CRYPT_OK;
2004-12-30 23:55:53 +00:00
}