1#!/usr/bin/perl
2#
3
4use strict;
5
6my $file = shift;
7
8open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";
9
10sub get_val($$)
11{
12    my $str = shift;
13    my $name = shift;
14    my $val = "";
15
16    while(my $line = <TEST_DATA>)
17    {
18        next if($line !~ /^# $str/);
19        last;
20    }
21
22    while(my $line = <TEST_DATA>)
23    {
24        last if($line eq "\r\n");
25        $val .= $line;
26    }
27
28    $val =~ s/[ \r\n]//g;
29
30    return $val;
31}
32
33my $state = 0;
34my $val_n = "";
35my $val_e = "";
36my $val_p = "";
37my $val_q = "";
38my $mod = 0;
39my $cnt = 1;
40while (my $line = <TEST_DATA>)
41{
42    next if ($line !~ /^# Example/);
43
44    ( $mod ) = ($line =~ /A (\d+)/);
45    $val_n = get_val("RSA modulus n", "N");
46    $val_e = get_val("RSA public exponent e", "E");
47    $val_p = get_val("Prime p", "P");
48    $val_q = get_val("Prime q", "Q");
49
50    for(my $i = 1; $i <= 6; $i++)
51    {
52        my $val_m = get_val("Message to be", "M");
53        my $val_salt = get_val("Salt", "Salt");
54        my $val_sig = get_val("Signature", "Sig");
55
56        print("RSASSA-PSS Signature Example ${cnt}_${i}\n");
57        print("pkcs1_rsassa_pss_sign:$mod:16:\"$val_p\":16:\"$val_q\":16:\"$val_n\":16:\"$val_e\":SIG_RSA_SHA1:MBEDTLS_MD_SHA1");
58        print(":\"$val_m\"");
59        print(":\"$val_salt\"");
60        print(":\"$val_sig\":0");
61        print("\n\n");
62
63        print("RSASSA-PSS Signature Example ${cnt}_${i} (verify)\n");
64        print("pkcs1_rsassa_pss_verify:$mod:16:\"$val_n\":16:\"$val_e\":SIG_RSA_SHA1:MBEDTLS_MD_SHA1");
65        print(":\"$val_m\"");
66        print(":\"$val_salt\"");
67        print(":\"$val_sig\":0");
68        print("\n\n");
69    }
70    $cnt++;
71}
72close(TEST_DATA);
73