Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
cry
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
12
Issues
12
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
crylib
cry
Commits
6ca8e6a8
Commit
6ca8e6a8
authored
Apr 16, 2017
by
davxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ECP multiplication using windowed algorithm
parent
bef830ee
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
1 deletion
+102
-1
CHANGELOG.md
CHANGELOG.md
+2
-0
README.md
README.md
+6
-0
config.mk
config.mk
+4
-1
src/ecp/ecp_mul.c
src/ecp/ecp_mul.c
+90
-0
No files found.
CHANGELOG.md
View file @
6ca8e6a8
...
...
@@ -26,6 +26,8 @@ Given a version number MAJOR.MINOR.PATCH
-
ECP core arithmetic (add,dbl,mul)
-
Load NIST-P256 EC parameters
-
DSA end ECDSA digital signature
-
ECP multiplication with windowed algorithm
[0.0.5] - 2016-10-02
--------------------
...
...
README.md
View file @
6ca8e6a8
...
...
@@ -42,6 +42,12 @@ Public key algorithms
-
Diffie-Hellman
### Digital signature
-
RSA (PKCS#1 v1.5)
-
DSA
-
ECDSA
Elliptic Curve
--------------
...
...
config.mk
View file @
6ca8e6a8
...
...
@@ -26,7 +26,7 @@ CRY_DEBUG=y
# Use one octet digit in place of sizeof(unsigned long) octets.
# Warning: NO ADVANTAGES, just for testing purposes
CRY_MPI_SMALL_DIGIT
=
y
#
CRY_MPI_SMALL_DIGIT=y
# Options: aes|weak|posix|win
CRY_PRNG
=
aes
...
...
@@ -44,3 +44,6 @@ CRY_MPI_MUL_COMBA=y
# Karatsuba multiplier enabled, see the mpi_mul.c to set the CUTOFF
CRY_MPI_MUL_KARATSUBA
=
y
# Elliptic curve point multiplication with windowed algorithm (faster)
CRY_ECP_MUL_WIN
=
y
src/ecp/ecp_mul.c
View file @
6ca8e6a8
...
...
@@ -19,6 +19,94 @@
#include "cry/ecp.h"
#include "mpi/mpi_pvt.h"
/* CRY_MPI_DIGIT_BITS */
#include <stdlib.h>
/* malloc() */
#define CHK(exp) do { if ((res = (exp)) != 0) goto e; } while (0)
#ifdef CRY_ECP_MUL_WIN
#define WINSIZ 4
#define WINPTS (1 << WINSIZ)
#define WINMSK (WINPTS-1)
int
cry_ecp_mul
(
cry_ecp
*
pr
,
const
cry_ecp
*
p1
,
const
cry_mpi
*
k
,
const
cry_mpi
*
a
,
const
cry_mpi
*
p
)
{
int
res
,
i
,
j
,
w
,
paf
=
1
;
struct
cry_ecp
r
,
*
win
=
NULL
;
cry_mpi_digit
msk
;
if
((
res
=
cry_ecp_init
(
&
r
))
!=
0
)
return
res
;
/*
* BEGIN window generation
*/
win
=
malloc
(
sizeof
(
cry_ecp
)
*
WINPTS
);
if
(
win
==
NULL
)
goto
e0
;
for
(
i
=
0
;
i
<
WINPTS
;
i
++
)
{
if
((
res
=
cry_ecp_init
(
&
win
[
i
]))
!=
0
)
{
// 0P
while
(
i
--
>
0
)
/* rollback */
cry_ecp_clear
(
&
win
[
i
]);
goto
e1
;
}
}
CHK
(
cry_ecp_copy
(
&
win
[
1
],
p1
));
// 1P
CHK
(
cry_ecp_dbl
(
&
win
[
2
],
&
win
[
1
],
a
,
p
));
// 2P
CHK
(
cry_ecp_add
(
&
win
[
3
],
&
win
[
2
],
&
win
[
1
],
p
));
// 3P
CHK
(
cry_ecp_dbl
(
&
win
[
4
],
&
win
[
2
],
a
,
p
));
// 4P
CHK
(
cry_ecp_add
(
&
win
[
5
],
&
win
[
4
],
&
win
[
1
],
p
));
// 5P
CHK
(
cry_ecp_add
(
&
win
[
6
],
&
win
[
5
],
&
win
[
1
],
p
));
// 6P
CHK
(
cry_ecp_add
(
&
win
[
7
],
&
win
[
6
],
&
win
[
1
],
p
));
// 7P
CHK
(
cry_ecp_dbl
(
&
win
[
8
],
&
win
[
4
],
a
,
p
));
// 8P
CHK
(
cry_ecp_add
(
&
win
[
9
],
&
win
[
8
],
&
win
[
1
],
p
));
// 9P
CHK
(
cry_ecp_add
(
&
win
[
10
],
&
win
[
9
],
&
win
[
1
],
p
));
// 10P
CHK
(
cry_ecp_add
(
&
win
[
11
],
&
win
[
10
],
&
win
[
1
],
p
));
// 11P
CHK
(
cry_ecp_add
(
&
win
[
12
],
&
win
[
11
],
&
win
[
1
],
p
));
// 12P
CHK
(
cry_ecp_add
(
&
win
[
13
],
&
win
[
12
],
&
win
[
1
],
p
));
// 13P
CHK
(
cry_ecp_add
(
&
win
[
14
],
&
win
[
13
],
&
win
[
1
],
p
));
// 14P
CHK
(
cry_ecp_add
(
&
win
[
15
],
&
win
[
14
],
&
win
[
1
],
p
));
// 15P
/*
* END window generation
*/
i
=
k
->
used
;
while
(
i
>
0
)
{
i
--
;
w
=
(
CRY_MPI_DIGIT_BITS
-
WINSIZ
);
msk
=
((
cry_mpi_digit
)
WINMSK
)
<<
w
;
j
=
CRY_MPI_DIGIT_BITS
;
while
(
j
>
0
)
{
if
(
!
paf
)
{
for
(
w
=
0
;
w
<
WINSIZ
;
w
++
)
CHK
(
cry_ecp_dbl
(
&
r
,
&
r
,
a
,
p
));
}
j
-=
WINSIZ
;
w
=
(
k
->
data
[
i
]
&
msk
)
>>
j
;
if
(
w
>
0
)
{
if
(
!
paf
)
{
CHK
(
cry_ecp_add
(
&
r
,
&
r
,
&
win
[
w
],
p
));
}
else
{
paf
=
0
;
/* First addition */
CHK
(
cry_ecp_copy
(
&
r
,
&
win
[
w
]));
}
}
msk
>>=
WINSIZ
;
}
}
/* Success */
cry_ecp_swap
(
pr
,
&
r
);
e:
for
(
i
=
0
;
i
<
WINPTS
;
i
++
)
cry_ecp_clear
(
&
win
[
i
]);
e1:
free
(
win
);
e0:
cry_ecp_clear
(
&
r
);
return
res
;
}
#else
/* !CRY_ECP_MUL_WIN */
int
cry_ecp_mul
(
cry_ecp
*
pr
,
const
cry_ecp
*
p1
,
const
cry_mpi
*
k
,
const
cry_mpi
*
a
,
const
cry_mpi
*
p
)
...
...
@@ -58,3 +146,5 @@ e: cry_mpi_clear_list(&dp.x, &dp.y, &r.x, &r.y, 0);
return
res
;
}
#endif
/* CRY_ECP_MUL_WIN */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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