blob: 354e351a4d311bbdca5d428417a199cdf04d5978 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Paul Bakker89e80c92012-03-20 13:50:09 +00002#
3# Based on NIST gcmDecryptxxx.rsp validation files
4# Only first 3 of every set used for compile time saving
Bence Szépkúti700ee442020-05-26 00:33:31 +02005#
Bence Szépkúti1e148272020-08-07 13:07:28 +02006# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02007# SPDX-License-Identifier: Apache-2.0
8#
9# Licensed under the Apache License, Version 2.0 (the "License"); you may
10# not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
Paul Bakker89e80c92012-03-20 13:50:09 +000020
21use strict;
22
23my $file = shift;
24
25open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";
26
27sub get_suite_val($)
28{
29 my $name = shift;
30 my $val = "";
31
32 while(my $line = <TEST_DATA>)
33 {
34 next if ($line !~ /^\[/);
35 ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/);
36 last;
37 }
38
39 return $val;
40}
41
42sub get_val($)
43{
44 my $name = shift;
45 my $val = "";
46 my $line;
47
48 while($line = <TEST_DATA>)
49 {
50 next if($line !~ /=/);
51 last;
52 }
53
54 ($val) = ($line =~ /^$name = (\w+)/);
55
56 return $val;
57}
58
59sub get_val_or_fail($)
60{
61 my $name = shift;
62 my $val = "FAIL";
63 my $line;
64
65 while($line = <TEST_DATA>)
66 {
67 next if($line !~ /=/ && $line !~ /FAIL/);
68 last;
69 }
70
71 ($val) = ($line =~ /^$name = (\w+)/) if ($line =~ /=/);
72
73 return $val;
74}
75
76my $cnt = 1;;
77while (my $line = <TEST_DATA>)
78{
79 my $key_len = get_suite_val("Keylen");
80 next if ($key_len !~ /\d+/);
81 my $iv_len = get_suite_val("IVlen");
82 my $pt_len = get_suite_val("PTlen");
83 my $add_len = get_suite_val("AADlen");
84 my $tag_len = get_suite_val("Taglen");
85
86 for ($cnt = 0; $cnt < 3; $cnt++)
87 {
88 my $Count = get_val("Count");
89 my $key = get_val("Key");
90 my $iv = get_val("IV");
91 my $ct = get_val("CT");
92 my $add = get_val("AAD");
93 my $tag = get_val("Tag");
94 my $pt = get_val_or_fail("PT");
95
96 print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n");
97 print("gcm_decrypt_and_verify");
98 print(":\"$key\"");
99 print(":\"$ct\"");
100 print(":\"$iv\"");
101 print(":\"$add\"");
102 print(":$tag_len");
103 print(":\"$tag\"");
104 print(":\"$pt\"");
105 print(":0");
106 print("\n\n");
107 }
108}
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200109
110print("GCM Selftest\n");
111print("gcm_selftest:\n\n");
112
Paul Bakker89e80c92012-03-20 13:50:09 +0000113close(TEST_DATA);