diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2023-03-25 11:28:56 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2023-03-25 11:28:56 +0000 |
commit | 50d47a8da9bd675786396730e9241dcc658ae0c0 (patch) | |
tree | 6f75e4bb8bbdd0f470903befe1d706dc493d08a6 /lib | |
parent | 91bc1b9b7fa6f201b32b12ae4c5681145cbfacb3 (diff) |
Make an attempt at reducing the eyebleed in bn_prime.pl
Use a style more resembling KNF and drop lots of parentheses. Simplify
a few things. No change in generated output on success.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libcrypto/bn/bn_prime.pl | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/lib/libcrypto/bn/bn_prime.pl b/lib/libcrypto/bn/bn_prime.pl index 0932811fe59..273e9580792 100644 --- a/lib/libcrypto/bn/bn_prime.pl +++ b/lib/libcrypto/bn/bn_prime.pl @@ -1,5 +1,5 @@ #!/bin/perl -# $OpenBSD: bn_prime.pl,v 1.9 2023/03/25 11:09:58 tb Exp $ +# $OpenBSD: bn_prime.pl,v 1.10 2023/03/25 11:28:55 tb Exp $ # # Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) # All rights reserved. @@ -57,25 +57,26 @@ # copied and put under another distribution licence # [including the GNU Public Licence.] -$num=2048; -$num=$ARGV[0] if ($#ARGV >= 0); +$num = 2048; +$num = $ARGV[0] if $#ARGV >= 0; # The 6543rd prime is 2^16 + 1. die "$num must be smaller than 6543" if $num >= 6543; -push(@primes,2); -$p=1; -loop: while ($#primes < $num-1) - { - $p+=2; - $s=int(sqrt($p)); +push(@primes, 2); +$p = 1; - for ($i=0; defined($primes[$i]) && $primes[$i]<=$s; $i++) - { - next loop if (($p%$primes[$i]) == 0); - } - push(@primes,$p); +loop: +while ($#primes < $num-1) { + $p += 2; + $s = int(sqrt($p)); + + for ($i = 0; defined($primes[$i]) && $primes[$i] <= $s; $i++) { + next loop if $p % $primes[$i] == 0; } + die "\$primes[$i] is too large: $primes[$i]" if $primes[$i] > 65535; + push(@primes, $p); +} printf("/*\t\$" . "OpenBSD" . "\$ */\n"); print <<\EOF; @@ -87,14 +88,7 @@ EOF print "#include \"bn_prime.h\"\n\n"; print "const uint16_t primes[NUMPRIMES] = {"; -for ($i=0; $i <= $#primes; $i++) - { - if ((($i%8) == 0)) { - printf("\n\t") - } else { - printf(" "); - } - die "\$primes[$i] is too large: $primes[$i]" if $primes[$i] > 65535; - printf("%5d,",$primes[$i]); - } +for ($i = 0; $i <= $#primes; $i++) { + printf("%s%5d,", $i % 8 == 0 ? "\n\t" : " ", $primes[$i]); +} print "\n};\n"; |