| 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 | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 6 | # | 
|  | 7 | # Copyright (C) 2011, Arm Limited, All Rights Reserved | 
| Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 8 | # SPDX-License-Identifier: Apache-2.0 | 
|  | 9 | # | 
|  | 10 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | 
|  | 11 | # not use this file except in compliance with the License. | 
|  | 12 | # You may obtain a copy of the License at | 
|  | 13 | # | 
|  | 14 | # http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 15 | # | 
|  | 16 | # Unless required by applicable law or agreed to in writing, software | 
|  | 17 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 
|  | 18 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 19 | # See the License for the specific language governing permissions and | 
|  | 20 | # limitations under the License. | 
| Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 21 | # | 
|  | 22 | # This file is part of Mbed TLS (https://tls.mbed.org) | 
| Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 23 |  | 
|  | 24 | use strict; | 
|  | 25 |  | 
|  | 26 | my $file = shift; | 
|  | 27 |  | 
|  | 28 | open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; | 
|  | 29 |  | 
|  | 30 | sub get_suite_val($) | 
|  | 31 | { | 
|  | 32 | my $name = shift; | 
|  | 33 | my $val = ""; | 
|  | 34 |  | 
|  | 35 | my $line = <TEST_DATA>; | 
|  | 36 | ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/); | 
|  | 37 |  | 
|  | 38 | return $val; | 
|  | 39 | } | 
|  | 40 |  | 
|  | 41 | sub get_val($) | 
|  | 42 | { | 
|  | 43 | my $name = shift; | 
|  | 44 | my $val = ""; | 
|  | 45 | my $line; | 
|  | 46 |  | 
|  | 47 | while($line = <TEST_DATA>) | 
|  | 48 | { | 
|  | 49 | next if($line !~ /=/); | 
|  | 50 | last; | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | ($val) = ($line =~ /^$name = (\w+)/); | 
|  | 54 |  | 
|  | 55 | return $val; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | my $cnt = 1;; | 
|  | 59 | while (my $line = <TEST_DATA>) | 
|  | 60 | { | 
|  | 61 | next if ($line !~ /^\[AES-256 use df/); | 
|  | 62 |  | 
|  | 63 | my $PredictionResistanceStr = get_suite_val("PredictionResistance"); | 
|  | 64 | my $PredictionResistance = 0; | 
|  | 65 | $PredictionResistance = 1 if ($PredictionResistanceStr eq 'True'); | 
|  | 66 | my $EntropyInputLen = get_suite_val("EntropyInputLen"); | 
|  | 67 | my $NonceLen = get_suite_val("NonceLen"); | 
|  | 68 | my $PersonalizationStringLen = get_suite_val("PersonalizationStringLen"); | 
|  | 69 | my $AdditionalInputLen = get_suite_val("AdditionalInputLen"); | 
|  | 70 |  | 
|  | 71 | for ($cnt = 0; $cnt < 15; $cnt++) | 
|  | 72 | { | 
|  | 73 | my $Count = get_val("COUNT"); | 
|  | 74 | my $EntropyInput = get_val("EntropyInput"); | 
|  | 75 | my $Nonce = get_val("Nonce"); | 
|  | 76 | my $PersonalizationString = get_val("PersonalizationString"); | 
|  | 77 | my $AdditionalInput1 = get_val("AdditionalInput"); | 
|  | 78 | my $EntropyInputPR1 = get_val("EntropyInputPR") if ($PredictionResistance == 1); | 
|  | 79 | my $EntropyInputReseed = get_val("EntropyInputReseed") if ($PredictionResistance == 0); | 
|  | 80 | my $AdditionalInputReseed = get_val("AdditionalInputReseed") if ($PredictionResistance == 0); | 
|  | 81 | my $AdditionalInput2 = get_val("AdditionalInput"); | 
|  | 82 | my $EntropyInputPR2 = get_val("EntropyInputPR") if ($PredictionResistance == 1); | 
|  | 83 | my $ReturnedBits = get_val("ReturnedBits"); | 
| Darryl Green | 11999bb | 2018-03-13 15:22:58 +0000 | [diff] [blame] | 84 |  | 
| Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 85 | if ($PredictionResistance == 1) | 
|  | 86 | { | 
|  | 87 | print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n"); | 
|  | 88 | print("ctr_drbg_validate_pr"); | 
|  | 89 | print(":\"$Nonce$PersonalizationString\""); | 
|  | 90 | print(":\"$EntropyInput$EntropyInputPR1$EntropyInputPR2\""); | 
|  | 91 | print(":\"$AdditionalInput1\""); | 
|  | 92 | print(":\"$AdditionalInput2\""); | 
|  | 93 | print(":\"$ReturnedBits\""); | 
|  | 94 | print("\n\n"); | 
|  | 95 | } | 
|  | 96 | else | 
|  | 97 | { | 
|  | 98 | print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n"); | 
|  | 99 | print("ctr_drbg_validate_nopr"); | 
|  | 100 | print(":\"$Nonce$PersonalizationString\""); | 
|  | 101 | print(":\"$EntropyInput$EntropyInputReseed\""); | 
|  | 102 | print(":\"$AdditionalInput1\""); | 
|  | 103 | print(":\"$AdditionalInputReseed\""); | 
|  | 104 | print(":\"$AdditionalInput2\""); | 
|  | 105 | print(":\"$ReturnedBits\""); | 
|  | 106 | print("\n\n"); | 
|  | 107 | } | 
|  | 108 | } | 
|  | 109 | } | 
|  | 110 | close(TEST_DATA); |