gen_pkcs1_v21_sign_verify.pl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env perl
  2. #
  3. # Copyright The Mbed TLS Contributors
  4. # SPDX-License-Identifier: Apache-2.0
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. use strict;
  18. my $file = shift;
  19. open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";
  20. sub get_val($$)
  21. {
  22. my $str = shift;
  23. my $name = shift;
  24. my $val = "";
  25. while(my $line = <TEST_DATA>)
  26. {
  27. next if($line !~ /^# $str/);
  28. last;
  29. }
  30. while(my $line = <TEST_DATA>)
  31. {
  32. last if($line eq "\r\n");
  33. $val .= $line;
  34. }
  35. $val =~ s/[ \r\n]//g;
  36. return $val;
  37. }
  38. my $state = 0;
  39. my $val_n = "";
  40. my $val_e = "";
  41. my $val_p = "";
  42. my $val_q = "";
  43. my $mod = 0;
  44. my $cnt = 1;
  45. while (my $line = <TEST_DATA>)
  46. {
  47. next if ($line !~ /^# Example/);
  48. ( $mod ) = ($line =~ /A (\d+)/);
  49. $val_n = get_val("RSA modulus n", "N");
  50. $val_e = get_val("RSA public exponent e", "E");
  51. $val_p = get_val("Prime p", "P");
  52. $val_q = get_val("Prime q", "Q");
  53. for(my $i = 1; $i <= 6; $i++)
  54. {
  55. my $val_m = get_val("Message to be", "M");
  56. my $val_salt = get_val("Salt", "Salt");
  57. my $val_sig = get_val("Signature", "Sig");
  58. print("RSASSA-PSS Signature Example ${cnt}_${i}\n");
  59. print("pkcs1_rsassa_pss_sign:$mod:16:\"$val_p\":16:\"$val_q\":16:\"$val_n\":16:\"$val_e\":SIG_RSA_SHA1:MBEDTLS_MD_SHA1");
  60. print(":\"$val_m\"");
  61. print(":\"$val_salt\"");
  62. print(":\"$val_sig\":0");
  63. print("\n\n");
  64. print("RSASSA-PSS Signature Example ${cnt}_${i} (verify)\n");
  65. print("pkcs1_rsassa_pss_verify:$mod:16:\"$val_n\":16:\"$val_e\":SIG_RSA_SHA1:MBEDTLS_MD_SHA1");
  66. print(":\"$val_m\"");
  67. print(":\"$val_salt\"");
  68. print(":\"$val_sig\":0");
  69. print("\n\n");
  70. }
  71. $cnt++;
  72. }
  73. close(TEST_DATA);