Commit Graph

58 Commits

Author SHA1 Message Date
christos 8499346dc4 Handle OpenSSL-3.x 2023-05-09 20:02:59 +00:00
mrg 84bbce3d17 include bsd.own.mk to be sure NETBSDSRCDIR is set. 2021-04-12 04:19:32 +00:00
christos 5d858a7a6b - remove duplicate comment
- flush after printing the number
(from kre@)
2020-10-12 13:54:51 +00:00
christos c6669ee4d0 more clarifications. 2020-10-12 13:53:43 +00:00
christos df7f34cf57 mention hex numbers 2020-10-11 18:48:20 +00:00
christos 662c0e244b Remove is_hex_str() (trying to guess if a number was hex or not). It is not
documented and can lead to unexpected behavior.
2020-10-11 18:46:21 +00:00
christos f1aebb0c36 From gson@
- don't assume -h is always on for large factors
- fix saved large factors printing when -h
2020-10-11 17:18:34 +00:00
christos 0540874be3 - for readability when the exponent < 10 don't prefix it with 0x (from kre)
- fix usage
- merge printing code.
2020-10-07 19:48:29 +00:00
christos c5aeb8a719 PR/55695: Andreas Gustafsson: factor(6) -h option doesn't always work
Handle -h for factors greater than the primes table.
2020-10-05 21:11:47 +00:00
christos a17b1cd2d7 revert previous and don't parse octal 2020-10-05 14:31:30 +00:00
tnn 7f481043e4 factor: usage(): mark __dead 2020-10-05 12:22:49 +00:00
christos 2c61d0e8cd - Accept octal input.
- Don't play with the original string so we can print it.
2020-10-04 19:32:15 +00:00
kre 5bbbc6a94d Fix a typo (s/int/in/) 2020-10-04 14:22:52 +00:00
christos 5e85fe34cc PR/55693: Andreas Gustafsson: factor(6) lists factors in wrong order
Sync with FreeBSD and change their -h (that printed hex) to -x because
we were already using -h.
2020-10-03 22:27:00 +00:00
christos 64a90adb69 fix for OpenSSL-1.1 2018-02-06 16:53:27 +00:00
rin f345b5cb3f Add -h option to factor(6): duplicate factors are printed in
"human-readable" form of x^n.
2017-11-11 23:48:44 +00:00
riastradh ef315f7931 Remove MKCRYPTO option.
Originally, MKCRYPTO was introduced because the United States
classified cryptography as a munition and restricted its export.  The
export controls were substantially relaxed fifteen years ago, and are
essentially irrelevant for software with published source code.

In the intervening time, nobody bothered to remove the option after
its motivation -- the US export restriction -- was eliminated.  I'm
not aware of any other operating system that has a similar option; I
expect it is mainly out of apathy for churn that we still have it.
Today, cryptography is an essential part of modern computing -- you
can't use the internet responsibly without cryptography.

The position of the TNF board of directors is that TNF makes no
representation that MKCRYPTO=no satisfies any country's cryptography
regulations.

My personal position is that the availability of cryptography is a
basic human right; that any local laws restricting it to a privileged
few are fundamentally immoral; and that it is wrong for developers to
spend effort crippling cryptography to work around such laws.

As proposed on tech-crypto, tech-security, and tech-userlevel to no
objections:

https://mail-index.netbsd.org/tech-crypto/2017/05/06/msg000719.html
https://mail-index.netbsd.org/tech-security/2017/05/06/msg000928.html
https://mail-index.netbsd.org/tech-userlevel/2017/05/06/msg010547.html

P.S.  Reviewing all the uses of MKCRYPTO in src revealed a lot of
*bad* crypto that was conditional on it, e.g. DES in telnet...  That
should probably be removed too, but on the grounds that it is bad,
not on the grounds that it is (nominally) crypto.
2017-05-21 15:28:36 +00:00
ast bfe1fbfe02 Imported and adapted from FreeBSD svn r272166 and r272207; this fixes
false positives for products of primes larger than 2^16. For example,
before this commit:

  $ /usr/games/primes 4295360521 4295360522
  4295360521
but
  $ /usr/games/factor 4295360521
  4295360521: 65539 65539

or
  $ /usr/games/primes 3825123056546413049 3825123056546413050
  3825123056546413049
yet
  $ /usr/games/factor 3825123056546413049
  3825123056546413049: 165479 23115459100831

or
  $ /usr/games/primes 18446744073709551577
  18446744073709551577
although
  $ /usr/games/factor 18446744073709551577
  18446744073709551577: 139646831 132095686967

Incidentally, the above examples show the smallest and largest cases that
were erroneously stated as prime in the range 2^32 .. 3825123056546413049
.. 2^64; the primes(6) program now stops at 3825123056546413050 as
primality tests on larger integers would be by brute force factorization.

In addition, special to the NetBSD version:
. for -d option, skip first difference when start is >65537 as it is incorrect
. corrected usage to mention both the existing -d as well as the new -h option

