summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-03-25 11:28:55 +0000
committertb <>2023-03-25 11:28:55 +0000
commit4098a9da93210ffa62b38cbf37595ecadbaa1207 (patch)
treea900846f7a07bac53d5d2485ab556e0ab38906f2 /src
parenta666002c655fe419f19baf61e52bc8cd79527013 (diff)
downloadopenbsd-4098a9da93210ffa62b38cbf37595ecadbaa1207.tar.gz
openbsd-4098a9da93210ffa62b38cbf37595ecadbaa1207.tar.bz2
openbsd-4098a9da93210ffa62b38cbf37595ecadbaa1207.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.pl42
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.
64die "$num must be smaller than 6543" if $num >= 6543; 64die "$num must be smaller than 6543" if $num >= 6543;
65 65
66push(@primes,2); 66push(@primes, 2);
67$p=1; 67$p = 1;
68loop: 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++) 69loop:
74 { 70while ($#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
80printf("/*\t\$" . "OpenBSD" . "\$ */\n"); 81printf("/*\t\$" . "OpenBSD" . "\$ */\n");
81print <<\EOF; 82print <<\EOF;
@@ -87,14 +88,7 @@ EOF
87 88
88print "#include \"bn_prime.h\"\n\n"; 89print "#include \"bn_prime.h\"\n\n";
89print "const uint16_t primes[NUMPRIMES] = {"; 90print "const uint16_t primes[NUMPRIMES] = {";
90for ($i=0; $i <= $#primes; $i++) 91for ($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 }
100print "\n};\n"; 94print "\n};\n";