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
41acaebb
Unverified
Commit
41acaebb
authored
Feb 22, 2020
by
Chadwick Strange
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into enhancement/documentation
parents
479b2abb
5fd5d025
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1182 additions
and
1192 deletions
+1182
-1192
Dockerfile
Dockerfile
+1
-1
DockerfileSimulation
DockerfileSimulation
+1
-0
codacy.yml
codacy.yml
+4
-0
secure_enclave.c
secure_enclave/secure_enclave.c
+1024
-997
secure_enclave.i
secure_enclave/secure_enclave.i
+1
-1
signature.c
secure_enclave/signature.c
+148
-190
signature.h
secure_enclave/signature.h
+2
-2
sgxwallet.c
sgxwallet.c
+1
-1
No files found.
Dockerfile
View file @
41acaebb
...
...
@@ -20,7 +20,7 @@ COPY m4 ./m4
COPY
scripts ./scripts
COPY
secure_enclave ./secure_enclave
COPY
spdlog ./spdlog
COPY
SGXWALLET_VERSION ./
RUN
autoreconf
-vif
RUN
libtoolize
--force
...
...
DockerfileSimulation
View file @
41acaebb
...
...
@@ -19,6 +19,7 @@ COPY m4 ./m4
COPY scripts ./scripts
COPY secure_enclave ./secure_enclave
COPY spdlog ./spdlog
COPY SGXWALLET_VERSION ./
RUN autoreconf -vif
RUN libtoolize --force
...
...
codacy.yml
0 → 100644
View file @
41acaebb
---
exclude_paths
:
-
'
scripts/**'
-
'
.github/**'
secure_enclave/secure_enclave.c
View file @
41acaebb
This diff is collapsed.
Click to expand it.
secure_enclave/secure_enclave.i
View file @
41acaebb
...
...
@@ -6532,7 +6532,7 @@ void signature_copy(signature R, signature sig);
_Bool signature_cmp(signature sig1, signature sig2);
void signature_
clear
(signature sig);
void signature_
free
(signature sig);
void signature_generate_key(point public_key, mpz_t private_key, domain_parameters curve);
...
...
secure_enclave/signature.c
View file @
41acaebb
...
...
@@ -32,10 +32,9 @@
#include "numbertheory.h"
/*Initialize a signature*/
signature
signature_init
()
{
signature
signature_init
()
{
signature
sig
;
sig
=
malloc
(
sizeof
(
struct
signature_s
)
);
sig
=
calloc
(
sizeof
(
struct
signature_s
),
1
);
mpz_init
(
sig
->
r
);
mpz_init
(
sig
->
s
);
sig
->
v
=
0
;
...
...
@@ -43,8 +42,7 @@ signature signature_init()
}
/*Print signature to standart output stream*/
void
signature_print
(
signature
sig
)
{
void
signature_print
(
signature
sig
)
{
/*printf("\nSignature (r,s): \n\t(");
mpz_out_str(stdout, 10, sig->r);
printf(",\n\t");
...
...
@@ -53,79 +51,66 @@ void signature_print(signature sig)
}
/*Set signature from strings of a base from 2-62*/
void
signature_set_str
(
signature
sig
,
char
*
r
,
char
*
s
,
int
base
)
{
void
signature_set_str
(
signature
sig
,
char
*
r
,
char
*
s
,
int
base
)
{
mpz_set_str
(
sig
->
r
,
r
,
base
);
mpz_set_str
(
sig
->
s
,
s
,
base
);
}
/*Set signature from hexadecimal strings*/
void
signature_set_hex
(
signature
sig
,
char
*
r
,
char
*
s
)
{
signature_set_str
(
sig
,
r
,
s
,
16
);
void
signature_set_hex
(
signature
sig
,
char
*
r
,
char
*
s
)
{
signature_set_str
(
sig
,
r
,
s
,
16
);
}
/*Set signature from decimal unsigned long ints*/
void
signature_set_ui
(
signature
sig
,
unsigned
long
int
r
,
unsigned
long
int
s
)
{
void
signature_set_ui
(
signature
sig
,
unsigned
long
int
r
,
unsigned
long
int
s
)
{
mpz_set_ui
(
sig
->
r
,
r
);
mpz_set_ui
(
sig
->
s
,
s
);
}
/*Make R a copy of P*/
void
signature_copy
(
signature
R
,
signature
sig
)
{
void
signature_copy
(
signature
R
,
signature
sig
)
{
mpz_set
(
R
->
r
,
sig
->
r
);
mpz_set
(
R
->
s
,
sig
->
s
);
}
/*Compare two signatures return 1 if not the same, returns 0 if they are the same*/
bool
signature_cmp
(
signature
sig1
,
signature
sig2
)
{
return
!
mpz_cmp
(
sig1
->
r
,
sig2
->
r
)
&&
!
mpz_cmp
(
sig1
->
s
,
sig2
->
s
);
bool
signature_cmp
(
signature
sig1
,
signature
sig2
)
{
return
!
mpz_cmp
(
sig1
->
r
,
sig2
->
r
)
&&
!
mpz_cmp
(
sig1
->
s
,
sig2
->
s
);
}
/*Generates a public key for a private key*/
void
signature_generate_key
(
point
public_key
,
mpz_t
private_key
,
domain_parameters
curve
)
{
void
signature_extract_public_key
(
point
public_key
,
mpz_t
private_key
,
domain_parameters
curve
)
{
point_multiplication
(
public_key
,
private_key
,
curve
->
G
,
curve
);
}
/*Generate signature for a message*/
void
signature_sign
(
signature
sig
,
mpz_t
message
,
mpz_t
private_key
,
domain_parameters
curve
)
{
void
signature_sign
(
signature
sig
,
mpz_t
message
,
mpz_t
private_key
,
domain_parameters
curve
)
{
//message must not have a bit length longer than that of n
//see: Guide to Elliptic Curve Cryptography, section 4.4.1.
assert
(
mpz_sizeinbase
(
message
,
2
)
<=
mpz_sizeinbase
(
curve
->
n
,
2
));
//Initializing variables
mpz_t
k
;
mpz_init
(
k
);
mpz_t
x
;
mpz_init
(
x
);
point
Q
=
point_init
();
mpz_t
r
;
mpz_init
(
r
);
mpz_t
t1
;
mpz_init
(
t1
);
mpz_t
t2
;
mpz_init
(
t2
);
mpz_t
t3
;
mpz_init
(
t3
);
mpz_t
s
;
mpz_init
(
s
);
unsigned
char
*
rand_char
=
(
unsigned
char
*
)
malloc
(
32
);
sgx_read_rand
(
rand_char
,
32
);
//Initializing variables
mpz_t
k
,
x
,
r
,
t1
,
t2
,
t3
,
t4
,
t5
,
s
,
n_div_2
,
rem
,
neg
,
seed
;
mpz_init
(
k
);
mpz_init
(
x
);
mpz_init
(
r
);
mpz_init
(
t1
);
mpz_init
(
t2
);
mpz_init
(
t3
);
mpz_init
(
s
);
mpz_init
(
t4
);
mpz_init
(
t5
);
mpz_init
(
n_div_2
);
mpz_init
(
rem
);
mpz_init
(
neg
);
mpz_init
(
seed
);
unsigned
char
*
rand_char
=
(
unsigned
char
*
)
malloc
(
32
);
sgx_read_rand
(
rand_char
,
32
);
gmp_randstate_t
r_state
;
signature_sign_start:
//Set k
sgx_read_rand
(
rand_char
,
32
);
mpz_t
seed
;
mpz_init
(
seed
);
sgx_read_rand
(
rand_char
,
32
);
;
mpz_import
(
seed
,
32
,
1
,
sizeof
(
rand_char
[
0
]),
0
,
0
,
rand_char
);
free
(
rand_char
);
mpz_mod
(
k
,
seed
,
curve
->
p
);
mpz_clear
(
seed
);
//mpz_set_str(k, "49a0d7b786ec9cde0d0721d72804befd06571c974b191efb42ecf322ba9ddd9a", 16);
// mpz_set_str(k, "DC87789C4C1A09C97FF4DE72C0D0351F261F10A2B9009C80AEE70DDEC77201A0", 16);
...
...
@@ -137,9 +122,9 @@ void signature_sign(signature sig, mpz_t message, mpz_t private_key, domain_para
//Calculate r
mpz_mod
(
r
,
x
,
curve
->
n
);
if
(
!
mpz_sgn
(
r
))
//Start over if r=0, note haven't been tested memory might die :)
if
(
!
mpz_sgn
(
r
))
//Start over if r=0, note haven't been tested memory might die :)
goto
signature_sign_start
;
mpz_clear
(
x
);
//Calculate s
//s = k¯¹(e+d*r) mod n = (k¯¹ mod n) * ((e+d*r) mod n) mod n
...
...
@@ -147,20 +132,13 @@ void signature_sign(signature sig, mpz_t message, mpz_t private_key, domain_para
mpz_invert
(
t1
,
k
,
curve
->
n
);
mpz_mul
(
t2
,
private_key
,
r
);
//t2 = d*r
mpz_add
(
t3
,
message
,
t2
);
//t3 = e+t2
mpz_clear
(
t2
);
mpz_init
(
t2
);
mpz_mod
(
t2
,
t3
,
curve
->
n
);
//t2 = t3 mod n
mpz_clear
(
t3
);
mpz_init
(
t3
);
mpz_mul
(
t3
,
t2
,
t1
);
//t3 = t2 * t1
mpz_mod
(
s
,
t3
,
curve
->
n
);
//s = t3 mod n
mpz_mod
(
t4
,
t3
,
curve
->
n
);
//t2 = t3 mod n
mpz_mul
(
t5
,
t4
,
t1
);
//t3 = t2 * t1
mpz_mod
(
s
,
t5
,
curve
->
n
);
//s = t3 mod n
//Calculate v
mpz_t
rem
;
mpz_init
(
rem
);
mpz_mod_ui
(
rem
,
Q
->
y
,
2
);
mpz_mod_ui
(
rem
,
Q
->
y
,
2
);
mpz_t
s_mul_2
;
mpz_init
(
s_mul_2
);
mpz_mul_ui
(
s_mul_2
,
s
,
2
);
...
...
@@ -169,74 +147,54 @@ void signature_sign(signature sig, mpz_t message, mpz_t private_key, domain_para
if
(
mpz_cmp
(
s_mul_2
,
curve
->
n
)
>
0
)
{
b
=
1
;
}
sig
->
v
=
mpz_get_ui
(
rem
)
^
b
;
point_clear
(
Q
);
mpz_clear
(
rem
);
mpz_clear
(
s_mul_2
);
sig
->
v
=
mpz_get_ui
(
rem
)
^
b
;
mpz_t
n_div_2
;
mpz_init
(
n_div_2
);
mpz_cdiv_q_ui
(
n_div_2
,
curve
->
n
,
2
);
mpz_cdiv_q_ui
(
n_div_2
,
curve
->
n
,
2
);
if
(
mpz_cmp
(
s
,
n_div_2
)
>
0
)
{
mpz_t
neg
;
mpz_init
(
neg
);
mpz_sub
(
neg
,
curve
->
n
,
s
);
mpz_clear
(
s
);
mpz_init
(
s
);
mpz_set
(
s
,
neg
);
mpz_clear
(
neg
);
}
mpz_clear
(
n_div_2
);
mpz_clear
(
t1
);
mpz_clear
(
t2
);
mpz_clear
(
t3
);
//Set signature
mpz_set
(
sig
->
r
,
r
);
mpz_set
(
sig
->
s
,
s
);
//Release k,r and s
mpz_clear
(
k
);
mpz_clear
(
r
);
mpz_clear
(
s
);
clean:
free
(
rand_char
);
point_clear
(
Q
);
mpz_clear
(
k
);
mpz_clear
(
r
);
mpz_clear
(
s
);
mpz_clear
(
x
);
mpz_clear
(
rem
);
mpz_clear
(
neg
);
mpz_clear
(
t1
);
mpz_clear
(
t2
);
mpz_clear
(
t3
);
mpz_clear
(
seed
);
mpz_clear
(
n_div_2
);
mpz_clear
(
s_mul_2
);
}
/*Verify the integrity of a message using it's signature*/
bool
signature_verify
(
mpz_t
message
,
signature
sig
,
point
public_key
,
domain_parameters
curve
)
{
//verify r and s are within [1, n-1]
mpz_t
one
;
mpz_init
(
one
);
mpz_set_ui
(
one
,
1
);
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
)
{
mpz_clear
(
one
);
return
false
;
}
mpz_clear
(
one
);
bool
signature_verify
(
mpz_t
message
,
signature
sig
,
point
public_key
,
domain_parameters
curve
)
{
//Initialize variables
mpz_t
w
;
mpz_init
(
w
);
mpz_t
u1
;
mpz_init
(
u1
);
mpz_t
u2
;
mpz_init
(
u2
);
mpz_t
t
;
mpz_init
(
t
);
mpz_t
tt2
;
mpz_init
(
tt2
);
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
);
...
...
@@ -255,25 +213,25 @@ bool signature_verify(mpz_t message, signature sig, point public_key, domain_par
point_addition
(
x
,
t1
,
t2
,
curve
);
//Get the result, by comparing x value with r and verifying that x is NOT at infinity
bool
result
=
mpz_cmp
(
sig
->
r
,
x
->
x
)
==
0
&&
!
x
->
infinity
;
//release memory
result
=
mpz_cmp
(
sig
->
r
,
x
->
x
)
==
0
&&
!
x
->
infinity
;
clean:
point_clear
(
x
);
point_clear
(
t1
);
point_clear
(
t2
);
mpz_clear
(
w
);
mpz_clear
(
u1
);
mpz_clear
(
u2
);
mpz_clear
(
t
);
mpz_clear
(
one
);
mpz_clear
(
w
);
mpz_clear
(
u1
);
mpz_clear
(
u2
);
mpz_clear
(
t
);
mpz_clear
(
tt2
);
//Return result
return
result
;
}
/*Release signature*/
void
signature_clear
(
signature
sig
)
{
void
signature_free
(
signature
sig
)
{
mpz_clear
(
sig
->
r
);
mpz_clear
(
sig
->
s
);
free
(
sig
);
...
...
secure_enclave/signature.h
View file @
41acaebb
...
...
@@ -53,10 +53,10 @@ void signature_copy(signature R, signature sig);
bool
signature_cmp
(
signature
sig1
,
signature
sig2
);
/*Release signature*/
void
signature_
clear
(
signature
sig
);
void
signature_
free
(
signature
sig
);
/*Generates a public key for a private key*/
void
signature_
generate
_key
(
point
public_key
,
mpz_t
private_key
,
domain_parameters
curve
);
void
signature_
extract_public
_key
(
point
public_key
,
mpz_t
private_key
,
domain_parameters
curve
);
/*Generate signature for a message*/
void
signature_sign
(
signature
sig
,
mpz_t
message
,
mpz_t
private_key
,
domain_parameters
curve
);
...
...
sgxwallet.c
View file @
41acaebb
...
...
@@ -97,7 +97,7 @@ int main(int argc, char *argv[]) {
is_sgx_https
=
0
;
break
;
case
'a'
:
is_aes
=
0
;
is_aes
=
1
;
break
;
case
'b'
:
SEK_initializer
=
enter_SEK
;
...
...
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