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
7b67bfe4
Unverified
Commit
7b67bfe4
authored
4 years ago
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3067-cleanup-sgx
parent
41244ce8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
17 deletions
+18
-17
DHDkg.c
secure_enclave/DHDkg.c
+18
-17
No files found.
secure_enclave/DHDkg.c
View file @
7b67bfe4
...
...
@@ -29,6 +29,7 @@
#include <../tgmp-build/include/sgx_tgmp.h>
#endif
#include "EnclaveConstants.h"
#include "DomainParameters.h"
#include "Curves.h"
#include "Point.h"
...
...
@@ -39,28 +40,33 @@
#include <string.h>
void
gen_session_key
(
char
*
skey_str
,
char
*
pb_keyB
,
char
*
common_key
)
{
char
*
pb_keyB_x
=
(
char
*
)
calloc
(
65
,
1
);
LOG_INFO
(
__FUNCTION__
);
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
mpz_t
skey
;
mpz_init
(
skey
);
point
pub_keyB
=
point_init
();
point
session_key
=
point_init
();
strncpy
(
pb_keyB_x
,
pb_keyB
,
64
);
pb_keyB_x
[
64
]
=
0
;
char
*
pb_keyB_y
=
(
char
*
)
calloc
(
65
,
1
);
strncpy
(
pb_keyB_y
,
pb_keyB
+
64
,
64
);
pb_keyB_y
[
64
]
=
0
;
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters_load_curve
(
curve
,
secp256k1
);
mpz_t
skey
;
mpz_init
(
skey
);
mpz_set_str
(
skey
,
skey_str
,
16
);
point
pub_keyB
=
point_init
();
point_set_hex
(
pub_keyB
,
pb_keyB_x
,
pb_keyB_y
);
point
session_key
=
point_init
();
point_multiplication
(
session_key
,
skey
,
pub_keyB
,
curve
);
char
arr_x
[
mpz_sizeinbase
(
session_key
->
x
,
16
)
+
2
]
;
SAFE_CHAR_BUF
(
arr_x
,
BUF_LEN
)
;
mpz_get_str
(
arr_x
,
16
,
session_key
->
x
);
int
n_zeroes
=
64
-
strlen
(
arr_x
);
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
){
...
...
@@ -69,12 +75,10 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
strncpy
(
common_key
+
n_zeroes
,
arr_x
,
strlen
(
arr_x
));
common_key
[
64
]
=
0
;
clean:
mpz_clear
(
skey
);
point_clear
(
pub_keyB
);
point_clear
(
session_key
);
domain_parameters_clear
(
curve
);
free
(
pb_keyB_x
);
free
(
pb_keyB_y
);
}
void
session_key_recover
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
)
{
...
...
@@ -86,8 +90,7 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
strncpy
(
pb_keyB_y
,
sshare
+
128
,
64
);
pb_keyB_y
[
64
]
=
0
;
domain_parameters
curve
=
domain_parameters_init
();
domain_parameters_load_curve
(
curve
,
secp256k1
);
mpz_t
skey
;
mpz_init
(
skey
);
...
...
@@ -95,7 +98,6 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
common_key
=
NULL
;
mpz_clear
(
skey
);
domain_parameters_clear
(
curve
);
free
(
pb_keyB_x
);
free
(
pb_keyB_y
);
...
...
@@ -119,7 +121,6 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
mpz_clear
(
skey
);
point_clear
(
pub_keyB
);
point_clear
(
session_key
);
domain_parameters_clear
(
curve
);
free
(
pb_keyB_x
);
free
(
pb_keyB_y
);
}
...
...
This diff is collapsed.
Click to expand it.
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