fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 2 | # |
| 3 | # Based on NIST CTR_DRBG.rsp validation file |
| 4 | # Only uses AES-256-CTR cases that use a Derivation function |
| 5 | # and concats nonce and personalization for initialization. |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 6 | # |
Bence Szépkúti | a2947ac | 2020-08-19 16:37:36 +0200 | [diff] [blame] | 7 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 8 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 9 | # |
| 10 | # This file is provided under the Apache License 2.0, or the |
| 11 | # GNU General Public License v2.0 or later. |
| 12 | # |
| 13 | # ********** |
| 14 | # Apache License 2.0: |
Bence Szépkúti | 51b41d5 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 15 | # |
| 16 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 17 | # not use this file except in compliance with the License. |
| 18 | # You may obtain a copy of the License at |
| 19 | # |
| 20 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 21 | # |
| 22 | # Unless required by applicable law or agreed to in writing, software |
| 23 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 24 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 25 | # See the License for the specific language governing permissions and |
| 26 | # limitations under the License. |
Bence Szépkúti | 468a76f | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 27 | # |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 28 | # ********** |
| 29 | # |
| 30 | # ********** |
| 31 | # GNU General Public License v2.0 or later: |
| 32 | # |
| 33 | # This program is free software; you can redistribute it and/or modify |
| 34 | # it under the terms of the GNU General Public License as published by |
| 35 | # the Free Software Foundation; either version 2 of the License, or |
| 36 | # (at your option) any later version. |
| 37 | # |
| 38 | # This program is distributed in the hope that it will be useful, |
| 39 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 41 | # GNU General Public License for more details. |
| 42 | # |
| 43 | # You should have received a copy of the GNU General Public License along |
| 44 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 45 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 46 | # |
| 47 | # ********** |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 48 | |
| 49 | use strict; |
| 50 | |
| 51 | my $file = shift; |
| 52 | |
| 53 | open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; |
| 54 | |
| 55 | sub get_suite_val($) |
| 56 | { |
| 57 | my $name = shift; |
| 58 | my $val = ""; |
| 59 | |
| 60 | my $line = <TEST_DATA>; |
| 61 | ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/); |
| 62 | |
| 63 | return $val; |
| 64 | } |
| 65 | |
| 66 | sub get_val($) |
| 67 | { |
| 68 | my $name = shift; |
| 69 | my $val = ""; |
| 70 | my $line; |
| 71 | |
| 72 | while($line = <TEST_DATA>) |
| 73 | { |
| 74 | next if($line !~ /=/); |
| 75 | last; |
| 76 | } |
| 77 | |
| 78 | ($val) = ($line =~ /^$name = (\w+)/); |
| 79 | |
| 80 | return $val; |
| 81 | } |
| 82 | |
| 83 | my $cnt = 1;; |
| 84 | while (my $line = <TEST_DATA>) |
| 85 | { |
| 86 | next if ($line !~ /^\[AES-256 use df/); |
| 87 | |
| 88 | my $PredictionResistanceStr = get_suite_val("PredictionResistance"); |
| 89 | my $PredictionResistance = 0; |
| 90 | $PredictionResistance = 1 if ($PredictionResistanceStr eq 'True'); |
| 91 | my $EntropyInputLen = get_suite_val("EntropyInputLen"); |
| 92 | my $NonceLen = get_suite_val("NonceLen"); |
| 93 | my $PersonalizationStringLen = get_suite_val("PersonalizationStringLen"); |
| 94 | my $AdditionalInputLen = get_suite_val("AdditionalInputLen"); |
| 95 | |
| 96 | for ($cnt = 0; $cnt < 15; $cnt++) |
| 97 | { |
| 98 | my $Count = get_val("COUNT"); |
| 99 | my $EntropyInput = get_val("EntropyInput"); |
| 100 | my $Nonce = get_val("Nonce"); |
| 101 | my $PersonalizationString = get_val("PersonalizationString"); |
| 102 | my $AdditionalInput1 = get_val("AdditionalInput"); |
| 103 | my $EntropyInputPR1 = get_val("EntropyInputPR") if ($PredictionResistance == 1); |
| 104 | my $EntropyInputReseed = get_val("EntropyInputReseed") if ($PredictionResistance == 0); |
| 105 | my $AdditionalInputReseed = get_val("AdditionalInputReseed") if ($PredictionResistance == 0); |
| 106 | my $AdditionalInput2 = get_val("AdditionalInput"); |
| 107 | my $EntropyInputPR2 = get_val("EntropyInputPR") if ($PredictionResistance == 1); |
| 108 | my $ReturnedBits = get_val("ReturnedBits"); |
Darryl Green | 11999bb | 2018-03-13 15:22:58 +0000 | [diff] [blame] | 109 | |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 110 | if ($PredictionResistance == 1) |
| 111 | { |
| 112 | print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n"); |
| 113 | print("ctr_drbg_validate_pr"); |
| 114 | print(":\"$Nonce$PersonalizationString\""); |
| 115 | print(":\"$EntropyInput$EntropyInputPR1$EntropyInputPR2\""); |
| 116 | print(":\"$AdditionalInput1\""); |
| 117 | print(":\"$AdditionalInput2\""); |
| 118 | print(":\"$ReturnedBits\""); |
| 119 | print("\n\n"); |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n"); |
| 124 | print("ctr_drbg_validate_nopr"); |
| 125 | print(":\"$Nonce$PersonalizationString\""); |
| 126 | print(":\"$EntropyInput$EntropyInputReseed\""); |
| 127 | print(":\"$AdditionalInput1\""); |
| 128 | print(":\"$AdditionalInputReseed\""); |
| 129 | print(":\"$AdditionalInput2\""); |
| 130 | print(":\"$ReturnedBits\""); |
| 131 | print("\n\n"); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | close(TEST_DATA); |