blob: 9ed0372a9b8291d931987e7f8d5b1c5b13801efe [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#
Bence Szépkútia2947ac2020-08-19 16:37:36 +02007# Copyright The Mbed TLS Contributors
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# **********
Paul Bakker0e04d0e2011-11-27 14:46:59 +000048
49use strict;
50
51my $file = shift;
52
53open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";
54
55sub 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
66sub 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
83my $cnt = 1;;
84while (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 Green11999bb2018-03-13 15:22:58 +0000109
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000110 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}
135close(TEST_DATA);