1#!/usr/bin/perl 2# 3# Based on NIST gcmEncryptIntIVxxx.rsp validation files 4# Only first 3 of every set used for compile time saving 5 6use strict; 7 8my $file = shift; 9 10open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; 11 12sub get_suite_val($) 13{ 14 my $name = shift; 15 my $val = ""; 16 17 while(my $line = <TEST_DATA>) 18 { 19 next if ($line !~ /^\[/); 20 ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/); 21 last; 22 } 23 24 return $val; 25} 26 27sub get_val($) 28{ 29 my $name = shift; 30 my $val = ""; 31 my $line; 32 33 while($line = <TEST_DATA>) 34 { 35 next if($line !~ /=/); 36 last; 37 } 38 39 ($val) = ($line =~ /^$name = (\w+)/); 40 41 return $val; 42} 43 44my $cnt = 1;; 45while (my $line = <TEST_DATA>) 46{ 47 my $key_len = get_suite_val("Keylen"); 48 next if ($key_len !~ /\d+/); 49 my $iv_len = get_suite_val("IVlen"); 50 my $pt_len = get_suite_val("PTlen"); 51 my $add_len = get_suite_val("AADlen"); 52 my $tag_len = get_suite_val("Taglen"); 53 54 for ($cnt = 0; $cnt < 3; $cnt++) 55 { 56 my $Count = get_val("Count"); 57 my $key = get_val("Key"); 58 my $pt = get_val("PT"); 59 my $add = get_val("AAD"); 60 my $iv = get_val("IV"); 61 my $ct = get_val("CT"); 62 my $tag = get_val("Tag"); 63 64 print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n"); 65 print("gcm_encrypt_and_tag"); 66 print(":\"$key\""); 67 print(":\"$pt\""); 68 print(":\"$iv\""); 69 print(":\"$add\""); 70 print(":\"$ct\""); 71 print(":$tag_len"); 72 print(":\"$tag\""); 73 print(":0"); 74 print("\n\n"); 75 } 76} 77 78print("GCM Selftest\n"); 79print("gcm_selftest:\n\n"); 80 81close(TEST_DATA); 82