blob: 614fedff11ef6fc8431b99cd54dab6fcab643ca7 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Paul Bakker0e04d0e2011-11-27 14:46:59 +00002#
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úti468a76f2020-05-26 00:33:31 +02006#
7# Copyright (C) 2011, Arm Limited, All Rights Reserved
Bence Szépkútif744bd72020-06-05 13:02:18 +02008# 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úti51b41d52020-05-26 01:54:15 +020015#
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úti468a76f2020-05-26 00:33:31 +020027#
Bence Szépkútif744bd72020-06-05 13:02:18 +020028# **********
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# **********
48#
Bence Szépkúti468a76f2020-05-26 00:33:31 +020049# This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker0e04d0e2011-11-27 14:46:59 +000050
51use strict;
52
53my $file = shift;
54
55open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";
56
57sub get_suite_val($)
58{
59 my $name = shift;
60 my $val = "";
61
62 my $line = <TEST_DATA>;
63 ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/);
64
65 return $val;
66}
67
68sub get_val($)
69{
70 my $name = shift;
71 my $val = "";
72 my $line;
73
74 while($line = <TEST_DATA>)
75 {
76 next if($line !~ /=/);
77 last;
78 }
79
80 ($val) = ($line =~ /^$name = (\w+)/);
81
82 return $val;
83}
84
85my $cnt = 1;;
86while (my $line = <TEST_DATA>)
87{
88 next if ($line !~ /^\[AES-256 use df/);
89
90 my $PredictionResistanceStr = get_suite_val("PredictionResistance");
91 my $PredictionResistance = 0;
92 $PredictionResistance = 1 if ($PredictionResistanceStr eq 'True');
93 my $EntropyInputLen = get_suite_val("EntropyInputLen");
94 my $NonceLen = get_suite_val("NonceLen");
95 my $PersonalizationStringLen = get_suite_val("PersonalizationStringLen");
96 my $AdditionalInputLen = get_suite_val("AdditionalInputLen");
97
98 for ($cnt = 0; $cnt < 15; $cnt++)
99 {
100 my $Count = get_val("COUNT");
101 my $EntropyInput = get_val("EntropyInput");
102 my $Nonce = get_val("Nonce");
103 my $PersonalizationString = get_val("PersonalizationString");
104 my $AdditionalInput1 = get_val("AdditionalInput");
105 my $EntropyInputPR1 = get_val("EntropyInputPR") if ($PredictionResistance == 1);
106 my $EntropyInputReseed = get_val("EntropyInputReseed") if ($PredictionResistance == 0);
107 my $AdditionalInputReseed = get_val("AdditionalInputReseed") if ($PredictionResistance == 0);
108 my $AdditionalInput2 = get_val("AdditionalInput");
109 my $EntropyInputPR2 = get_val("EntropyInputPR") if ($PredictionResistance == 1);
110 my $ReturnedBits = get_val("ReturnedBits");
Darryl Green11999bb2018-03-13 15:22:58 +0000111
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000112 if ($PredictionResistance == 1)
113 {
114 print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n");
115 print("ctr_drbg_validate_pr");
116 print(":\"$Nonce$PersonalizationString\"");
117 print(":\"$EntropyInput$EntropyInputPR1$EntropyInputPR2\"");
118 print(":\"$AdditionalInput1\"");
119 print(":\"$AdditionalInput2\"");
120 print(":\"$ReturnedBits\"");
121 print("\n\n");
122 }
123 else
124 {
125 print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n");
126 print("ctr_drbg_validate_nopr");
127 print(":\"$Nonce$PersonalizationString\"");
128 print(":\"$EntropyInput$EntropyInputReseed\"");
129 print(":\"$AdditionalInput1\"");
130 print(":\"$AdditionalInputReseed\"");
131 print(":\"$AdditionalInput2\"");
132 print(":\"$ReturnedBits\"");
133 print("\n\n");
134 }
135 }
136}
137close(TEST_DATA);