Deleted Added
full compact
factor.c (199815) factor.c (216598)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Landon Curt Noll.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38#endif
39#ifdef __SCCSID
40__SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95");
41#endif
42#ifdef __RCSID
43__RCSID("$NetBSD: factor.c,v 1.19 2009/08/12 05:54:31 dholland Exp $");
44#endif
45#ifdef __FBSDID
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Landon Curt Noll.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 29 unchanged lines hidden (view full) ---

38#endif
39#ifdef __SCCSID
40__SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95");
41#endif
42#ifdef __RCSID
43__RCSID("$NetBSD: factor.c,v 1.19 2009/08/12 05:54:31 dholland Exp $");
44#endif
45#ifdef __FBSDID
46__FBSDID("$FreeBSD: head/games/factor/factor.c 199815 2009-11-26 00:38:13Z fanf $");
46__FBSDID("$FreeBSD: head/games/factor/factor.c 216598 2010-12-20 19:07:56Z uqs $");
47#endif
48#endif /* not lint */
49
50/*
51 * factor - factor a number into primes
52 *
53 * By: Landon Curt Noll chongo@toad.com, ...!{sun,tolsoft}!hoptoad!chongo
54 *

--- 151 unchanged lines hidden (view full) ---

206
207 /* Watch for primes larger than the table. */
208 if (fact > pr_limit) {
209#ifdef HAVE_OPENSSL
210 BIGNUM *bnfact;
211
212 bnfact = BN_new();
213 BN_set_word(bnfact, *(fact - 1));
47#endif
48#endif /* not lint */
49
50/*
51 * factor - factor a number into primes
52 *
53 * By: Landon Curt Noll chongo@toad.com, ...!{sun,tolsoft}!hoptoad!chongo
54 *

--- 151 unchanged lines hidden (view full) ---

206
207 /* Watch for primes larger than the table. */
208 if (fact > pr_limit) {
209#ifdef HAVE_OPENSSL
210 BIGNUM *bnfact;
211
212 bnfact = BN_new();
213 BN_set_word(bnfact, *(fact - 1));
214 BN_sqr(bnfact, bnfact, ctx);
214 if (!BN_sqr(bnfact, bnfact, ctx))
215 errx(1, "error in BN_sqr()");
215 if (BN_cmp(bnfact, val) > 0 ||
216 BN_is_prime(val, PRIME_CHECKS,
217 NULL, NULL, NULL) == 1)
218 pr_print(val);
219 else
220 pollard_pminus1(val);
221#else
222 pr_print(val);

--- 43 unchanged lines hidden (view full) ---

266 base = BN_new();
267 rbase = BN_new();
268 num = BN_new();
269 i = BN_new();
270 x = BN_new();
271
272 BN_set_word(rbase, 1);
273newbase:
216 if (BN_cmp(bnfact, val) > 0 ||
217 BN_is_prime(val, PRIME_CHECKS,
218 NULL, NULL, NULL) == 1)
219 pr_print(val);
220 else
221 pollard_pminus1(val);
222#else
223 pr_print(val);

--- 43 unchanged lines hidden (view full) ---

267 base = BN_new();
268 rbase = BN_new();
269 num = BN_new();
270 i = BN_new();
271 x = BN_new();
272
273 BN_set_word(rbase, 1);
274newbase:
274 BN_add_word(rbase, 1);
275 if (!BN_add_word(rbase, 1))
276 errx(1, "error in BN_add_word()");
275 BN_set_word(i, 2);
276 BN_copy(base, rbase);
277
278 for (;;) {
279 BN_mod_exp(base, base, i, val, ctx);
280 if (BN_is_one(base))
281 goto newbase;
282
283 BN_copy(x, base);
284 BN_sub_word(x, 1);
277 BN_set_word(i, 2);
278 BN_copy(base, rbase);
279
280 for (;;) {
281 BN_mod_exp(base, base, i, val, ctx);
282 if (BN_is_one(base))
283 goto newbase;
284
285 BN_copy(x, base);
286 BN_sub_word(x, 1);
285 BN_gcd(x, x, val, ctx);
287 if (!BN_gcd(x, x, val, ctx))
288 errx(1, "error in BN_gcd()");
286
287 if (!BN_is_one(x)) {
288 if (BN_is_prime(x, PRIME_CHECKS, NULL, NULL,
289 NULL) == 1)
290 pr_print(x);
291 else
292 pollard_pminus1(x);
293 fflush(stdout);

--- 4 unchanged lines hidden (view full) ---

298 if (BN_is_prime(num, PRIME_CHECKS, NULL, NULL,
299 NULL) == 1) {
300 pr_print(num);
301 fflush(stdout);
302 return;
303 }
304 BN_copy(val, num);
305 }
289
290 if (!BN_is_one(x)) {
291 if (BN_is_prime(x, PRIME_CHECKS, NULL, NULL,
292 NULL) == 1)
293 pr_print(x);
294 else
295 pollard_pminus1(x);
296 fflush(stdout);

--- 4 unchanged lines hidden (view full) ---

301 if (BN_is_prime(num, PRIME_CHECKS, NULL, NULL,
302 NULL) == 1) {
303 pr_print(num);
304 fflush(stdout);
305 return;
306 }
307 BN_copy(val, num);
308 }
306 BN_add_word(i, 1);
309 if (!BN_add_word(i, 1))
310 errx(1, "error in BN_add_word()");
307 }
308}
309
310/*
311 * Sigh.. No _decimal_ output to file functions in BN.
312 */
313static void
314BN_print_dec_fp(FILE *fp, const BIGNUM *num)

--- 55 unchanged lines hidden ---
311 }
312}
313
314/*
315 * Sigh.. No _decimal_ output to file functions in BN.
316 */
317static void
318BN_print_dec_fp(FILE *fp, const BIGNUM *num)

--- 55 unchanged lines hidden ---