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
5b677535
Commit
5b677535
authored
Oct 03, 2014
by
Niels Möller
Browse files
Make ecc-sqrt-test work with mini-gmp.
parent
a3fb911e
Changes
4
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
5b677535
2014-10-03 Niels Möller <nisse@lysator.liu.se>
* testsuite/ecc-sqrt-test.c (mpz_ui_kronecker)
[NETTLE_USE_MINI_GMP]: New fallback definition when building with
mini-gmp.
* testsuite/testutils.c (gmp_randinit_default)
[NETTLE_USE_MINI_GMP]: Likewise.
(mpz_urandomb): Likewise.
* testsuite/testutils.h (gmp_randstate_t) [NETTLE_USE_MINI_GMP]:
Fallback typedef, using knuth_lfib_ctx.
2014-10-02 Niels Möller <nisse@lysator.liu.se>
* testsuite/eddsa-compress-test.c: New testcase.
...
...
testsuite/ecc-sqrt-test.c
View file @
5b677535
...
...
@@ -33,6 +33,38 @@
#define COUNT 5000
#if NETTLE_USE_MINI_GMP
/* Implements Legendre symbol only, requiring that p is an odd prime */
static
int
mpz_ui_kronecker
(
mp_limb_t
ul
,
const
mpz_t
p
)
{
mpz_t
t
,
u
;
int
r
;
mpz_init_set_ui
(
u
,
ul
);
mpz_init_set
(
t
,
p
);
mpz_sub_ui
(
t
,
t
,
1
);
mpz_tdiv_q_2exp
(
t
,
t
,
1
);
mpz_powm
(
t
,
u
,
t
,
p
);
r
=
mpz_cmp_ui
(
t
,
1
);
if
(
r
<
0
)
r
=
0
;
else
if
(
r
==
0
)
r
=
1
;
else
{
mpz_sub
(
t
,
p
,
t
);
ASSERT
(
mpz_cmp_ui
(
t
,
1
)
==
0
);
r
=
-
1
;
}
mpz_clear
(
t
);
mpz_clear
(
u
);
return
r
;
}
#endif
/* NETTLE_USE_MINI_GMP */
static
void
test_modulo
(
gmp_randstate_t
rands
,
const
struct
ecc_modulo
*
m
)
{
...
...
testsuite/testutils.c
View file @
5b677535
...
...
@@ -699,6 +699,25 @@ mpn_zero_p (mp_srcptr ap, mp_size_t n)
}
#endif
#if NETTLE_USE_MINI_GMP
void
gmp_randinit_default
(
struct
knuth_lfib_ctx
*
ctx
)
{
knuth_lfib_init
(
ctx
,
17
);
}
void
mpz_urandomb
(
mpz_t
r
,
struct
knuth_lfib_ctx
*
ctx
,
mp_bitcnt_t
bits
)
{
size_t
bytes
=
(
bits
+
7
)
/
8
;
uint8_t
*
buf
=
xalloc
(
bytes
);
knuth_lfib_random
(
ctx
,
bytes
,
buf
);
buf
[
bytes
-
1
]
&=
0xff
>>
(
8
*
bytes
-
bits
);
nettle_mpz_set_str_256_u
(
r
,
bytes
,
buf
);
free
(
buf
);
}
#endif
/* NETTLE_USE_MINI_GMP */
mp_limb_t
*
xalloc_limbs
(
mp_size_t
n
)
{
...
...
testsuite/testutils.h
View file @
5b677535
...
...
@@ -20,11 +20,14 @@
# include "ecc-internal.h"
# include "ecdsa.h"
# include "gmp-glue.h"
# if NETTLE_USE_MINI_GMP
# include "knuth-lfib.h"
# endif
/* Undo dsa-compat name mangling */
#undef dsa_generate_keypair
#define dsa_generate_keypair nettle_dsa_generate_keypair
#endif
#endif
/* WITH_HOGWEED */
#include
"nettle-meta.h"
...
...
@@ -162,6 +165,17 @@ int
mpn_zero_p
(
mp_srcptr
ap
,
mp_size_t
n
);
#endif
#if NETTLE_USE_MINI_GMP
typedef
struct
knuth_lfib_ctx
gmp_randstate_t
[
1
];
void
gmp_randinit_default
(
struct
knuth_lfib_ctx
*
ctx
);
#define gmp_randclear(state)
void
mpz_urandomb
(
mpz_t
r
,
struct
knuth_lfib_ctx
*
ctx
,
mp_bitcnt_t
bits
);
/* This is cheating */
#define mpz_rrandomb mpz_urandomb
#endif
/* NETTLE_USE_MINI_GMP */
mp_limb_t
*
xalloc_limbs
(
mp_size_t
n
);
...
...
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