]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
test: extend keys unit test
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 19 Sep 2019 15:47:53 +0000 (17:47 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 24 Sep 2019 14:39:49 +0000 (16:39 +0200)
test/unit/keys.c

index ac995fad5c1c5603bbf399e49435107661db5562..a7873388f28c20779edd99e9dfa21281a8a2039e 100644 (file)
 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");