blob: 0a128e5fcdfeda7b6f6253c9b6bfb9caa369f008 [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úti468a76f2020-05-26 00:33:31 +02005#
6# Copyright (C) 2012-2013, Arm Limited, All Rights Reserved
Bence Szépkútif744bd72020-06-05 13:02:18 +02007# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
8#
9# This file is provided under the Apache License 2.0, or the
10# GNU General Public License v2.0 or later.
11#
12# **********
13# Apache License 2.0:
Bence Szépkúti51b41d52020-05-26 01:54:15 +020014#
15# Licensed under the Apache License, Version 2.0 (the "License"); you may
16# not use this file except in compliance with the License.
17# You may obtain a copy of the License at
18#
19# http://www.apache.org/licenses/LICENSE-2.0
20#
21# Unless required by applicable law or agreed to in writing, software
22# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
23# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24# See the License for the specific language governing permissions and
25# limitations under the License.
Bence Szépkúti468a76f2020-05-26 00:33:31 +020026#
Bence Szépkútif744bd72020-06-05 13:02:18 +020027# **********
28#
29# **********
30# GNU General Public License v2.0 or later:
31#
32# This program is free software; you can redistribute it and/or modify
33# it under the terms of the GNU General Public License as published by
34# the Free Software Foundation; either version 2 of the License, or
35# (at your option) any later version.
36#
37# This program is distributed in the hope that it will be useful,
38# but WITHOUT ANY WARRANTY; without even the implied warranty of
39# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40# GNU General Public License for more details.
41#
42# You should have received a copy of the GNU General Public License along
43# with this program; if not, write to the Free Software Foundation, Inc.,
44# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
45#
46# **********
47#
Bence Szépkúti468a76f2020-05-26 00:33:31 +020048# This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker89e80c92012-03-20 13:50:09 +000049
50use strict;
51
52my $file = shift;
53
54open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";
55
56sub get_suite_val($)
57{
58 my $name = shift;
59 my $val = "";
60
61 while(my $line = <TEST_DATA>)
62 {
63 next if ($line !~ /^\[/);
64 ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/);
65 last;
66 }
67
68 return $val;
69}
70
71sub get_val($)
72{
73 my $name = shift;
74 my $val = "";
75 my $line;
76
77 while($line = <TEST_DATA>)
78 {
79 next if($line !~ /=/);
80 last;
81 }
82
83 ($val) = ($line =~ /^$name = (\w+)/);
84
85 return $val;
86}
87
88my $cnt = 1;;
89while (my $line = <TEST_DATA>)
90{
91 my $key_len = get_suite_val("Keylen");
92 next if ($key_len !~ /\d+/);
93 my $iv_len = get_suite_val("IVlen");
94 my $pt_len = get_suite_val("PTlen");
95 my $add_len = get_suite_val("AADlen");
96 my $tag_len = get_suite_val("Taglen");
97
98 for ($cnt = 0; $cnt < 3; $cnt++)
99 {
100 my $Count = get_val("Count");
101 my $key = get_val("Key");
102 my $pt = get_val("PT");
103 my $add = get_val("AAD");
104 my $iv = get_val("IV");
105 my $ct = get_val("CT");
106 my $tag = get_val("Tag");
107
108 print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n");
109 print("gcm_encrypt_and_tag");
110 print(":\"$key\"");
111 print(":\"$pt\"");
112 print(":\"$iv\"");
113 print(":\"$add\"");
114 print(":\"$ct\"");
115 print(":$tag_len");
116 print(":\"$tag\"");
117 print(":0");
118 print("\n\n");
119 }
120}
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200121
122print("GCM Selftest\n");
123print("gcm_selftest:\n\n");
124
Paul Bakker89e80c92012-03-20 13:50:09 +0000125close(TEST_DATA);