blob: 6e4cb1fbbf43b25b408276693a4c8e8d6ae89112 [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#
6# Copyright (C) 2012-2013, Arm Limited, All Rights Reserved
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.
Bence Szépkúti700ee442020-05-26 00:33:31 +020020#
21# This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker89e80c92012-03-20 13:50:09 +000022
23use strict;
24
25my $file = shift;
26
27open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";
28
29sub get_suite_val($)
30{
31 my $name = shift;
32 my $val = "";
33
34 while(my $line = <TEST_DATA>)
35 {
36 next if ($line !~ /^\[/);
37 ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/);
38 last;
39 }
40
41 return $val;
42}
43
44sub get_val($)
45{
46 my $name = shift;
47 my $val = "";
48 my $line;
49
50 while($line = <TEST_DATA>)
51 {
52 next if($line !~ /=/);
53 last;
54 }
55
56 ($val) = ($line =~ /^$name = (\w+)/);
57
58 return $val;
59}
60
61sub get_val_or_fail($)
62{
63 my $name = shift;
64 my $val = "FAIL";
65 my $line;
66
67 while($line = <TEST_DATA>)
68 {
69 next if($line !~ /=/ && $line !~ /FAIL/);
70 last;
71 }
72
73 ($val) = ($line =~ /^$name = (\w+)/) if ($line =~ /=/);
74
75 return $val;
76}
77
78my $cnt = 1;;
79while (my $line = <TEST_DATA>)
80{
81 my $key_len = get_suite_val("Keylen");
82 next if ($key_len !~ /\d+/);
83 my $iv_len = get_suite_val("IVlen");
84 my $pt_len = get_suite_val("PTlen");
85 my $add_len = get_suite_val("AADlen");
86 my $tag_len = get_suite_val("Taglen");
87
88 for ($cnt = 0; $cnt < 3; $cnt++)
89 {
90 my $Count = get_val("Count");
91 my $key = get_val("Key");
92 my $iv = get_val("IV");
93 my $ct = get_val("CT");
94 my $add = get_val("AAD");
95 my $tag = get_val("Tag");
96 my $pt = get_val_or_fail("PT");
97
98 print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n");
99 print("gcm_decrypt_and_verify");
100 print(":\"$key\"");
101 print(":\"$ct\"");
102 print(":\"$iv\"");
103 print(":\"$add\"");
104 print(":$tag_len");
105 print(":\"$tag\"");
106 print(":\"$pt\"");
107 print(":0");
108 print("\n\n");
109 }
110}
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200111
112print("GCM Selftest\n");
113print("gcm_selftest:\n\n");
114
Paul Bakker89e80c92012-03-20 13:50:09 +0000115close(TEST_DATA);