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
4 years ago
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing DKG
parent
8ba52ba1
Changes
1
Show 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 @@
...
@@ -23,10 +23,13 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdbool.h>
#ifdef USER_SPACE
#ifdef USER_SPACE
#include <gmp.h>
#include <gmp.h>
#else
#else
#include <../tgmp-build/include/sgx_tgmp.h>
#include <../tgmp-build/include/sgx_tgmp.h>
#endif
#endif
#include "EnclaveConstants.h"
#include "EnclaveConstants.h"
...
@@ -39,13 +42,12 @@
...
@@ -39,13 +42,12 @@
#include "EnclaveCommon.h"
#include "EnclaveCommon.h"
#include <string.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_x
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
SAFE_CHAR_BUF
(
pb_keyB_y
,
65
);
mpz_t
skey
;
mpz_t
skey
;
...
@@ -86,7 +88,7 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
...
@@ -86,7 +88,7 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
SAFE_CHAR_BUF
(
arr_x
,
BUF_LEN
);
SAFE_CHAR_BUF
(
arr_x
,
BUF_LEN
);
mpz_get_str
(
arr_x
,
16
,
session_key
->
x
);
mpz_get_str
(
arr_x
,
16
,
session_key
->
x
);
int
n_zeroes
=
64
-
strlen
(
arr_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'
;
common_key
[
i
]
=
'0'
;
}
}
strncpy
(
common_key
+
n_zeroes
,
arr_x
,
strlen
(
arr_x
));
strncpy
(
common_key
+
n_zeroes
,
arr_x
,
strlen
(
arr_x
));
...
@@ -98,12 +100,31 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
...
@@ -98,12 +100,31 @@ void gen_session_key(char *skey_str, char* pb_keyB, char* common_key) {
point_clear
(
session_key
);
point_clear
(
session_key
);
}
}
void
session_key_recover
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
)
{
void
session_key_recover
(
const
char
*
skey_str
,
const
char
*
sshare
,
char
*
common_key
)
{
SAFE_CHAR_BUF
(
pb_keyB_x
,
65
);
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
);
strncpy
(
pb_keyB_x
,
sshare
+
64
,
64
);
pb_keyB_x
[
64
]
=
0
;
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
);
strncpy
(
pb_keyB_y
,
sshare
+
128
,
64
);
pb_keyB_y
[
64
]
=
0
;
pb_keyB_y
[
64
]
=
0
;
...
@@ -113,18 +134,17 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
...
@@ -113,18 +134,17 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
point
session_key
=
point_init
();
point
session_key
=
point_init
();
if
(
mpz_set_str
(
skey
,
skey_str
,
16
)
==
-
1
)
{
if
(
mpz_set_str
(
skey
,
skey_str
,
16
)
==
-
1
)
{
common_key
[
0
]
=
""
;
goto
clean
;
goto
clean
;
}
}
point_set_hex
(
pub_keyB
,
pb_keyB_x
,
pb_keyB_y
);
point_set_hex
(
pub_keyB
,
pb_keyB_x
,
pb_keyB_y
);
point_multiplication
(
session_key
,
skey
,
pub_keyB
,
curve
);
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
);
mpz_get_str
(
arr_x
,
16
,
session_key
->
x
);
int
n_zeroes
=
64
-
strlen
(
arr_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'
;
common_key
[
i
]
=
'0'
;
}
}
strncpy
(
common_key
+
n_zeroes
,
arr_x
,
strlen
(
arr_x
));
strncpy
(
common_key
+
n_zeroes
,
arr_x
,
strlen
(
arr_x
));
...
@@ -135,40 +155,55 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
...
@@ -135,40 +155,55 @@ void session_key_recover(const char *skey_str, const char* sshare, char* common_
point_clear
(
session_key
);
point_clear
(
session_key
);
}
}
void
xor_encrypt
(
char
*
key
,
char
*
message
,
char
*
cypher
)
{
void
xor_encrypt
(
char
*
key
,
char
*
message
,
char
*
cypher
)
{
uint8_t
cypher_bin
[
33
];
if
(
!
cypher
)
{
LOG_ERROR
(
"xor_encrypt: null cypher"
);
goto
clean
;
}
if
(
!
key
)
{
LOG_ERROR
(
"xor_encrypt: null key"
);
goto
clean
;
}
if
(
!
message
)
{
LOG_ERROR
(
"xor_encrypt: null message"
);
goto
clean
;
}
SAFE_CHAR_BUF
(
cypher_bin
,
33
);
SAFE_CHAR_BUF
(
key_bin
,
33
);
uint8_t
*
key_bin
=
(
uint8_t
*
)
calloc
(
33
,
1
);
uint64_t
key_length
;
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
key_bin
)){
cypher
=
NULL
;
if
(
!
hex2carray
(
key
,
&
key_length
,
key_bin
))
{
free
(
key_bin
);
goto
clean
;
return
;
}
}
uint64_t
msg_length
;
uint64_t
msg_length
;
uint8_t
msg_bin
[
33
];
uint8_t
msg_bin
[
33
];
if
(
!
hex2carray
(
message
,
&
msg_length
,
msg_bin
)){
if
(
!
hex2carray
(
message
,
&
msg_length
,
msg_bin
))
{
cypher
=
NULL
;
goto
clean
;
free
(
key_bin
);
return
;
}
}
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
cypher_bin
[
i
]
=
msg_bin
[
i
]
^
key_bin
[
i
];
cypher_bin
[
i
]
=
msg_bin
[
i
]
^
key_bin
[
i
];
}
}
carray2Hex
(
cypher_bin
,
32
,
cypher
);
carray2Hex
(
cypher_bin
,
32
,
cypher
);
free
(
key_bin
);
clean:
;
}
}
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
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
;
uint64_t
key_length
;
if
(
!
hex2carray
(
key
,
&
key_length
,
key_bin
)){
if
(
!
hex2carray
(
key
,
&
key_length
,
key_bin
))
{
message
=
NULL
;
message
=
NULL
;
free
(
key_bin
);
free
(
key_bin
);
return
;
return
;
...
@@ -176,13 +211,13 @@ void xor_decrypt(char* key, char* cypher, char* message) {
...
@@ -176,13 +211,13 @@ void xor_decrypt(char* key, char* cypher, char* message) {
uint64_t
cypher_length
;
uint64_t
cypher_length
;
uint8_t
cypher_bin
[
33
];
uint8_t
cypher_bin
[
33
];
if
(
!
hex2carray
(
cypher
,
&
cypher_length
,
cypher_bin
)){
if
(
!
hex2carray
(
cypher
,
&
cypher_length
,
cypher_bin
))
{
message
=
NULL
;
message
=
NULL
;
free
(
key_bin
);
free
(
key_bin
);
return
;
return
;
}
}
for
(
int
i
=
0
;
i
<
32
;
i
++
){
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
msg_bin
[
i
]
=
cypher_bin
[
i
]
^
key_bin
[
i
];
msg_bin
[
i
]
=
cypher_bin
[
i
]
^
key_bin
[
i
];
}
}
...
...
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