Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
8c109b8b
Unverified
Commit
8c109b8b
authored
May 14, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed docs
parent
d6fc4674
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
58 deletions
+58
-58
Signature.c
secure_enclave/Signature.c
+0
-57
Signature.h
secure_enclave/Signature.h
+58
-1
No files found.
secure_enclave/Signature.c
View file @
8c109b8b
...
...
@@ -171,64 +171,7 @@ void signature_sign(signature sig, mpz_t message, mpz_t private_key, domain_para
}
/*Verify the integrity of a message using it's signature*/
bool
signature_verify
(
mpz_t
message
,
signature
sig
,
point
public_key
,
domain_parameters
curve
)
{
//Initialize variables
mpz_t
one
,
w
,
u1
,
u2
,
t
,
tt2
;
mpz_init
(
one
);
mpz_init
(
w
);
mpz_init
(
u1
);
mpz_init
(
u2
);
mpz_init
(
t
);
mpz_init
(
tt2
);
mpz_set_ui
(
one
,
1
);
point
x
=
point_init
();
point
t1
=
point_init
();
point
t2
=
point_init
();
bool
result
=
false
;
if
(
mpz_cmp
(
sig
->
r
,
one
)
<
0
&&
mpz_cmp
(
curve
->
n
,
sig
->
r
)
<=
0
&&
mpz_cmp
(
sig
->
s
,
one
)
<
0
&&
mpz_cmp
(
curve
->
n
,
sig
->
s
)
<=
0
)
{
goto
clean
;
}
//w = s¯¹ mod n
number_theory_inverse
(
w
,
sig
->
s
,
curve
->
n
);
//u1 = message * w mod n
mpz_mod
(
tt2
,
message
,
curve
->
n
);
mpz_mul
(
t
,
tt2
,
w
);
mpz_mod
(
u1
,
t
,
curve
->
n
);
//u2 = r*w mod n
mpz_mul
(
t
,
sig
->
r
,
w
);
mpz_mod
(
u2
,
t
,
curve
->
n
);
//x = u1*G+u2*Q
point_multiplication
(
t1
,
u1
,
curve
->
G
,
curve
);
point_multiplication
(
t2
,
u2
,
public_key
,
curve
);
point_addition
(
x
,
t1
,
t2
,
curve
);
//Get the result, by comparing x value with r and verifying that x is NOT at infinity
result
=
mpz_cmp
(
sig
->
r
,
x
->
x
)
==
0
&&
!
x
->
infinity
;
clean:
point_clear
(
x
);
point_clear
(
t1
);
point_clear
(
t2
);
mpz_clear
(
one
);
mpz_clear
(
w
);
mpz_clear
(
u1
);
mpz_clear
(
u2
);
mpz_clear
(
t
);
mpz_clear
(
tt2
);
return
result
;
}
/*Release signature*/
void
signature_free
(
signature
sig
)
{
...
...
secure_enclave/Signature.h
View file @
8c109b8b
...
...
@@ -65,6 +65,63 @@ void signature_extract_public_key(point public_key, mpz_t private_key, domain_pa
void
signature_sign
(
signature
sig
,
mpz_t
message
,
mpz_t
private_key
,
domain_parameters
curve
);
/*Verify the integrity of a message using it's signature*/
bool
signature_verify
(
mpz_t
message
,
signature
sig
,
point
public_key
,
domain_parameters
curve
);
static
inline
bool
signature_verify
(
mpz_t
message
,
signature
sig
,
point
public_key
,
domain_parameters
curve
)
{
//Initialize variables
mpz_t
one
,
w
,
u1
,
u2
,
t
,
tt2
;
mpz_init
(
one
);
mpz_init
(
w
);
mpz_init
(
u1
);
mpz_init
(
u2
);
mpz_init
(
t
);
mpz_init
(
tt2
);
mpz_set_ui
(
one
,
1
);
point
x
=
point_init
();
point
t1
=
point_init
();
point
t2
=
point_init
();
bool
result
=
false
;
if
(
mpz_cmp
(
sig
->
r
,
one
)
<
0
&&
mpz_cmp
(
curve
->
n
,
sig
->
r
)
<=
0
&&
mpz_cmp
(
sig
->
s
,
one
)
<
0
&&
mpz_cmp
(
curve
->
n
,
sig
->
s
)
<=
0
)
{
goto
clean
;
}
//w = s¯¹ mod n
number_theory_inverse
(
w
,
sig
->
s
,
curve
->
n
);
//u1 = message * w mod n
mpz_mod
(
tt2
,
message
,
curve
->
n
);
mpz_mul
(
t
,
tt2
,
w
);
mpz_mod
(
u1
,
t
,
curve
->
n
);
//u2 = r*w mod n
mpz_mul
(
t
,
sig
->
r
,
w
);
mpz_mod
(
u2
,
t
,
curve
->
n
);
//x = u1*G+u2*Q
point_multiplication
(
t1
,
u1
,
curve
->
G
,
curve
);
point_multiplication
(
t2
,
u2
,
public_key
,
curve
);
point_addition
(
x
,
t1
,
t2
,
curve
);
//Get the result, by comparing x value with r and verifying that x is NOT at infinity
result
=
mpz_cmp
(
sig
->
r
,
x
->
x
)
==
0
&&
!
x
->
infinity
;
clean:
point_clear
(
x
);
point_clear
(
t1
);
point_clear
(
t2
);
mpz_clear
(
one
);
mpz_clear
(
w
);
mpz_clear
(
u1
);
mpz_clear
(
u2
);
mpz_clear
(
t
);
mpz_clear
(
tt2
);
return
result
;
}
#endif
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