2016-04-20 02:10:43 +00:00
|
|
|
#! /usr/bin/env perl
|
2019-01-02 00:19:43 +00:00
|
|
|
# Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved.
|
2016-04-20 02:10:43 +00:00
|
|
|
#
|
|
|
|
# Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
# this file except in compliance with the License. You can obtain a copy
|
|
|
|
# in the file LICENSE in the source distribution or at
|
|
|
|
# https://www.openssl.org/source/license.html
|
|
|
|
|
2006-04-18 23:36:07 +00:00
|
|
|
|
2009-02-10 13:03:31 +00:00
|
|
|
use strict;
|
|
|
|
|
|
|
|
my %xref_tbl;
|
|
|
|
my %oid_tbl;
|
|
|
|
|
|
|
|
my ($mac_file, $xref_file) = @ARGV;
|
|
|
|
|
2018-02-13 18:09:02 +00:00
|
|
|
# Output year depends on the year of the script and the input file.
|
|
|
|
my $YEAR = [localtime([stat($0)]->[9])]->[5] + 1900;
|
|
|
|
my $iYEAR = [localtime([stat($mac_file)]->[9])]->[5] + 1900;
|
|
|
|
$YEAR = $iYEAR if $iYEAR > $YEAR;
|
|
|
|
$iYEAR = [localtime([stat($xref_file)]->[9])]->[5] + 1900;
|
|
|
|
$YEAR = $iYEAR if $iYEAR > $YEAR;
|
|
|
|
|
2015-06-23 11:27:23 +00:00
|
|
|
open(IN, $mac_file) || die "Can't open $mac_file, $!\n";
|
2006-04-18 23:36:07 +00:00
|
|
|
|
|
|
|
# Read in OID nid values for a lookup table.
|
|
|
|
|
|
|
|
while (<IN>)
|
|
|
|
{
|
Perl's chop / chomp considered bad, use a regexp instead
Once upon a time, there was chop, which somply chopped off the last
character of $_ or a given variable, and it was used to take off the
EOL character (\n) of strings.
... but then, you had to check for the presence of such character.
So came chomp, the better chop which checks for \n before chopping it
off. And this worked well, as long as Perl made internally sure that
all EOLs were converted to \n.
These days, though, there seems to be a mixture of perls, so lines
from files in the "wrong" environment might have \r\n as EOL, or just
\r (Mac OS, unless I'm misinformed).
So it's time we went for the more generic variant and use s|\R$||, the
better chomp which recognises all kinds of known EOLs and chops them
off.
A few chops were left alone, as they are use as surgical tools to
remove one last slash or one last comma.
NOTE: \R came with perl 5.10.0. It means that from now on, our
scripts will fail with any older version.
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-02-11 20:47:30 +00:00
|
|
|
s|\R$||; # Better chomp
|
2006-04-18 23:36:07 +00:00
|
|
|
my ($name, $num) = /^(\S+)\s+(\S+)$/;
|
|
|
|
$oid_tbl{$name} = $num;
|
|
|
|
}
|
|
|
|
close IN;
|
|
|
|
|
2015-06-23 11:27:23 +00:00
|
|
|
open(IN, $xref_file) || die "Can't open $xref_file, $!\n";
|
2006-04-18 23:36:07 +00:00
|
|
|
|
|
|
|
my $ln = 1;
|
|
|
|
|
|
|
|
while (<IN>)
|
|
|
|
{
|
Perl's chop / chomp considered bad, use a regexp instead
Once upon a time, there was chop, which somply chopped off the last
character of $_ or a given variable, and it was used to take off the
EOL character (\n) of strings.
... but then, you had to check for the presence of such character.
So came chomp, the better chop which checks for \n before chopping it
off. And this worked well, as long as Perl made internally sure that
all EOLs were converted to \n.
These days, though, there seems to be a mixture of perls, so lines
from files in the "wrong" environment might have \r\n as EOL, or just
\r (Mac OS, unless I'm misinformed).
So it's time we went for the more generic variant and use s|\R$||, the
better chomp which recognises all kinds of known EOLs and chops them
off.
A few chops were left alone, as they are use as surgical tools to
remove one last slash or one last comma.
NOTE: \R came with perl 5.10.0. It means that from now on, our
scripts will fail with any older version.
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-02-11 20:47:30 +00:00
|
|
|
s|\R$||; # Better chomp
|
2006-04-18 23:36:07 +00:00
|
|
|
s/#.*$//;
|
|
|
|
next if (/^\S*$/);
|
|
|
|
my ($xr, $p1, $p2) = /^(\S+)\s+(\S+)\s+(\S+)/;
|
|
|
|
check_oid($xr);
|
|
|
|
check_oid($p1);
|
|
|
|
check_oid($p2);
|
|
|
|
$xref_tbl{$xr} = [$p1, $p2, $ln];
|
|
|
|
}
|
|
|
|
|
|
|
|
my @xrkeys = keys %xref_tbl;
|
|
|
|
|
|
|
|
my @srt1 = sort { $oid_tbl{$a} <=> $oid_tbl{$b}} @xrkeys;
|
|
|
|
|
2012-04-22 21:18:30 +00:00
|
|
|
my $i;
|
|
|
|
for($i = 0; $i <= $#srt1; $i++)
|
2006-04-18 23:36:07 +00:00
|
|
|
{
|
|
|
|
$xref_tbl{$srt1[$i]}[2] = $i;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @srt2 = sort
|
|
|
|
{
|
|
|
|
my$ap1 = $oid_tbl{$xref_tbl{$a}[0]};
|
|
|
|
my$bp1 = $oid_tbl{$xref_tbl{$b}[0]};
|
|
|
|
return $ap1 - $bp1 if ($ap1 != $bp1);
|
|
|
|
my$ap2 = $oid_tbl{$xref_tbl{$a}[1]};
|
|
|
|
my$bp2 = $oid_tbl{$xref_tbl{$b}[1]};
|
|
|
|
|
|
|
|
return $ap2 - $bp2;
|
|
|
|
} @xrkeys;
|
2009-04-07 16:33:26 +00:00
|
|
|
|
|
|
|
my $pname = $0;
|
2015-06-23 11:27:23 +00:00
|
|
|
$pname =~ s|.*/||;
|
2006-04-18 23:36:07 +00:00
|
|
|
|
|
|
|
print <<EOF;
|
2016-05-17 21:38:18 +00:00
|
|
|
/*
|
|
|
|
* WARNING: do not edit!
|
|
|
|
* Generated by $pname
|
|
|
|
*
|
2018-02-13 18:09:02 +00:00
|
|
|
* Copyright 1998-$YEAR The OpenSSL Project Authors. All Rights Reserved.
|
2016-05-17 21:38:18 +00:00
|
|
|
*
|
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
2006-04-18 23:36:07 +00:00
|
|
|
|
2015-02-04 03:31:34 +00:00
|
|
|
typedef struct {
|
|
|
|
int sign_id;
|
|
|
|
int hash_id;
|
|
|
|
int pkey_id;
|
|
|
|
} nid_triple;
|
2006-04-18 23:36:07 +00:00
|
|
|
|
2016-01-06 02:54:18 +00:00
|
|
|
DEFINE_STACK_OF(nid_triple)
|
|
|
|
|
2015-02-04 03:31:34 +00:00
|
|
|
static const nid_triple sigoid_srt[] = {
|
2006-04-18 23:36:07 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
foreach (@srt1)
|
|
|
|
{
|
|
|
|
my $xr = $_;
|
|
|
|
my ($p1, $p2) = @{$xref_tbl{$_}};
|
2015-02-04 03:31:34 +00:00
|
|
|
my $o1 = " {NID_$xr, NID_$p1,";
|
|
|
|
my $o2 = "NID_$p2},";
|
|
|
|
if (length("$o1 $o2") < 78)
|
|
|
|
{
|
|
|
|
print "$o1 $o2\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print "$o1\n $o2\n";
|
|
|
|
}
|
|
|
|
}
|
2006-04-18 23:36:07 +00:00
|
|
|
|
2015-02-04 03:31:34 +00:00
|
|
|
print "};";
|
2006-04-18 23:36:07 +00:00
|
|
|
print <<EOF;
|
|
|
|
|
|
|
|
|
2015-02-04 03:31:34 +00:00
|
|
|
static const nid_triple *const sigoid_srt_xref[] = {
|
2006-04-18 23:36:07 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
foreach (@srt2)
|
|
|
|
{
|
2014-11-01 00:10:56 +00:00
|
|
|
my ($p1, $p2, $x) = @{$xref_tbl{$_}};
|
|
|
|
# If digest or signature algorithm is "undef" then the algorithm
|
|
|
|
# needs special handling and is excluded from the cross reference table.
|
|
|
|
next if $p1 eq "undef" || $p2 eq "undef";
|
2015-02-04 03:31:34 +00:00
|
|
|
print " \&sigoid_srt\[$x\],\n";
|
2006-04-18 23:36:07 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 03:31:34 +00:00
|
|
|
print "};\n";
|
2006-04-18 23:36:07 +00:00
|
|
|
|
|
|
|
sub check_oid
|
|
|
|
{
|
|
|
|
my ($chk) = @_;
|
|
|
|
if (!exists $oid_tbl{$chk})
|
|
|
|
{
|
Perl's chop / chomp considered bad, use a regexp instead
Once upon a time, there was chop, which somply chopped off the last
character of $_ or a given variable, and it was used to take off the
EOL character (\n) of strings.
... but then, you had to check for the presence of such character.
So came chomp, the better chop which checks for \n before chopping it
off. And this worked well, as long as Perl made internally sure that
all EOLs were converted to \n.
These days, though, there seems to be a mixture of perls, so lines
from files in the "wrong" environment might have \r\n as EOL, or just
\r (Mac OS, unless I'm misinformed).
So it's time we went for the more generic variant and use s|\R$||, the
better chomp which recognises all kinds of known EOLs and chops them
off.
A few chops were left alone, as they are use as surgical tools to
remove one last slash or one last comma.
NOTE: \R came with perl 5.10.0. It means that from now on, our
scripts will fail with any older version.
Reviewed-by: Rich Salz <rsalz@openssl.org>
2016-02-11 20:47:30 +00:00
|
|
|
die "Can't find \"$chk\"\n";
|
2006-04-18 23:36:07 +00:00
|
|
|
}
|
|
|
|
}
|