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