mbed TLS Build
tests/scripts/gen_ctr_drbg.pl@1:1a219dea6cb5, 2019-06-04 (annotated)
- Committer:
- williequesada
- Date:
- Tue Jun 04 16:03:38 2019 +0000
- Revision:
- 1:1a219dea6cb5
- Parent:
- 0:cdf462088d13
compartir a Pablo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markrad | 0:cdf462088d13 | 1 | #!/usr/bin/perl |
markrad | 0:cdf462088d13 | 2 | # |
markrad | 0:cdf462088d13 | 3 | # Based on NIST CTR_DRBG.rsp validation file |
markrad | 0:cdf462088d13 | 4 | # Only uses AES-256-CTR cases that use a Derivation function |
markrad | 0:cdf462088d13 | 5 | # and concats nonce and personalization for initialization. |
markrad | 0:cdf462088d13 | 6 | |
markrad | 0:cdf462088d13 | 7 | use strict; |
markrad | 0:cdf462088d13 | 8 | |
markrad | 0:cdf462088d13 | 9 | my $file = shift; |
markrad | 0:cdf462088d13 | 10 | |
markrad | 0:cdf462088d13 | 11 | open(TEST_DATA, "$file") or die "Opening test cases '$file': $!"; |
markrad | 0:cdf462088d13 | 12 | |
markrad | 0:cdf462088d13 | 13 | sub get_suite_val($) |
markrad | 0:cdf462088d13 | 14 | { |
markrad | 0:cdf462088d13 | 15 | my $name = shift; |
markrad | 0:cdf462088d13 | 16 | my $val = ""; |
markrad | 0:cdf462088d13 | 17 | |
markrad | 0:cdf462088d13 | 18 | my $line = <TEST_DATA>; |
markrad | 0:cdf462088d13 | 19 | ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/); |
markrad | 0:cdf462088d13 | 20 | |
markrad | 0:cdf462088d13 | 21 | return $val; |
markrad | 0:cdf462088d13 | 22 | } |
markrad | 0:cdf462088d13 | 23 | |
markrad | 0:cdf462088d13 | 24 | sub get_val($) |
markrad | 0:cdf462088d13 | 25 | { |
markrad | 0:cdf462088d13 | 26 | my $name = shift; |
markrad | 0:cdf462088d13 | 27 | my $val = ""; |
markrad | 0:cdf462088d13 | 28 | my $line; |
markrad | 0:cdf462088d13 | 29 | |
markrad | 0:cdf462088d13 | 30 | while($line = <TEST_DATA>) |
markrad | 0:cdf462088d13 | 31 | { |
markrad | 0:cdf462088d13 | 32 | next if($line !~ /=/); |
markrad | 0:cdf462088d13 | 33 | last; |
markrad | 0:cdf462088d13 | 34 | } |
markrad | 0:cdf462088d13 | 35 | |
markrad | 0:cdf462088d13 | 36 | ($val) = ($line =~ /^$name = (\w+)/); |
markrad | 0:cdf462088d13 | 37 | |
markrad | 0:cdf462088d13 | 38 | return $val; |
markrad | 0:cdf462088d13 | 39 | } |
markrad | 0:cdf462088d13 | 40 | |
markrad | 0:cdf462088d13 | 41 | my $cnt = 1;; |
markrad | 0:cdf462088d13 | 42 | while (my $line = <TEST_DATA>) |
markrad | 0:cdf462088d13 | 43 | { |
markrad | 0:cdf462088d13 | 44 | next if ($line !~ /^\[AES-256 use df/); |
markrad | 0:cdf462088d13 | 45 | |
markrad | 0:cdf462088d13 | 46 | my $PredictionResistanceStr = get_suite_val("PredictionResistance"); |
markrad | 0:cdf462088d13 | 47 | my $PredictionResistance = 0; |
markrad | 0:cdf462088d13 | 48 | $PredictionResistance = 1 if ($PredictionResistanceStr eq 'True'); |
markrad | 0:cdf462088d13 | 49 | my $EntropyInputLen = get_suite_val("EntropyInputLen"); |
markrad | 0:cdf462088d13 | 50 | my $NonceLen = get_suite_val("NonceLen"); |
markrad | 0:cdf462088d13 | 51 | my $PersonalizationStringLen = get_suite_val("PersonalizationStringLen"); |
markrad | 0:cdf462088d13 | 52 | my $AdditionalInputLen = get_suite_val("AdditionalInputLen"); |
markrad | 0:cdf462088d13 | 53 | |
markrad | 0:cdf462088d13 | 54 | for ($cnt = 0; $cnt < 15; $cnt++) |
markrad | 0:cdf462088d13 | 55 | { |
markrad | 0:cdf462088d13 | 56 | my $Count = get_val("COUNT"); |
markrad | 0:cdf462088d13 | 57 | my $EntropyInput = get_val("EntropyInput"); |
markrad | 0:cdf462088d13 | 58 | my $Nonce = get_val("Nonce"); |
markrad | 0:cdf462088d13 | 59 | my $PersonalizationString = get_val("PersonalizationString"); |
markrad | 0:cdf462088d13 | 60 | my $AdditionalInput1 = get_val("AdditionalInput"); |
markrad | 0:cdf462088d13 | 61 | my $EntropyInputPR1 = get_val("EntropyInputPR") if ($PredictionResistance == 1); |
markrad | 0:cdf462088d13 | 62 | my $EntropyInputReseed = get_val("EntropyInputReseed") if ($PredictionResistance == 0); |
markrad | 0:cdf462088d13 | 63 | my $AdditionalInputReseed = get_val("AdditionalInputReseed") if ($PredictionResistance == 0); |
markrad | 0:cdf462088d13 | 64 | my $AdditionalInput2 = get_val("AdditionalInput"); |
markrad | 0:cdf462088d13 | 65 | my $EntropyInputPR2 = get_val("EntropyInputPR") if ($PredictionResistance == 1); |
markrad | 0:cdf462088d13 | 66 | my $ReturnedBits = get_val("ReturnedBits"); |
markrad | 0:cdf462088d13 | 67 | |
markrad | 0:cdf462088d13 | 68 | if ($PredictionResistance == 1) |
markrad | 0:cdf462088d13 | 69 | { |
markrad | 0:cdf462088d13 | 70 | print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n"); |
markrad | 0:cdf462088d13 | 71 | print("ctr_drbg_validate_pr"); |
markrad | 0:cdf462088d13 | 72 | print(":\"$Nonce$PersonalizationString\""); |
markrad | 0:cdf462088d13 | 73 | print(":\"$EntropyInput$EntropyInputPR1$EntropyInputPR2\""); |
markrad | 0:cdf462088d13 | 74 | print(":\"$AdditionalInput1\""); |
markrad | 0:cdf462088d13 | 75 | print(":\"$AdditionalInput2\""); |
markrad | 0:cdf462088d13 | 76 | print(":\"$ReturnedBits\""); |
markrad | 0:cdf462088d13 | 77 | print("\n\n"); |
markrad | 0:cdf462088d13 | 78 | } |
markrad | 0:cdf462088d13 | 79 | else |
markrad | 0:cdf462088d13 | 80 | { |
markrad | 0:cdf462088d13 | 81 | print("CTR_DRBG NIST Validation (AES-256 use df,$PredictionResistanceStr,$EntropyInputLen,$NonceLen,$PersonalizationStringLen,$AdditionalInputLen) #$Count\n"); |
markrad | 0:cdf462088d13 | 82 | print("ctr_drbg_validate_nopr"); |
markrad | 0:cdf462088d13 | 83 | print(":\"$Nonce$PersonalizationString\""); |
markrad | 0:cdf462088d13 | 84 | print(":\"$EntropyInput$EntropyInputReseed\""); |
markrad | 0:cdf462088d13 | 85 | print(":\"$AdditionalInput1\""); |
markrad | 0:cdf462088d13 | 86 | print(":\"$AdditionalInputReseed\""); |
markrad | 0:cdf462088d13 | 87 | print(":\"$AdditionalInput2\""); |
markrad | 0:cdf462088d13 | 88 | print(":\"$ReturnedBits\""); |
markrad | 0:cdf462088d13 | 89 | print("\n\n"); |
markrad | 0:cdf462088d13 | 90 | } |
markrad | 0:cdf462088d13 | 91 | } |
markrad | 0:cdf462088d13 | 92 | } |
markrad | 0:cdf462088d13 | 93 | close(TEST_DATA); |