blob: 715eac3587182375116bb8a2ebd7b42ece46320f [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úti700ee442020-05-26 00:33:31 +02006#
7# Copyright (C) 2011, Arm Limited, All Rights Reserved
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02008# 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úti700ee442020-05-26 00:33:31 +020021#
22# This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker0e04d0e2011-11-27 14:46:59 +000023
24use strict;
25
26my $file = shift;
27
28open(TEST_DATA, "$file") or die "Opening test cases '$file': $!";
29
30sub 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
41sub 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
58my $cnt = 1;;
59while (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 Green11999bb2018-03-13 15:22:58 +000084
Paul Bakker0e04d0e2011-11-27 14:46:59 +000085 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}
110close(TEST_DATA);