Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nettle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmitry Baryshkov
nettle
Commits
02c617a9
Commit
02c617a9
authored
10 years ago
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
Document and test that ecc_modp_inv produces 0 for input a == 0 (mod p).
parent
752861f7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ChangeLog
+8
-0
8 additions, 0 deletions
ChangeLog
sec-modinv.c
+1
-0
1 addition, 0 deletions
sec-modinv.c
testsuite/ecc-modinv-test.c
+41
-0
41 additions, 0 deletions
testsuite/ecc-modinv-test.c
with
50 additions
and
0 deletions
ChangeLog
+
8
−
0
View file @
02c617a9
2014-08-23 Niels Möller <nisse@lysator.liu.se>
* sec-modinv.c (sec_modinv): Document that for a == 0 (mod m), we
should produce the "inverse" 0.
* testsuite/ecc-modinv-test.c (test_main): Check that ecc_modp_inv
produces 0 if a == 0 or a == p.
2014-08-22 Niels Möller <nisse@lysator.liu.se>
* x86_64/ecc-25519-modp.asm: New file. Assembly implementation,
...
...
This diff is collapsed.
Click to expand it.
sec-modinv.c
+
1
−
0
View file @
02c617a9
...
...
@@ -71,6 +71,7 @@ cnd_swap (int cnd, mp_limb_t *ap, mp_limb_t *bp, mp_size_t n)
}
/* Compute a^{-1} mod m, with running time depending only on the size.
Returns zero if a == 0 (mod m), to be consistent with a^{phi(m)-1}.
Also needs (m+1)/2, and m must be odd. */
void
sec_modinv
(
mp_limb_t
*
vp
,
mp_limb_t
*
ap
,
mp_size_t
n
,
...
...
This diff is collapsed.
Click to expand it.
testsuite/ecc-modinv-test.c
+
41
−
0
View file @
02c617a9
...
...
@@ -37,6 +37,17 @@ ref_modinv (mp_limb_t *rp, const mp_limb_t *ap, const mp_limb_t *mp, mp_size_t m
#define MAX_ECC_SIZE (1 + 521 / GMP_NUMB_BITS)
#define COUNT 500
static
int
mpn_zero_p
(
mp_srcptr
ap
,
mp_size_t
n
)
{
while
(
--
n
>=
0
)
{
if
(
ap
[
n
]
!=
0
)
return
0
;
}
return
1
;
}
void
test_main
(
void
)
{
...
...
@@ -55,6 +66,36 @@ test_main (void)
{
const
struct
ecc_curve
*
ecc
=
ecc_curves
[
i
];
unsigned
j
;
/* Check behaviour for zero input */
mpn_zero
(
a
,
ecc
->
size
);
memset
(
ai
,
17
,
ecc
->
size
*
sizeof
(
*
ai
));
ecc_modp_inv
(
ecc
,
ai
,
a
,
scratch
);
if
(
!
mpn_zero_p
(
ai
,
ecc
->
size
))
{
fprintf
(
stderr
,
"ecc_modp_inv failed for zero input (bit size %u):
\n
"
,
ecc
->
bit_size
);
gmp_fprintf
(
stderr
,
"p = %Nx
\n
"
"t = %Nx (bad)
\n
"
,
ecc
->
p
,
ecc
->
size
,
ai
,
ecc
->
size
);
abort
();
}
/* Check behaviour for a = p */
mpn_copyi
(
a
,
ecc
->
p
,
ecc
->
size
);
memset
(
ai
,
17
,
ecc
->
size
*
sizeof
(
*
ai
));
ecc_modp_inv
(
ecc
,
ai
,
a
,
scratch
);
if
(
!
mpn_zero_p
(
ai
,
ecc
->
size
))
{
fprintf
(
stderr
,
"ecc_modp_inv failed for a = p input (bit size %u):
\n
"
,
ecc
->
bit_size
);
gmp_fprintf
(
stderr
,
"p = %Nx
\n
"
"t = %Nx (bad)
\n
"
,
ecc
->
p
,
ecc
->
size
,
ai
,
ecc
->
size
);
abort
();
}
for
(
j
=
0
;
j
<
COUNT
;
j
++
)
{
if
(
j
&
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment