1#!/usr/bin/env perl 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. 6# 7# Copyright The Mbed TLS Contributors 8# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 9 10use strict; 11 12my $file = shift; 13 14open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; 15 16sub get_suite_val($) 17{ 18 my $name = shift; 19 my $val = ""; 20 21 my $line = <TEST_DATA>; 22 ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/); 23 24 return $val; 25} 26 27sub get_val($) 28{ 29 my $name = shift; 30 my $val = ""; 31 my $line; 32 33 while($line = <TEST_DATA>) 34 { 35 next if($line !~ /=/); 36 last; 37 } 38 39 ($val) = ($line =~ /^$name = (\w+)/); 40 41 return $val; 42} 43 44my $cnt = 1;; 45while (my $line = <TEST_DATA>) 46{ 47 next if ($line !~ /^\[AES-256 use df/); 48 49 my $PredictionResistanceStr = get_suite_val("PredictionResistance"); 50 my $PredictionResistance = 0; 51 $PredictionResistance = 1 if ($PredictionResistanceStr eq 'True'); 52 my $EntropyInputLen = get_suite_val("EntropyInputLen"); 53 my $NonceLen = get_suite_val("NonceLen"); 54 my $PersonalizationStringLen = get_suite_val("PersonalizationStringLen"); 55 my $AdditionalInputLen = get_suite_val("AdditionalInputLen"); 56 57 for ($cnt = 0; $cnt < 15; $cnt++) 58 { 59 my $Count = get_val("COUNT"); 60 my $EntropyInput = get_val("EntropyInput"); 61 my $Nonce = get_val("Nonce"); 62 my $PersonalizationString = get_val("PersonalizationString"); 63 my $AdditionalInput1 = get_val("AdditionalInput"); 64 my $EntropyInputPR1 = get_val("EntropyInputPR") if ($PredictionResistance == 1); 65 my $EntropyInputReseed = get_val("EntropyInputReseed") if ($PredictionResistance == 0); 66 my $AdditionalInputReseed = get_val("AdditionalInputReseed") if ($PredictionResistance == 0); 67 my $AdditionalInput2 = get_val("AdditionalInput"); 68 my $EntropyInputPR2 = get_val("EntropyInputPR") if ($PredictionResistance == 1); 69 my $ReturnedBits = get_val("ReturnedBits"); 70 71 if ($PredictionResistance == 1) 72 { 73 print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n"); 74 print("ctr_drbg_validate_pr"); 75 print(":\"$Nonce$PersonalizationString\""); 76 print(":\"$EntropyInput$EntropyInputPR1$EntropyInputPR2\""); 77 print(":\"$AdditionalInput1\""); 78 print(":\"$AdditionalInput2\""); 79 print(":\"$ReturnedBits\""); 80 print("\n\n"); 81 } 82 else 83 { 84 print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n"); 85 print("ctr_drbg_validate_nopr"); 86 print(":\"$Nonce$PersonalizationString\""); 87 print(":\"$EntropyInput$EntropyInputReseed\""); 88 print(":\"$AdditionalInput1\""); 89 print(":\"$AdditionalInputReseed\""); 90 print(":\"$AdditionalInput2\""); 91 print(":\"$ReturnedBits\""); 92 print("\n\n"); 93 } 94 } 95} 96close(TEST_DATA); 97