blob: 602d85aa4138d262c8fa1b4552370e834274f303 [file] [log] [blame]
fbrosson533407a2018-04-04 21:44:29 +00001#!/usr/bin/env perl
Paul Bakker89e80c92012-03-20 13:50:09 +00002#
3# Based on NIST gcmEncryptIntIVxxx.rsp validation files
4# Only first 3 of every set used for compile time saving
Bence Szépkúti700ee442020-05-26 00:33:31 +02005#
6# Copyright (C) 2012-2013, Arm Limited, All Rights Reserved
7#
8# This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker89e80c92012-03-20 13:50:09 +00009
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 while(my $line = <TEST_DATA>)
22 {
23 next if ($line !~ /^\[/);
24 ($val) = ($line =~ /\[$name\s\=\s(\w+)\]/);
25 last;
26 }
27
28 return $val;
29}
30
31sub get_val($)
32{
33 my $name = shift;
34 my $val = "";
35 my $line;
36
37 while($line = <TEST_DATA>)
38 {
39 next if($line !~ /=/);
40 last;
41 }
42
43 ($val) = ($line =~ /^$name = (\w+)/);
44
45 return $val;
46}
47
48my $cnt = 1;;
49while (my $line = <TEST_DATA>)
50{
51 my $key_len = get_suite_val("Keylen");
52 next if ($key_len !~ /\d+/);
53 my $iv_len = get_suite_val("IVlen");
54 my $pt_len = get_suite_val("PTlen");
55 my $add_len = get_suite_val("AADlen");
56 my $tag_len = get_suite_val("Taglen");
57
58 for ($cnt = 0; $cnt < 3; $cnt++)
59 {
60 my $Count = get_val("Count");
61 my $key = get_val("Key");
62 my $pt = get_val("PT");
63 my $add = get_val("AAD");
64 my $iv = get_val("IV");
65 my $ct = get_val("CT");
66 my $tag = get_val("Tag");
67
68 print("GCM NIST Validation (AES-$key_len,$iv_len,$pt_len,$add_len,$tag_len) #$Count\n");
69 print("gcm_encrypt_and_tag");
70 print(":\"$key\"");
71 print(":\"$pt\"");
72 print(":\"$iv\"");
73 print(":\"$add\"");
74 print(":\"$ct\"");
75 print(":$tag_len");
76 print(":\"$tag\"");
77 print(":0");
78 print("\n\n");
79 }
80}
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +020081
82print("GCM Selftest\n");
83print("gcm_selftest:\n\n");
84
Paul Bakker89e80c92012-03-20 13:50:09 +000085close(TEST_DATA);