Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dmitry Baryshkov
nettle
Commits
9359db63
Commit
9359db63
authored
Apr 13, 2014
by
Niels Möller
Browse files
Deleted the nettle_next_prime function.
parent
877fa24c
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
9359db63
2014-04-13 Niels Möller <nisse@lysator.liu.se>
* examples/next-prime.c: Deleted file.
* bignum-next-prime.c (nettle_next_prime): Deleted file and
function.
* prime-list.h: Deleted file.
* bignum.h (nettle_next_prime): Deleted prototype.
* Makefile.in (hogweed_SOURCES): Deleted bignum-next-prime.c.
(DISTFILES): Deleted prime-list.h.
* examples/Makefile.in (HOGWEED_TARGETS): Deleted next-prime, and
corresponding make target.
2014-04-12 Niels Möller <nisse@lysator.liu.se>
* nettle.texinfo (Copyright): Updated licensing info.
...
...
Makefile.in
View file @
9359db63
...
...
@@ -134,8 +134,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
hogweed_SOURCES
=
sexp.c sexp-format.c
\
sexp-transport.c sexp-transport-format.c
\
bignum.c bignum-next-prime.c
\
bignum-random.c bignum-random-prime.c
\
bignum.c bignum-random.c bignum-random-prime.c
\
sexp2bignum.c
\
pkcs1.c pkcs1-encrypt.c pkcs1-decrypt.c
\
pkcs1-rsa-digest.c pkcs1-rsa-md5.c pkcs1-rsa-sha1.c
\
...
...
@@ -203,7 +202,7 @@ DISTFILES = $(SOURCES) $(HEADERS) getopt.h .bootstrap run-tests \
$(des_headers)
descore.README
\
aes-internal.h camellia-internal.h serpent-internal.h
\
cast128_sboxes.h desinfo.h desCode.h
\
nettle-internal.h nettle-write.h
prime-list.h
\
nettle-internal.h nettle-write.h
\
gmp-glue.h ecc-internal.h
\
mini-gmp.h mini-gmp.c asm.m4
\
nettle.texinfo nettle.info nettle.html nettle.pdf sha-example.c
...
...
NEWS
View file @
9359db63
...
...
@@ -75,6 +75,11 @@ NEWS for the Nettle 3.0 release
changed from uint8_t * to void *, for consistency with
related libc functions.
Removed features:
* The nettle_next_prime function has been deleted.
Applications should use GMP's mpz_nextprime instead.
Bug fixes:
* Building with ./configure --disable-static now works.
...
...
bignum-next-prime.c
deleted
100644 → 0
View file @
877fa24c
/* bignum-next-prime.c
Copyright (C) 2002 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include
<limits.h>
/* Needed for alloca on freebsd */
#include
<stdlib.h>
#include
"bignum.h"
#include
"gmp-glue.h"
/* From gmp.h */
/* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */
#if defined (__GNUC__) && defined (__GNUC_MINOR__)
#define GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
#define GNUC_PREREQ(maj, min) 0
#endif
#if GNUC_PREREQ (3,0)
# define UNLIKELY(cond) __builtin_expect ((cond) != 0, 0)
#else
# define UNLIKELY(cond) cond
#endif
/* From some benchmarking using the examples nextprime(200!) and
nextprime(240!), it seems that it pays off to use a prime list up
to around 5000--10000 primes. There are 6541 odd primes less than
2^16. */
static
const
uint16_t
primes
[]
=
{
/* Generated by
./examples/eratosthenes 65535 \
| awk '{ if (NR % 10 == 2) printf ("\n"); if (NR > 1) printf("%d, ", $1); }
END { printf("\n"); }' > prime-list.h
*/
#include
"prime-list.h"
};
#define NUMBER_OF_PRIMES (sizeof(primes) / sizeof(primes[0]))
#ifdef mpz_millerrabin
# define PRIME_P mpz_millerrabin
#else
# define PRIME_P mpz_probab_prime_p
#endif
/* NOTE: The mpz_nextprime in current GMP is unoptimized. */
void
nettle_next_prime
(
mpz_t
p
,
mpz_t
n
,
unsigned
count
,
unsigned
prime_limit
,
void
*
progress_ctx
,
nettle_progress_func
*
progress
)
{
mpz_t
tmp
;
unsigned
difference
;
TMP_GMP_DECL
(
moduli
,
unsigned
);
if
(
prime_limit
>
NUMBER_OF_PRIMES
)
prime_limit
=
NUMBER_OF_PRIMES
;
/* First handle tiny numbers */
if
(
mpz_cmp_ui
(
n
,
2
)
<=
0
)
{
mpz_set_ui
(
p
,
2
);
return
;
}
mpz_set
(
p
,
n
);
mpz_setbit
(
p
,
0
);
if
(
mpz_cmp_ui
(
p
,
8
)
<
0
)
return
;
mpz_init
(
tmp
);
if
(
mpz_cmp_ui
(
p
,
primes
[
prime_limit
-
1
])
<=
0
)
/* Use only 3, 5 and 7 */
/* FIXME: Could do binary search in the table. */
prime_limit
=
3
;
/* Compute residues modulo small odd primes */
/* FIXME: Could be sped up by collecting limb-sized products of the
primes, to reduce the calls to mpz_fdiv_ui */
/* FIXME: Could also handle the first few primes separately; compute
the residue mod 15015 = 3 * 7 * 11 * 13, and tabulate the steps
between the 5760 odd numbers in this interval that have no factor
in common with 15015.
*/
TMP_GMP_ALLOC
(
moduli
,
prime_limit
);
{
unsigned
i
;
for
(
i
=
0
;
i
<
prime_limit
;
i
++
)
moduli
[
i
]
=
mpz_fdiv_ui
(
p
,
primes
[
i
]);
}
for
(
difference
=
0
;
;
difference
+=
2
)
{
int
composite
=
0
;
unsigned
i
;
if
(
difference
>=
UINT_MAX
-
10
)
{
/* Should not happen, at least not very often... */
mpz_add_ui
(
p
,
p
,
difference
);
difference
=
0
;
}
/* First check residues */
for
(
i
=
0
;
i
<
prime_limit
;
i
++
)
{
if
(
moduli
[
i
]
==
0
)
composite
=
1
;
moduli
[
i
]
+=
2
;
if
(
UNLIKELY
(
moduli
[
i
]
>=
primes
[
i
]))
moduli
[
i
]
-=
primes
[
i
];
}
if
(
composite
)
continue
;
mpz_add_ui
(
p
,
p
,
difference
);
difference
=
0
;
if
(
progress
)
progress
(
progress_ctx
,
'.'
);
/* Miller-Rabin test */
if
(
PRIME_P
(
p
,
count
))
break
;
#if 0
if (progress)
progress(progress_ctx, '*');
#endif
}
mpz_clear
(
tmp
);
TMP_GMP_FREE
(
moduli
);
}
bignum.h
View file @
9359db63
...
...
@@ -89,10 +89,6 @@ nettle_mpz_random(mpz_t x,
void
*
ctx
,
nettle_random_func
*
random
,
const
mpz_t
n
);
void
nettle_next_prime
(
mpz_t
p
,
mpz_t
n
,
unsigned
count
,
unsigned
prime_limit
,
void
*
progress_ctx
,
nettle_progress_func
*
progress
);
void
nettle_random_prime
(
mpz_t
p
,
unsigned
bits
,
int
top_bits_set
,
void
*
ctx
,
nettle_random_func
*
random
,
...
...
examples/Makefile.in
View file @
9359db63
...
...
@@ -15,7 +15,7 @@ BENCH_LIBS = @BENCH_LIBS@ -lm
HOGWEED_TARGETS
=
rsa-keygen
$(EXEEXT)
rsa-sign
$(EXEEXT)
\
rsa-verify
$(EXEEXT)
rsa-encrypt
$(EXEEXT)
rsa-decrypt
$(EXEEXT)
\
next-prime
$(EXEEXT)
random-prime
$(EXEEXT)
\
random-prime
$(EXEEXT)
\
hogweed-benchmark
$(EXEEXT)
ecc-benchmark
$(EXEEXT)
ENC_TARGETS
=
base16enc
$(EXEEXT)
base16dec
$(EXEEXT)
\
...
...
@@ -53,10 +53,6 @@ all: $(TARGETS)
(
cd
..
&&
$(MAKE)
nettle-internal.
$(OBJEXT)
)
# For Solaris and BSD make, we have to use an explicit rule for each executable
next-prime$(EXEEXT)
:
next-prime.$(OBJEXT) $(GETOPT_OBJS)
$(LINK)
next-prime.
$(OBJEXT)
$(GETOPT_OBJS)
\
-lhogweed
-lnettle
$(LIBS)
-o
next-prime
$(EXEEXT)
random-prime$(EXEEXT)
:
random-prime.$(OBJEXT) io.$(OBJEXT) $(GETOPT_OBJS)
$(LINK)
random-prime.
$(OBJEXT)
io.
$(OBJEXT)
$(GETOPT_OBJS)
\
-lhogweed
-lnettle
$(LIBS)
-o
random-prime
$(EXEEXT)
...
...
examples/next-prime.c
deleted
100644 → 0
View file @
877fa24c
/* next-prime.c
Command line tool for prime search.
Copyright (C) 2007 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
#include
"bignum.h"
#include
"getopt.h"
static
void
usage
(
void
)
{
fprintf
(
stderr
,
"Usage: next-prime [OPTIONS] number
\n\n
"
"Options:
\n
"
" --help Display this message.
\n
"
" -v, --verbose Display timing information.
\n
"
" --factorial Use factorial of input number.
\n
"
" -s --sieve-limit Number of primes to use for sieving.
\n
"
);
}
int
main
(
int
argc
,
char
**
argv
)
{
mpz_t
n
;
mpz_t
p
;
int
c
;
int
verbose
=
0
;
int
factorial
=
0
;
int
prime_limit
=
200
;
clock_t
start
;
clock_t
end
;
enum
{
OPT_HELP
=
300
};
static
const
struct
option
options
[]
=
{
/* Name, args, flag, val */
{
"help"
,
no_argument
,
NULL
,
OPT_HELP
},
{
"verbose"
,
no_argument
,
NULL
,
'v'
},
{
"factorial"
,
no_argument
,
NULL
,
'f'
},
{
"sieve-limit"
,
required_argument
,
NULL
,
's'
},
{
NULL
,
0
,
NULL
,
0
}
};
while
(
(
c
=
getopt_long
(
argc
,
argv
,
"vs:"
,
options
,
NULL
))
!=
-
1
)
switch
(
c
)
{
case
'v'
:
verbose
=
1
;
break
;
case
OPT_HELP
:
usage
();
return
EXIT_SUCCESS
;
case
'f'
:
factorial
=
1
;
break
;
case
's'
:
prime_limit
=
atoi
(
optarg
);
if
(
prime_limit
<
0
)
{
usage
();
return
EXIT_FAILURE
;
}
break
;
case
'?'
:
return
EXIT_FAILURE
;
default:
abort
();
}
argc
-=
optind
;
argv
+=
optind
;
if
(
argc
!=
1
)
{
usage
();
return
EXIT_FAILURE
;
}
mpz_init
(
n
);
if
(
factorial
)
{
long
arg
;
char
*
end
;
arg
=
strtol
(
argv
[
0
],
&
end
,
0
);
if
(
*
end
||
arg
<
0
)
{
fprintf
(
stderr
,
"Invalid number.
\n
"
);
return
EXIT_FAILURE
;
}
mpz_fac_ui
(
n
,
arg
);
}
else
if
(
mpz_set_str
(
n
,
argv
[
0
],
0
))
{
fprintf
(
stderr
,
"Invalid number.
\n
"
);
return
EXIT_FAILURE
;
}
if
(
mpz_cmp_ui
(
n
,
2
)
<=
0
)
{
printf
(
"2
\n
"
);
return
EXIT_SUCCESS
;
}
mpz_init
(
p
);
start
=
clock
();
nettle_next_prime
(
p
,
n
,
25
,
prime_limit
,
NULL
,
NULL
);
end
=
clock
();
mpz_out_str
(
stdout
,
10
,
p
);
printf
(
"
\n
"
);
if
(
verbose
)
{
mpz_t
d
;
mpz_init
(
d
);
mpz_sub
(
d
,
p
,
n
);
/* Avoid using gmp_fprintf, to stay compatible with gmp-3.1. */
fprintf
(
stderr
,
"bit size: %lu, diff: "
,
(
unsigned
long
)
mpz_sizeinbase
(
p
,
2
));
mpz_out_str
(
stderr
,
10
,
d
);
fprintf
(
stderr
,
", total time: %.3g s
\n
"
,
(
double
)(
end
-
start
)
/
CLOCKS_PER_SEC
);
}
return
EXIT_SUCCESS
;
}
prime-list.h
deleted
100644 → 0
View file @
877fa24c
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment