blob: 101456fedf9ad1b3a28210edfc3fd6dfe07461a2 [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 gcmEncryptIntIVxxx.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
59my $cnt = 1;;
60while (my $line = <TEST_DATA>)
61{
62 my $key_len = get_suite_val("Keylen");
63 next if ($key_len !~ /\d+/);
64 my $iv_len = get_suite_val("IVlen");
65 my $pt_len = get_suite_val("PTlen");
66 my $add_len = get_suite_val("AADlen");
67 my $tag_len = get_suite_val("Taglen");
68
69 for ($cnt = 0; $cnt < 3; $cnt++)
70 {
71 my $Count = get_val("Count");
72 my $key = get_val("Key");
73 my $pt = get_val("PT");
74 my $add = get_val("AAD");
75 my $iv = get_val("IV");
76 my $ct = get_val("CT");
77 my $tag = get_val("Tag");
78
79 print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n");
80 print("gcm_encrypt_and_tag");
81 print(":\"$key\"");
82 print(":\"$pt\"");
83 print(":\"$iv\"");
84 print(":\"$add\"");
85 print(":\"$ct\"");
86 print(":$tag_len");
87 print(":\"$tag\"");
88 print(":0");
89 print("\n\n");
90 }
91}
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +020092
93print("GCM Selftest\n");
94print("gcm_selftest:\n\n");
95
Paul Bakker89e80c92012-03-20 13:50:09 +000096close(TEST_DATA);