Allow quoted ASCII strings as input for AEAD regress.
authorjsing <jsing@openbsd.org>
Sat, 30 Jul 2022 16:12:40 +0000 (16:12 +0000)
committerjsing <jsing@openbsd.org>
Sat, 30 Jul 2022 16:12:40 +0000 (16:12 +0000)
Currently, each line in the text file is expected to be string of
hexadecimal digits. In addition to this, allow a line to be given as an
quoted ASCII string.

regress/lib/libcrypto/aead/aeadtest.c

index a6a2673..da23343 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: aeadtest.c,v 1.17 2022/07/30 14:49:15 jsing Exp $     */
+/*     $OpenBSD: aeadtest.c,v 1.18 2022/07/30 16:12:40 jsing Exp $     */
 /*
  * Copyright (c) 2014, Google Inc.
  *
@@ -306,31 +306,52 @@ main(int argc, char **argv)
                        continue;
                }
 
-               for (j = 0; line[i] != 0 && line[i] != '\n'; i++) {
-                       unsigned char v, v2;
-                       v = hex_digit(line[i++]);
-                       if (line[i] == 0 || line[i] == '\n') {
-                               fprintf(stderr, "Odd-length hex data on "
-                                   "line %u\n", line_no);
-                               return 3;
+               if (line[i] == '"') {
+                       i++;
+                       for (j = 0; line[i] != 0 && line[i] != '\n'; i++) {
+                               if (line[i] == '"')
+                                       break;
+                               if (j == BUF_MAX) {
+                                       fprintf(stderr, "Too much data on "
+                                           "line %u (max is %u bytes)\n",
+                                           line_no, (unsigned) BUF_MAX);
+                                       return 3;
+                               }
+                               buf[j++] = line[i];
+                               *buf_len = *buf_len + 1;
                        }
-                       v2 = hex_digit(line[i]);
-                       if (v > 15 || v2 > 15) {
-                               fprintf(stderr, "Invalid hex char on line %u\n",
+                       if (line[i + 1] != 0 && line[i + 1] != '\n') {
+                               fprintf(stderr, "Trailing data on line %u\n",
                                    line_no);
                                return 3;
                        }
-                       v <<= 4;
-                       v |= v2;
-
-                       if (j == BUF_MAX) {
-                               fprintf(stderr, "Too much hex data on line %u "
-                                   "(max is %u bytes)\n",
-                                   line_no, (unsigned) BUF_MAX);
-                               return 3;
+               } else {
+                       for (j = 0; line[i] != 0 && line[i] != '\n'; i++) {
+                               unsigned char v, v2;
+                               v = hex_digit(line[i++]);
+                               if (line[i] == 0 || line[i] == '\n') {
+                                       fprintf(stderr, "Odd-length hex data "
+                                           "on line %u\n", line_no);
+                                       return 3;
+                               }
+                               v2 = hex_digit(line[i]);
+                               if (v > 15 || v2 > 15) {
+                                       fprintf(stderr, "Invalid hex char on "
+                                           "line %u\n", line_no);
+                                       return 3;
+                               }
+                               v <<= 4;
+                               v |= v2;
+
+                               if (j == BUF_MAX) {
+                                       fprintf(stderr, "Too much hex data on "
+                                           "line %u (max is %u bytes)\n",
+                                           line_no, (unsigned) BUF_MAX);
+                                       return 3;
+                               }
+                               buf[j++] = v;
+                               *buf_len = *buf_len + 1;
                        }
-                       buf[j++] = v;
-                       *buf_len = *buf_len + 1;
                }
        }