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
c26f01d5
Unverified
Commit
c26f01d5
authored
Aug 14, 2020
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing DKG
parent
8ba52ba1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
44 deletions
+79
-44
DHDkg.c
secure_enclave/DHDkg.c
+79
-44
No files found.
secure_enclave/DHDkg.c
View file @
c26f01d5
...
...
@@ -23,10 +23,13 @@
#include <stdlib.h>
#include <stdbool.h>
#ifdef USER_SPACE
#include <gmp.h>
#else
#include <../tgmp-build/include/sgx_tgmp.h>
#endif
#include "EnclaveConstants.h"
...
...
@@ -39,13 +42,12 @@
#include "EnclaveCommon.h"
#include <string.h>
void
gen_session_key
(
char
*
skey_str
,
char
*
pb_keyB
,
char
*
common_key
)
{
void
gen_session_key
(
char
*
skey_str
,
char
*
pb_keyB
,
char
*
common_key
)
{
LOG_INFO
(
__FUNCTION__
);
LOG_INFO
(
__FUNCTION__
);
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
mpz_t
skey
;
...
...
@@ -86,8 +88,8 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
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
++
)
{
common_key
[
i
]
=
'0'
;
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
)
{
common_key
[
i
]
=
'0'
;
}
strncpy
(
common_key
+
n_zeroes
,
arr_x
,
strlen
(
arr_x
));
common_key
[
64
]
=
0
;
...
...
@@ -98,12 +100,31 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
point_clear
(
session_key
);
}
void
session_key_recover
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
)
{
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
void
session_key_recover
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
)
{
if
(
!
common_key
)
{
LOG_ERROR
(
"session_key_recover: Null common_key"
);
goto
clean
;
}
common_key
[
0
]
=
0
;
if
(
!
skey_str
)
{
LOG_ERROR
(
"session_key_recover: Null skey_str"
);
goto
clean
;
}
if
(
!
sshare
)
{
LOG_ERROR
(
"session_key_recover: Null sshare"
);
goto
clean
;
}
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
strncpy
(
pb_keyB_x
,
sshare
+
64
,
64
);
pb_keyB_x
[
64
]
=
0
;
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
strncpy
(
pb_keyB_y
,
sshare
+
128
,
64
);
pb_keyB_y
[
64
]
=
0
;
...
...
@@ -113,18 +134,17 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
point
session_key
=
point_init
();
if
(
mpz_set_str
(
skey
,
skey_str
,
16
)
==
-
1
)
{
common_key
[
0
]
=
""
;
goto
clean
;
}
point_set_hex
(
pub_keyB
,
pb_keyB_x
,
pb_keyB_y
);
point_multiplication
(
session_key
,
skey
,
pub_keyB
,
curve
);
SAFE_CHAR_BUF
(
arr_x
,
BUF_LEN
);
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
++
)
{
for
(
int
i
=
0
;
i
<
n_zeroes
;
i
++
)
{
common_key
[
i
]
=
'0'
;
}
strncpy
(
common_key
+
n_zeroes
,
arr_x
,
strlen
(
arr_x
));
...
...
@@ -135,54 +155,69 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
point_clear
(
session_key
);
}
void
xor_encrypt
(
char
*
key
,
char
*
message
,
char
*
cypher
)
{
uint8_t
cypher_bin
[
33
];
void
xor_encrypt
(
char
*
key
,
char
*
message
,
char
*
cypher
)
{
uint8_t
*
key_bin
=
(
uint8_t
*
)
calloc
(
33
,
1
);
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
key_bin
)){
cypher
=
NULL
;
free
(
key_bin
);
return
;
}
if
(
!
cypher
)
{
LOG_ERROR
(
"xor_encrypt: null cypher"
);
goto
clean
;
}
uint64_t
msg_length
;
uint8_t
msg_bin
[
33
];
if
(
!
hex2carray
(
message
,
&
msg_length
,
msg_bin
)){
cypher
=
NULL
;
free
(
key_bin
);
return
;
}
if
(
!
key
)
{
LOG_ERROR
(
"xor_encrypt: null key"
);
goto
clean
;
}
for
(
int
i
=
0
;
i
<
32
;
i
++
){
cypher_bin
[
i
]
=
msg_bin
[
i
]
^
key_bin
[
i
];
}
if
(
!
message
)
{
LOG_ERROR
(
"xor_encrypt: null message"
);
goto
clean
;
}
SAFE_CHAR_BUF
(
cypher_bin
,
33
);
SAFE_CHAR_BUF
(
key_bin
,
33
);
carray2Hex
(
cypher_bin
,
32
,
cypher
);
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
key_bin
))
{
goto
clean
;
}
uint64_t
msg_length
;
uint8_t
msg_bin
[
33
];
if
(
!
hex2carray
(
message
,
&
msg_length
,
msg_bin
))
{
goto
clean
;
}
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
cypher_bin
[
i
]
=
msg_bin
[
i
]
^
key_bin
[
i
];
}
carray2Hex
(
cypher_bin
,
32
,
cypher
);
clean:
;
free
(
key_bin
);
}
void
xor_decrypt
(
char
*
key
,
char
*
cypher
,
char
*
message
)
{
void
xor_decrypt
(
char
*
key
,
char
*
cypher
,
char
*
message
)
{
uint8_t
msg_bin
[
33
];
uint8_t
*
key_bin
=
(
uint8_t
*
)
calloc
(
33
,
1
);
uint8_t
*
key_bin
=
(
uint8_t
*
)
calloc
(
33
,
1
);
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
key_bin
)){
message
=
NULL
;
free
(
key_bin
);
return
;
if
(
!
hex2carray
(
key
,
&
key_length
,
key_bin
))
{
message
=
NULL
;
free
(
key_bin
);
return
;
}
uint64_t
cypher_length
;
uint8_t
cypher_bin
[
33
];
if
(
!
hex2carray
(
cypher
,
&
cypher_length
,
cypher_bin
)){
message
=
NULL
;
free
(
key_bin
);
return
;
if
(
!
hex2carray
(
cypher
,
&
cypher_length
,
cypher_bin
))
{
message
=
NULL
;
free
(
key_bin
);
return
;
}
for
(
int
i
=
0
;
i
<
32
;
i
++
){
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
msg_bin
[
i
]
=
cypher_bin
[
i
]
^
key_bin
[
i
];
}
...
...
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