For original FreeBSD commit message by Colin Percival, see:
http://svnweb.freebsd.org/base?view=revision&revision=272166
2014-10-02 21:36:37 +00:00
drochner 7621b801a7 remove duplicated #defines (in a usually unused part of the code) 2011-11-09 20:17:44 +00:00
joerg cbd2e3d54f Properly print string. 2011-05-23 22:49:59 +00:00
joerg 6394298f1b Follow the Fundamental Theory of Algebra. Disallow factorising of
numbers less than 2 as it is not
- naturally unique (negative numbers)
- finite (0)
- non-empty (1)

Discussed with the kristaps and wiz
2010-05-15 21:22:39 +00:00
tnozaki 50eb6aadde cast isblank(3)'s argument to unsigned char. 2010-05-13 17:52:11 +00:00
drochner d184555b35 rename pollard_pminus1->pollard_rho for consistency 2010-04-28 18:04:31 +00:00
drochner fe64100e9e -Fix an old bug in the "pollard" code: it gets its argument passed
by reference, and changes the value behind the pointer under some
 circumstances (basically if it finds more than 2 different factors).
 It also calls itself if it finds a factor which is not considered prime
 (by openssl's miller-rabin check) and uses the call argument afterwards.
 This doesn't work -- we need to copy the argument into its own storage.
-Modify the code to do the "rho" algorithm as was initially announced.
 It takes somewhat longer in rare cases, but still works in cases where
 the "p-1" algorithm is unusable. This might fix PR misc/43192
 by Luiz Henrique de Figueiredo.
-Add some optional debug support, minor cleanup.
2010-04-27 18:11:19 +00:00
drochner f79e06d729 fix an obvious flaw in bounds check: the array of precomputed primes
could be overrun if its last entry (65537) was a factor of the input
(this does not affect PR misc/43192 -- the factors are much larger
here: 7742394596501*159455563099482401)
2010-04-22 14:28:48 +00:00
wiz 0b27f753a1 Add backslash before a dash to get a minus. 2010-04-22 06:57:13 +00:00
dholland 9f8746b55e Sync with reality. Bump date. 2010-04-22 04:42:21 +00:00
dholland e0ba63fe83 sprinkle static 2009-08-12 05:48:04 +00:00
lukem 2fe2731d3f Remove the \n and tabs from the __COPYRIGHT() strings. 2008-07-20 00:52:39 +00:00
perry 8b0f9554ff convert __attribute__s to applicable cdefs.h macros 2007-12-15 19:44:37 +00:00
rillig 1a815e1f74 Fixed a comment that said the factors in the output would be strictly
ascending.
2005-06-27 20:49:31 +00:00
christos ceb0805a9b Add -lcrypt where -lcrypto is specified. 2005-03-09 03:11:21 +00:00
jsm 4eccb08bd5 Separate primes manpage from that of factor. Correct DIAGNOSTICS
information.
2004-02-08 13:16:25 +00:00
jsm 4eec310a4f Check large factor for being prime before applying Pollard's
algorithm; fixes "factor 2147483647111311".  Correct comment;
algorithm is Pollard p-1, not Pollard rho.  Increase base if p-1
algorithm reaches 1; fixes "factor 99999999999991".  Testcases from
David A Bagley <bagleyd@tux.org>.
2004-02-08 11:47:36 +00:00
agc e5aeb4ea46 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22269, verified by myself.
2003-08-07 09:36:50 +00:00
wiz c91d8d6b9b Lots of minor fixes resulting from reading these man pages in detail. 2002-09-26 18:31:58 +00:00
lukem 0be7b964d2 use NETBSDSRCDIR as appropriate 2002-09-19 03:15:39 +00:00
simonb aab04f503e Provide a BN_dec2bn() shim for the non-openssl case that reports an error
if strtoul() fails.
2002-06-18 23:07:36 +00:00
simonb da942834bb Fix a logic botch where if a number smaller than the square of the seive
was prime to still called the Pollard Rho function when it didn't have
to.  Problem report by Nathan Williams.

Unfortunately this one can't be picked up by a simple regression test
since the broken way still produced the correct output, but just took
far longer...
2002-06-17 15:43:52 +00:00
itojun 69757aee7e make factor work with and without openssl. 2002-06-16 22:24:00 +00:00
simonb a311a7732d Use libcrypto's bignum support to implement a Pollard Rho factoring
algorithm so we can factorise numbers larger than a host long.
2002-06-15 02:12:23 +00:00
wiz 834bb1b3ab Whitespace and/or punctuation fixes. 2001-04-02 22:42:37 +00:00
jsm 092d313019 Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).

Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-08 21:17:44 +00:00
hubertf 1c9494f62b mark non-returning functions (PR#6144 by Joseph Myers <jsm28@cam.ac.uk>) 1998-09-13 15:27:25 +00:00
lukem dd1343dba9 use CPPFLAGS instead of CFLAGS 1997-10-22 04:42:45 +00:00
lukem 82090a8bf1 WARNSify 1997-10-10 12:49:45 +00:00
gwr 10e180cc49 Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
1997-05-08 21:11:01 +00:00
gwr 012e528f2e Use .PATH.c: ... 1997-05-06 20:44:56 +00:00
tls 34cd8f5bdf Sync to 4.4BSD-Lite2 1997-01-07 11:56:32 +00:00
cgd 42fb1b9d4a merge with Lite, new RCS id conventions, etc. 1995-03-23 08:28:00 +00:00