symm/sha3.[ch]: Add support for SHA3 and related functions based on Keccak.
[catacomb] / symm / sha3-trans
diff --git a/symm/sha3-trans b/symm/sha3-trans
new file mode 100755 (executable)
index 0000000..3c3f68c
--- /dev/null
@@ -0,0 +1,56 @@
+#! /bin/sh
+
+prog=`echo $0 | sed 's:.*/::'`
+
+cat <<EOF
+# Test vectors for SHA3
+#
+# Generated on `date +%Y-%m-%d` by $prog
+
+EOF
+
+for i in "$@"; do
+  base=${i##*/}
+  case $base in
+    SHA3_*) tail=${base#SHA3_}; alg=sha3 sep=- hex=-hex ;;
+    SHAKE*) tail=${base#SHAKE}; alg=shake sep= hex= ;;
+    *) echo >&2 "$0: bad filename \`$i'"; exit 2 ;;
+  esac
+  case $tail in
+    *LongMsg.rsp) hack=kat; bits=${tail%LongMsg.rsp} ;;
+    *ShortMsg.rsp) hack=kat; bits=${tail%ShortMsg.rsp} ;;
+    *VariableOut.rsp) hack=kat; bits=${tail%VariableOut.rsp} ;;
+    *Monte.rsp) hack=mct; bits=${tail%Monte.rsp} ;;
+    *) echo >&2 "$0: bad filename \`$i'"; exit 2 ;;
+  esac
+
+  case $hack,$alg in
+    kat,*)
+      echo "$alg$sep$bits$hex {"
+      awk '
+       BEGIN { FS = "[ \t\r]+"; len = 8; }
+       /^Len = / { len = $3; }
+       /^Msg = / { msg = tolower($3); if (!len) msg = "\"\""; }
+       /^(MD|Output) = / {
+         h = tolower($3);
+         if (len%8 == 0) printf("  %s\n    %s;\n", msg, h);
+       }
+      ' <"$i"
+      echo "}"
+      ;;
+    mct,sha3)
+      echo "$alg$sep$bits-mct {"
+      awk '
+       BEGIN { FS = "[ \t\r]+"; }
+       BEGIN { prev = ""; }
+       /MD = / {
+         if (prev != "") printf("  1000\n    %s\n    %s;\n", prev, $3);
+         prev = $3;
+       }
+      ' <"$i"
+      echo "}"
+      ;;
+    *)
+      echo >&2 "$0: unsupported test kind $hack/$alg"; exit 2 ;;
+  esac
+done