From: Miroslav Lichvar Date: Thu, 19 Sep 2019 15:47:53 +0000 (+0200) Subject: test: extend keys unit test X-Git-Tag: 4.0-pre1~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8be384cdf97c852eed78c2ad26c6c0b1b29ef56;p=thirdparty%2Fchrony.git test: extend keys unit test --- diff --git a/test/unit/keys.c b/test/unit/keys.c index ac995fad..a7873388 100644 --- a/test/unit/keys.c +++ b/test/unit/keys.c @@ -27,39 +27,51 @@ static uint32_t write_random_key(FILE *f) { - const char *hash_name; + const char *type, *prefix; char key[128]; uint32_t id; int i, length; length = random() % sizeof (key) + 1; length = MAX(length, 4); - UTI_GetRandomBytes(&id, sizeof (id)); - UTI_GetRandomBytes(key, length); + prefix = random() % 2 ? "HEX:" : ""; - switch (random() % 6) { + switch (random() % 8) { #ifdef FEAT_SECHASH case 0: - hash_name = "SHA1"; + type = "SHA1"; break; case 1: - hash_name = "SHA256"; + type = "SHA256"; break; case 2: - hash_name = "SHA384"; + type = "SHA384"; break; case 3: - hash_name = "SHA512"; + type = "SHA512"; break; #endif +#ifdef HAVE_CMAC case 4: - hash_name = "MD5"; + type = "AES128"; + length = prefix[0] == '\0' ? 8 : 16; + break; + case 5: + type = "AES256"; + length = prefix[0] == '\0' ? 16 : 32; + break; +#endif + case 6: + type = "MD5"; break; default: - hash_name = ""; + type = ""; } - fprintf(f, "%u %s %s", id, hash_name, random() % 2 ? "HEX:" : ""); + UTI_GetRandomBytes(&id, sizeof (id)); + UTI_GetRandomBytes(key, length); + + fprintf(f, "%u %s %s", id, type, prefix); for (i = 0; i < length; i++) fprintf(f, "%02hhX", key[i]); fprintf(f, "\n");