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 gcmEncryptIntIVxxx.rsp validation files |
| 4 | # Only first 3 of every set used for compile time saving |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 5 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame^] | 6 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 7 | # 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. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 20 | |
| 21 | use strict; |
| 22 | |
| 23 | my $file = shift; |
| 24 | |
| 25 | open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; |
| 26 | |
| 27 | sub get_suite_val($) |
| 28 | { |
| 29 | my $name = shift; |
| 30 | my $val = ""; |
| 31 | |
| 32 | while(my $line = <TEST_DATA>) |
| 33 | { |
| 34 | next if ($line !~ /^\[/); |
| 35 | ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/); |
| 36 | last; |
| 37 | } |
| 38 | |
| 39 | return $val; |
| 40 | } |
| 41 | |
| 42 | sub get_val($) |
| 43 | { |
| 44 | my $name = shift; |
| 45 | my $val = ""; |
| 46 | my $line; |
| 47 | |
| 48 | while($line = <TEST_DATA>) |
| 49 | { |
| 50 | next if($line !~ /=/); |
| 51 | last; |
| 52 | } |
| 53 | |
| 54 | ($val) = ($line =~ /^$name = (\w+)/); |
| 55 | |
| 56 | return $val; |
| 57 | } |
| 58 | |
| 59 | my $cnt = 1;; |
| 60 | while (my $line = <TEST_DATA>) |
| 61 | { |
| 62 | my $key_len = get_suite_val("Keylen"); |
| 63 | next if ($key_len !~ /\d+/); |
| 64 | my $iv_len = get_suite_val("IVlen"); |
| 65 | my $pt_len = get_suite_val("PTlen"); |
| 66 | my $add_len = get_suite_val("AADlen"); |
| 67 | my $tag_len = get_suite_val("Taglen"); |
| 68 | |
| 69 | for ($cnt = 0; $cnt < 3; $cnt++) |
| 70 | { |
| 71 | my $Count = get_val("Count"); |
| 72 | my $key = get_val("Key"); |
| 73 | my $pt = get_val("PT"); |
| 74 | my $add = get_val("AAD"); |
| 75 | my $iv = get_val("IV"); |
| 76 | my $ct = get_val("CT"); |
| 77 | my $tag = get_val("Tag"); |
| 78 | |
| 79 | print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n"); |
| 80 | print("gcm_encrypt_and_tag"); |
| 81 | print(":\"$key\""); |
| 82 | print(":\"$pt\""); |
| 83 | print(":\"$iv\""); |
| 84 | print(":\"$add\""); |
| 85 | print(":\"$ct\""); |
| 86 | print(":$tag_len"); |
| 87 | print(":\"$tag\""); |
| 88 | print(":0"); |
| 89 | print("\n\n"); |
| 90 | } |
| 91 | } |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 92 | |
| 93 | print("GCM Selftest\n"); |
| 94 | print("gcm_selftest:\n\n"); |
| 95 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 96 | close(TEST_DATA); |