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