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
0e2db9b4
Unverified
Commit
0e2db9b4
authored
Sep 10, 2019
by
kladkogex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes
parent
d9d10219
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
59 deletions
+62
-59
BLSCrypto.cpp
BLSCrypto.cpp
+58
-0
BLSCrypto.h
BLSCrypto.h
+2
-0
testw.cpp
testw.cpp
+2
-59
No files found.
BLSCrypto.cpp
View file @
0e2db9b4
...
...
@@ -110,3 +110,61 @@ bool sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, size_t
}
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
char
*
keyArray
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
uint8_t
*
encryptedKey
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
strncpy
((
char
*
)
keyArray
,
(
char
*
)
_key
,
BUF_LEN
);
*
errStatus
=
-
1
;
unsigned
int
encryptedLen
=
0
;
status
=
encrypt_key
(
eid
,
errStatus
,
errMsg
,
keyArray
,
encryptedKey
,
&
encryptedLen
);
if
(
status
!=
SGX_SUCCESS
)
{
*
errStatus
=
-
1
;
return
nullptr
;
}
if
(
*
errStatus
!=
0
)
{
return
nullptr
;
}
char
*
result
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
carray2Hex
(
encryptedKey
,
encryptedLen
,
result
);
return
result
;
}
char
*
decryptBLSKeyShareFromHex
(
int
*
errStatus
,
char
*
errMsg
,
const
char
*
_encryptedKey
)
{
*
errStatus
=
-
1
;
uint64_t
decodedLen
=
0
;
uint8_t
decoded
[
BUF_LEN
];
if
(
!
(
hex2carray
(
_encryptedKey
,
&
decodedLen
,
decoded
)))
{
return
nullptr
;
}
char
*
plaintextKey
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
status
=
decrypt_key
(
eid
,
errStatus
,
errMsg
,
decoded
,
decodedLen
,
plaintextKey
);
if
(
status
!=
SGX_SUCCESS
)
{
return
nullptr
;
}
if
(
*
errStatus
!=
0
)
{
return
nullptr
;
}
return
plaintextKey
;
}
\ No newline at end of file
BLSCrypto.h
View file @
0e2db9b4
...
...
@@ -29,6 +29,8 @@ EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len,
EXTERNC
char
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
);
EXTERNC
char
*
decryptBLSKeyShareFromHex
(
int
*
errStatus
,
char
*
errMsg
,
const
char
*
_encryptedKey
);
#endif //SGXWALLET_BLSCRYPTO_H
testw.cpp
View file @
0e2db9b4
...
...
@@ -65,63 +65,6 @@ sgx_enclave_id_t eid;
sgx_status_t
status
;
int
updated
;
char
*
encryptKey2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
char
*
keyArray
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
uint8_t
*
encryptedKey
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
strncpy
((
char
*
)
keyArray
,
(
char
*
)
_key
,
BUF_LEN
);
*
errStatus
=
-
1
;
unsigned
int
encryptedLen
=
0
;
status
=
encrypt_key
(
eid
,
errStatus
,
errMsg
,
keyArray
,
encryptedKey
,
&
encryptedLen
);
if
(
status
!=
SGX_SUCCESS
)
{
*
errStatus
=
-
1
;
return
nullptr
;
}
if
(
*
errStatus
!=
0
)
{
return
nullptr
;
}
char
*
result
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
carray2Hex
(
encryptedKey
,
encryptedLen
,
result
);
return
result
;
}
char
*
decryptKeyFromHex
(
int
*
errStatus
,
char
*
errMsg
,
const
char
*
_encryptedKey
)
{
*
errStatus
=
-
1
;
uint64_t
decodedLen
=
0
;
uint8_t
decoded
[
BUF_LEN
];
if
(
!
(
hex2carray
(
_encryptedKey
,
&
decodedLen
,
decoded
)))
{
return
nullptr
;
}
char
*
plaintextKey
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
status
=
decrypt_key
(
eid
,
errStatus
,
errMsg
,
decoded
,
decodedLen
,
plaintextKey
);
if
(
status
!=
SGX_SUCCESS
)
{
return
nullptr
;
}
if
(
*
errStatus
!=
0
)
{
return
nullptr
;
}
return
plaintextKey
;
}
#define TEST_KEY "4160780231445160889237664391382223604184857153814275770598791864649971919844"
...
...
@@ -139,7 +82,7 @@ char* encryptTestKey() {
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
char
*
encryptedKeyHex
=
encrypt
Key
2Hex
(
&
errStatus
,
errMsg
,
key
);
char
*
encryptedKeyHex
=
encrypt
BLSKeyShare
2Hex
(
&
errStatus
,
errMsg
,
key
);
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
REQUIRE
(
errStatus
==
0
);
...
...
@@ -176,7 +119,7 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
char
*
encryptedKey
=
encryptTestKey
();
REQUIRE
(
encryptedKey
!=
nullptr
);
char
*
plaintextKey
=
decrypt
Key
FromHex
(
&
errStatus
,
errMsg
,
encryptedKey
);
char
*
plaintextKey
=
decrypt
BLSKeyShare
FromHex
(
&
errStatus
,
errMsg
,
encryptedKey
);
REQUIRE
(
errStatus
==
0
);
...
...
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