1#!/usr/bin/env perl 2# 3# Copyright The Mbed TLS Contributors 4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 5# 6# This file is provided under the Apache License 2.0, or the 7# GNU General Public License v2.0 or later. 8# 9# ********** 10# Apache License 2.0: 11# 12# Licensed under the Apache License, Version 2.0 (the "License"); you may 13# not use this file except in compliance with the License. 14# You may obtain a copy of the License at 15# 16# http://www.apache.org/licenses/LICENSE-2.0 17# 18# Unless required by applicable law or agreed to in writing, software 19# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 20# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21# See the License for the specific language governing permissions and 22# limitations under the License. 23# 24# ********** 25# 26# ********** 27# GNU General Public License v2.0 or later: 28# 29# This program is free software; you can redistribute it and/or modify 30# it under the terms of the GNU General Public License as published by 31# the Free Software Foundation; either version 2 of the License, or 32# (at your option) any later version. 33# 34# This program is distributed in the hope that it will be useful, 35# but WITHOUT ANY WARRANTY; without even the implied warranty of 36# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37# GNU General Public License for more details. 38# 39# You should have received a copy of the GNU General Public License along 40# with this program; if not, write to the Free Software Foundation, Inc., 41# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 42# 43# ********** 44 45use strict; 46 47my $file = shift; 48 49open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; 50 51sub get_val($$) 52{ 53 my $str = shift; 54 my $name = shift; 55 my $val = ""; 56 57 while(my $line = <TEST_DATA>) 58 { 59 next if($line !~ /^# $str/); 60 last; 61 } 62 63 while(my $line = <TEST_DATA>) 64 { 65 last if($line eq "\r\n"); 66 $val .= $line; 67 } 68 69 $val =~ s/[ \r\n]//g; 70 71 return $val; 72} 73 74my $state = 0; 75my $val_n = ""; 76my $val_e = ""; 77my $val_p = ""; 78my $val_q = ""; 79my $mod = 0; 80my $cnt = 1; 81while (my $line = <TEST_DATA>) 82{ 83 next if ($line !~ /^# Example/); 84 85 ( $mod ) = ($line =~ /A (\d+)/); 86 $val_n = get_val("RSA modulus n", "N"); 87 $val_e = get_val("RSA public exponent e", "E"); 88 $val_p = get_val("Prime p", "P"); 89 $val_q = get_val("Prime q", "Q"); 90 91 for(my $i = 1; $i <= 6; $i++) 92 { 93 my $val_m = get_val("Message to be", "M"); 94 my $val_salt = get_val("Salt", "Salt"); 95 my $val_sig = get_val("Signature", "Sig"); 96 97 print("RSASSA-PSS Signature Example ${cnt}_${i}\n"); 98 print("pkcs1_rsassa_pss_sign:$mod:16:\"$val_p\":16:\"$val_q\":16:\"$val_n\":16:\"$val_e\":SIG_RSA_SHA1:MBEDTLS_MD_SHA1"); 99 print(":\"$val_m\""); 100 print(":\"$val_salt\""); 101 print(":\"$val_sig\":0"); 102 print("\n\n"); 103 104 print("RSASSA-PSS Signature Example ${cnt}_${i} (verify)\n"); 105 print("pkcs1_rsassa_pss_verify:$mod:16:\"$val_n\":16:\"$val_e\":SIG_RSA_SHA1:MBEDTLS_MD_SHA1"); 106 print(":\"$val_m\""); 107 print(":\"$val_salt\""); 108 print(":\"$val_sig\":0"); 109 print("\n\n"); 110 } 111 $cnt++; 112} 113close(TEST_DATA); 114