diff options
author | Werner Koch <wk@gnupg.org> | 2011-06-13 12:28:03 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2011-06-13 12:32:29 +0200 |
commit | f796e9877e7e065b23dee68184e46a4307d9dfa9 (patch) | |
tree | 1c43f4fd81c45b39aec2fec1c0e6d83dfe6d3cdd /tests/pkcstv2c.awk | |
parent | caf4480811fffdf3b8677864e8d663a68f210e5c (diff) | |
download | libgcrypt-f796e9877e7e065b23dee68184e46a4307d9dfa9.tar.gz |
Add a full set of pkcs#1 v2 test vectors
For v1.5 we use somewhat unofficial test vectors we found on the
rsalabs FTP server. There is a little awk script which helped us to
convert them. All the test vectors are in separate files with C
tables to keep the actual test program readable.
We detected a few flaws in our pkcs1 implementation which will be
fixed with the next commit.
Diffstat (limited to 'tests/pkcstv2c.awk')
-rwxr-xr-x | tests/pkcstv2c.awk | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/pkcstv2c.awk b/tests/pkcstv2c.awk new file mode 100755 index 00000000..747f47db --- /dev/null +++ b/tests/pkcstv2c.awk @@ -0,0 +1,112 @@ +#! /usr/bin/awk -f +# pkcstv2c.awk - Convert pkcs1 test vectors into a C table. +# Copyright 2011 Free Software Foundation, Inc. +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This file is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# + +BEGIN { + in_key = 0; + in_item = 0; + in_number = 0; + no_comma = 0; + + printf " static struct {\n"; + printf " const char *desc;\n"; + printf " const char *n, *e, *d;\n"; + printf " struct {\n"; + printf " const char *desc;\n"; + printf " const char *mesg;\n"; + printf " const char *seed;\n"; + printf " const char *encr;\n"; + printf " } m[20];\n"; + printf " } tbl[] =\n"; + printf " {\n"; +} + +{ sub (/\r/,""); } + +/^# Public key/ { skip_pub = 1; } +/^# Private key/ { skip_pub = 0; } +skip_pub { next } + +in_number && ! /^[0-9a-f]/ { + if (in_number == 2) + printf "\""; + if (no_comma) + no_comma = 0; + else + printf "," + printf "\n"; + in_number = 0; +} + +in_number == 3 { + printf "\n"; + in_number = 1; +} + +in_number == 1 { + gsub (/ /,"") + printf "%*s\"%s", indent, "", $0; + in_number = 2; + next; +} + +in_number == 2 { + gsub (/ /,"") + printf "%s\"", $0; + in_number = 3; + next; +} + +/^#.*Example.*key pair/ { + if (in_item) { + printf " }\n }\n },\n"; + in_item = 0; + } + in_key = 1; + indent = 6; + printf " {\n \"%s\",\n", gensub(/.*: (A .*)/, "\\1", "g"); + next +} + +/^# PKCS#1 .*Example/ { + if (in_key) { + printf " {\n"; + in_key = 0; + } + if (in_item) + printf " },{\n"; + else + printf " {\n"; + in_item = 1; + indent = 10; + printf " \"%s\",\n", gensub(/^# (.*)/, "\\1", "g"); + next +} + +(in_key || in_item) && /^# (Modulus|Public|Exponent|Message|Seed)/ { + # printf "/* %s */\n", $0; + in_number = 1; + next +} +(in_key || in_item) && /^# (Signature|Encryption)/ { + # printf "/* %s */\n", $0; + in_number = 1; + no_comma = 1; + next +} + +END { + if (in_item) { + printf " }\n }\n }\n };\n"; + in_item = 0; + } +}
\ No newline at end of file |