diff options
| author | tb <> | 2023-03-25 11:28:55 +0000 |
|---|---|---|
| committer | tb <> | 2023-03-25 11:28:55 +0000 |
| commit | f50bb7ce0720248882d9202fe6f4547788ff9b51 (patch) | |
| tree | a900846f7a07bac53d5d2485ab556e0ab38906f2 /src | |
| parent | 7ecbd890715f86fc72d507a56e989d43308d0cee (diff) | |
| download | openbsd-f50bb7ce0720248882d9202fe6f4547788ff9b51.tar.gz openbsd-f50bb7ce0720248882d9202fe6f4547788ff9b51.tar.bz2 openbsd-f50bb7ce0720248882d9202fe6f4547788ff9b51.zip | |
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 'src')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_prime.pl | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/src/lib/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl index 0932811fe5..273e958079 100644 --- a/src/lib/libcrypto/bn/bn_prime.pl +++ b/src/lib/libcrypto/bn/bn_prime.pl | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #!/bin/perl | 1 | #!/bin/perl |
| 2 | # $OpenBSD: bn_prime.pl,v 1.9 2023/03/25 11:09:58 tb Exp $ | 2 | # $OpenBSD: bn_prime.pl,v 1.10 2023/03/25 11:28:55 tb Exp $ |
| 3 | # | 3 | # |
| 4 | # Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 4 | # Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
| 5 | # All rights reserved. | 5 | # All rights reserved. |
| @@ -57,25 +57,26 @@ | |||
| 57 | # copied and put under another distribution licence | 57 | # copied and put under another distribution licence |
| 58 | # [including the GNU Public Licence.] | 58 | # [including the GNU Public Licence.] |
| 59 | 59 | ||
| 60 | $num=2048; | 60 | $num = 2048; |
| 61 | $num=$ARGV[0] if ($#ARGV >= 0); | 61 | $num = $ARGV[0] if $#ARGV >= 0; |
| 62 | 62 | ||
| 63 | # The 6543rd prime is 2^16 + 1. | 63 | # The 6543rd prime is 2^16 + 1. |
| 64 | die "$num must be smaller than 6543" if $num >= 6543; | 64 | die "$num must be smaller than 6543" if $num >= 6543; |
| 65 | 65 | ||
| 66 | push(@primes,2); | 66 | push(@primes, 2); |
| 67 | $p=1; | 67 | $p = 1; |
| 68 | loop: while ($#primes < $num-1) | ||
| 69 | { | ||
| 70 | $p+=2; | ||
| 71 | $s=int(sqrt($p)); | ||
| 72 | 68 | ||
| 73 | for ($i=0; defined($primes[$i]) && $primes[$i]<=$s; $i++) | 69 | loop: |
| 74 | { | 70 | while ($#primes < $num-1) { |
| 75 | next loop if (($p%$primes[$i]) == 0); | 71 | $p += 2; |
| 76 | } | 72 | $s = int(sqrt($p)); |
| 77 | push(@primes,$p); | 73 | |
| 74 | for ($i = 0; defined($primes[$i]) && $primes[$i] <= $s; $i++) { | ||
| 75 | next loop if $p % $primes[$i] == 0; | ||
| 78 | } | 76 | } |
| 77 | die "\$primes[$i] is too large: $primes[$i]" if $primes[$i] > 65535; | ||
| 78 | push(@primes, $p); | ||
| 79 | } | ||
| 79 | 80 | ||
| 80 | printf("/*\t\$" . "OpenBSD" . "\$ */\n"); | 81 | printf("/*\t\$" . "OpenBSD" . "\$ */\n"); |
| 81 | print <<\EOF; | 82 | print <<\EOF; |
| @@ -87,14 +88,7 @@ EOF | |||
| 87 | 88 | ||
| 88 | print "#include \"bn_prime.h\"\n\n"; | 89 | print "#include \"bn_prime.h\"\n\n"; |
| 89 | print "const uint16_t primes[NUMPRIMES] = {"; | 90 | print "const uint16_t primes[NUMPRIMES] = {"; |
| 90 | for ($i=0; $i <= $#primes; $i++) | 91 | for ($i = 0; $i <= $#primes; $i++) { |
| 91 | { | 92 | printf("%s%5d,", $i % 8 == 0 ? "\n\t" : " ", $primes[$i]); |
| 92 | if ((($i%8) == 0)) { | 93 | } |
| 93 | printf("\n\t") | ||
| 94 | } else { | ||
| 95 | printf(" "); | ||
| 96 | } | ||
| 97 | die "\$primes[$i] is too large: $primes[$i]" if $primes[$i] > 65535; | ||
| 98 | printf("%5d,",$primes[$i]); | ||
| 99 | } | ||
| 100 | print "\n};\n"; | 94 | print "\n};\n"; |
