fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 2 | # |
| 3 | # Based on NIST gcmDecryptxxx.rsp validation files |
| 4 | # Only first 3 of every set used for compile time saving |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 5 | # |
| 6 | # Copyright (C) 2012-2013, Arm Limited, All Rights Reserved |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 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: |
Bence Szépkúti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 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. |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 26 | # |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 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 | # |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 48 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 49 | |
| 50 | use strict; |
| 51 | |
| 52 | my $file = shift; |
| 53 | |
| 54 | open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; |
| 55 | |
| 56 | sub 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 | |
| 71 | sub 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 | |
| 88 | sub get_val_or_fail($) |
| 89 | { |
| 90 | my $name = shift; |
| 91 | my $val = "FAIL"; |
| 92 | my $line; |
| 93 | |
| 94 | while($line = <TEST_DATA>) |
| 95 | { |
| 96 | next if($line !~ /=/ && $line !~ /FAIL/); |
| 97 | last; |
| 98 | } |
| 99 | |
| 100 | ($val) = ($line =~ /^$name = (\w+)/) if ($line =~ /=/); |
| 101 | |
| 102 | return $val; |
| 103 | } |
| 104 | |
| 105 | my $cnt = 1;; |
| 106 | while (my $line = <TEST_DATA>) |
| 107 | { |
| 108 | my $key_len = get_suite_val("Keylen"); |
| 109 | next if ($key_len !~ /\d+/); |
| 110 | my $iv_len = get_suite_val("IVlen"); |
| 111 | my $pt_len = get_suite_val("PTlen"); |
| 112 | my $add_len = get_suite_val("AADlen"); |
| 113 | my $tag_len = get_suite_val("Taglen"); |
| 114 | |
| 115 | for ($cnt = 0; $cnt < 3; $cnt++) |
| 116 | { |
| 117 | my $Count = get_val("Count"); |
| 118 | my $key = get_val("Key"); |
| 119 | my $iv = get_val("IV"); |
| 120 | my $ct = get_val("CT"); |
| 121 | my $add = get_val("AAD"); |
| 122 | my $tag = get_val("Tag"); |
| 123 | my $pt = get_val_or_fail("PT"); |
| 124 | |
| 125 | print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n"); |
| 126 | print("gcm_decrypt_and_verify"); |
| 127 | print(":\"$key\""); |
| 128 | print(":\"$ct\""); |
| 129 | print(":\"$iv\""); |
| 130 | print(":\"$add\""); |
| 131 | print(":$tag_len"); |
| 132 | print(":\"$tag\""); |
| 133 | print(":\"$pt\""); |
| 134 | print(":0"); |
| 135 | print("\n\n"); |
| 136 | } |
| 137 | } |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 138 | |
| 139 | print("GCM Selftest\n"); |
| 140 | print("gcm_selftest:\n\n"); |
| 141 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 142 | close(TEST_DATA); |