1#!/usr/bin/env perl 2# 3# Based on NIST gcmEncryptIntIVxxx.rsp validation files 4# Only first 3 of every set used for compile time saving 5# 6# Copyright The Mbed TLS Contributors 7# 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: 14# 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. 26# 27# ********** 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 48use strict; 49 50my $file = shift; 51 52open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; 53 54sub get_suite_val($) 55{ 56 my $name = shift; 57 my $val = ""; 58 59 while(my $line = <TEST_DATA>) 60 { 61 next if ($line !~ /^\[/); 62 ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/); 63 last; 64 } 65 66 return $val; 67} 68 69sub get_val($) 70{ 71 my $name = shift; 72 my $val = ""; 73 my $line; 74 75 while($line = <TEST_DATA>) 76 { 77 next if($line !~ /=/); 78 last; 79 } 80 81 ($val) = ($line =~ /^$name = (\w+)/); 82 83 return $val; 84} 85 86my $cnt = 1;; 87while (my $line = <TEST_DATA>) 88{ 89 my $key_len = get_suite_val("Keylen"); 90 next if ($key_len !~ /\d+/); 91 my $iv_len = get_suite_val("IVlen"); 92 my $pt_len = get_suite_val("PTlen"); 93 my $add_len = get_suite_val("AADlen"); 94 my $tag_len = get_suite_val("Taglen"); 95 96 for ($cnt = 0; $cnt < 3; $cnt++) 97 { 98 my $Count = get_val("Count"); 99 my $key = get_val("Key"); 100 my $pt = get_val("PT"); 101 my $add = get_val("AAD"); 102 my $iv = get_val("IV"); 103 my $ct = get_val("CT"); 104 my $tag = get_val("Tag"); 105 106 print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n"); 107 print("gcm_encrypt_and_tag"); 108 print(":\"$key\""); 109 print(":\"$pt\""); 110 print(":\"$iv\""); 111 print(":\"$add\""); 112 print(":\"$ct\""); 113 print(":$tag_len"); 114 print(":\"$tag\""); 115 print(":0"); 116 print("\n\n"); 117 } 118} 119 120print("GCM Selftest\n"); 121print("gcm_selftest:\n\n"); 122 123close(TEST_DATA); 124