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
d6943929
Unverified
Commit
d6943929
authored
Sep 24, 2019
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add generate keys to api
parent
466e8b7d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
18 deletions
+35
-18
ECDSACrypto.cpp
ECDSACrypto.cpp
+12
-4
ECDSACrypto.h
ECDSACrypto.h
+1
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+9
-5
secure_enclave.c
secure_enclave/secure_enclave.c
+6
-4
spec.json
spec.json
+5
-2
testw.cpp
testw.cpp
+2
-2
No files found.
ECDSACrypto.cpp
View file @
d6943929
...
...
@@ -3,19 +3,27 @@
//
#include "ECDSACrypto.h"
#include "BLSCrypto.h"
#include "sgxwallet.h"
#include <iostream>
char
*
gen_ecdsa_key
(){
std
::
vector
<
std
::
string
>
gen_ecdsa_key
(){
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
char
*
encr_pr_key
=
(
char
*
)
calloc
(
1024
,
1
);
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint32_t
enc_len
=
0
;
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
,
(
uint8_t
*
)
encr_pr_key
,
&
enc_len
,
pub_key_x
,
pub_key_y
);
return
encr_pr_key
;
std
::
vector
<
std
::
string
>
keys
(
2
);
char
*
hexEncrKey
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
carray2Hex
(
encr_pr_key
,
enc_len
,
hexEncrKey
);
keys
.
at
(
0
)
=
hexEncrKey
;
keys
.
at
(
1
)
=
std
::
string
(
pub_key_x
)
+
std
::
string
(
pub_key_y
);
std
::
cerr
<<
"in ECDSACrypto encr key x "
<<
keys
.
at
(
0
)
<<
std
::
endl
;
return
keys
;
}
std
::
vector
<
std
::
string
>
ecdsa_sign_hash
(
const
char
*
encryptedKey
,
const
char
*
hashHex
){
...
...
ECDSACrypto.h
View file @
d6943929
...
...
@@ -16,7 +16,7 @@
#define EXTERNC
#endif*/
char
*
gen_ecdsa_key
();
std
::
vector
<
std
::
string
>
gen_ecdsa_key
();
std
::
vector
<
std
::
string
>
ecdsa_sign_hash
(
const
char
*
encryptedKey
,
const
char
*
hashHex
);
...
...
SGXWalletServer.cpp
View file @
d6943929
...
...
@@ -154,21 +154,25 @@ Json::Value generateECDSAKeyImpl(const std::string &_keyName) {
cerr
<<
"Calling method"
<<
endl
;
char
*
encryptedKey
=
nullptr
;
std
::
vector
<
std
::
string
>
keys
;
try
{
encryptedKey
=
gen_ecdsa_key
();
if
(
encryptedKey
==
nullptr
)
{
keys
=
gen_ecdsa_key
();
if
(
keys
.
size
()
==
0
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
""
);
}
writeECDSAKey
(
_keyName
,
encryptedKey
);
writeECDSAKey
(
_keyName
,
keys
.
at
(
0
)
);
}
catch
(
RPCException
&
_e
)
{
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
}
result
[
"encryptedKey"
]
=
encryptedKey
;
result
[
"encryptedKey"
]
=
keys
.
at
(
0
);
result
[
"PublicKey"
]
=
keys
.
at
(
1
);
std
::
cerr
<<
"in SGXWalletServer encr key x "
<<
keys
.
at
(
0
)
<<
std
::
endl
;
return
result
;
}
...
...
secure_enclave/secure_enclave.c
View file @
d6943929
...
...
@@ -156,16 +156,18 @@ void generate_ecdsa_key(int *err_status, char *err_string,
signature_generate_key
(
Pkey
,
skey
,
curve
);
int
len
=
mpz_sizeinbase
(
Pkey
->
x
,
10
)
+
2
;
uint8_t
base
=
16
;
int
len
=
mpz_sizeinbase
(
Pkey
->
x
,
base
)
+
2
;
//snprintf(err_string, BUF_LEN, "len = %d\n", len);
char
arr_x
[
len
];
char
*
px
=
mpz_get_str
(
arr_x
,
10
,
Pkey
->
x
);
char
*
px
=
mpz_get_str
(
arr_x
,
base
,
Pkey
->
x
);
//snprintf(err_string, BUF_LEN, "arr=%p px=%p\n", arr_x, px);
strncpy
(
pub_key_x
,
arr_x
,
1024
);
char
arr_y
[
mpz_sizeinbase
(
Pkey
->
y
,
10
)
+
2
];
char
*
py
=
mpz_get_str
(
arr_y
,
10
,
Pkey
->
y
);
char
arr_y
[
mpz_sizeinbase
(
Pkey
->
y
,
base
)
+
2
];
char
*
py
=
mpz_get_str
(
arr_y
,
base
,
Pkey
->
y
);
strncpy
(
pub_key_y
,
arr_y
,
1024
);
char
skey_str
[
mpz_sizeinbase
(
skey
,
10
)
+
2
];
...
...
spec.json
View file @
d6943929
...
...
@@ -51,7 +51,8 @@
"returns"
:
{
"status"
:
0
,
"errorMessage"
:
"12345"
,
"encryptedKey"
:
"12345"
"encryptedKey"
:
"12345"
,
"PublicKey"
:
"12345"
}
},
...
...
@@ -66,7 +67,9 @@
"returns"
:
{
"status"
:
0
,
"errorMessage"
:
"12345"
,
"signature"
:
"12345"
"signature_v"
:
"12345"
,
"signature_r"
:
"12345"
,
"signature_s"
:
"12345"
}
}
]
\ No newline at end of file
testw.cpp
View file @
d6943929
...
...
@@ -414,7 +414,7 @@ using namespace std;
TEST_CASE
(
"API test"
,
"[api_test]"
)
{
cerr
<<
"API test started"
<<
endl
;
//
init_all();
init_all
();
//HttpServer httpserver(1025);
//SGXWalletServer s(httpserver,
...
...
@@ -427,7 +427,7 @@ TEST_CASE("API test", "[api_test]") {
cerr
<<
"Client inited"
<<
endl
;
try
{
cout
<<
c
.
generateECDSAKey
(
"test_key"
)
<<
endl
;
cout
<<
c
.
generateECDSAKey
(
"test_key
1
"
)
<<
endl
;
}
catch
(
JsonRpcException
&
e
)
{
cerr
<<
e
.
what
()
<<
endl
;
}
...
...
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