xref: /illumos-gate/usr/src/test/crypto-tests/tests/digest/data/convert.gawk (revision 4d9fdb46b215739778ebc12079842c9905586999)
1#!/usr/bin/gawk
2
3# Copyright 2020 Oxide Computer Company
4
5# Converts the MD5 test vectors into the same format as the SHA ones
6# usage: gawk -f convert.awk byte-hashes.md5
7
8BEGIN {
9	filenum = 0;
10}
11
12$2 == "^" {
13	filename = sprintf("byte%04d.dat", filenum);
14	# od -An -t x1 -w200000 < <file>  | sed -e 's/ //g'
15	cmd = sprintf("sh -c \"od -An -t x1 -w200000 < %s | sed -e 's/ //g'\"", filename);
16	cmd |& getline bindata
17	binlen = length(bindata) / 2;
18	if (binlen == 0) {
19		bindata = "00"
20	}
21	printf("Len = %d\n", binlen * 8);
22	printf("Msg = %s\n", bindata);
23	printf("MD = %s\n\n", tolower($1));
24	filenum++;
25}
26