Skip to content

Commit

Permalink
Merge pull request #372 from skalenetwork/new-beta
Browse files Browse the repository at this point in the history
New beta
  • Loading branch information
gannakulikova authored Jan 26, 2022
2 parents 1573a80 + cfba892 commit ec057a9
Show file tree
Hide file tree
Showing 81 changed files with 9,413 additions and 1,406 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* @olehnikolaiev @kladkogex
*.md @skalenetwork/docowners
/docs/ @skalenetwork/docowners
68 changes: 1 addition & 67 deletions BLSCrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "LevelDB.h"
#include "ServerInit.h"
#include "BLSCrypto.h"
#include "CryptoTools.h"


string *FqToString(libff::alt_bn128_Fq *_fq) {
Expand All @@ -65,71 +66,6 @@ string *FqToString(libff::alt_bn128_Fq *_fq) {
return new string(arr);
}

int char2int(char _input) {
if (_input >= '0' && _input <= '9')
return _input - '0';
if (_input >= 'A' && _input <= 'F')
return _input - 'A' + 10;
if (_input >= 'a' && _input <= 'f')
return _input - 'a' + 10;
return -1;
}

vector<char> carray2Hex(const unsigned char *d, uint64_t _len) {

CHECK_STATE(d);

vector<char> _hexArray( 2 * _len + 1);

char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

for (uint64_t j = 0; j < _len; j++) {
_hexArray[j * 2] = hexval[((d[j] >> 4) & 0xF)];
_hexArray[j * 2 + 1] = hexval[(d[j]) & 0x0F];
}

_hexArray[_len * 2] = 0;

return _hexArray;
}


bool hex2carray(const char *_hex, uint64_t *_bin_len,
uint8_t *_bin, uint64_t _max_length) {


CHECK_STATE(_hex);
CHECK_STATE(_bin);
CHECK_STATE(_bin_len)


uint64_t len = strnlen(_hex, 2 * _max_length + 1);

CHECK_STATE(len != 2 * _max_length + 1);

CHECK_STATE(len <= 2 * _max_length);


if (len == 0 && len % 2 == 1)
return false;

*_bin_len = len / 2;

for (uint64_t i = 0; i < len / 2; i++) {
int high = char2int((char) _hex[i * 2]);
int low = char2int((char) _hex[i * 2 + 1]);

if (high < 0 || low < 0) {
return false;
}

_bin[i] = (unsigned char) (high * 16 + low);
}

return true;
}

bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, size_t _n, char *_sig) {

CHECK_STATE(_encryptedKeyHex);
Expand Down Expand Up @@ -182,13 +118,11 @@ bool sign_aes(const char *_encryptedKeyHex, const char *_hashHex, size_t _t, siz

int errStatus = 0;


sgx_status_t status = SGX_SUCCESS;

status = trustedBlsSignMessage(eid, &errStatus, errMsg.data(), encryptedKey,
sz, xStrArg, yStrArg, signature);


HANDLE_TRUSTED_FUNCTION_ERROR(status, errStatus, errMsg.data());

string hint = BLSutils::ConvertToString(hash_with_hint.first.Y) + ":" + hash_with_hint.second;
Expand Down
9 changes: 1 addition & 8 deletions BLSCrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file BLSCrypto.h
@author Stan Kladko
Expand All @@ -37,13 +37,6 @@

EXTERNC bool bls_sign(const char* encryptedKeyHex, const char* hashHex, size_t t, size_t n, char* _sig);

EXTERNC int char2int(char _input);

EXTERNC std::vector<char> carray2Hex(const unsigned char *d, uint64_t _len);

EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len,
uint8_t* _bin, uint64_t _max_length );

std::string encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key);

#endif //SGXWALLET_BLSCRYPTO_H
4 changes: 1 addition & 3 deletions BLSPrivateKeyShareSGX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "sgxwallet.h"

#include "BLSCrypto.h"
#include "CryptoTools.h"
#include "ServerInit.h"
#include "SEKManager.h"
#include "BLSPrivateKeyShareSGX.h"
Expand Down Expand Up @@ -122,13 +123,10 @@ string BLSPrivateKeyShareSGX::signWithHelperSGXstr(
BOOST_THROW_EXCEPTION(runtime_error("Null yStr"));
}


vector<char> errMsg(BUF_LEN, 0);


SAFE_CHAR_BUF(xStrArg, BUF_LEN)SAFE_CHAR_BUF(yStrArg, BUF_LEN)SAFE_CHAR_BUF(signature, BUF_LEN);


strncpy(xStrArg, xStr->c_str(), BUF_LEN);
strncpy(yStrArg, yStr->c_str(), BUF_LEN);

Expand Down
17 changes: 0 additions & 17 deletions BLSSignReqMessage.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions BLSSignReqMessage.h

This file was deleted.

30 changes: 0 additions & 30 deletions BLSSignRspMessage.cpp

This file was deleted.

43 changes: 0 additions & 43 deletions BLSSignRspMessage.h

This file was deleted.

89 changes: 89 additions & 0 deletions CryptoTools.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Copyright (C) 2021-Present SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file CryptoTools.cpp
@author Oleh Nikolaiev
@date 2021
*/

#include <vector>

#include "common.h"
#include "CryptoTools.h"

using std::vector;

int char2int(char _input) {
if (_input >= '0' && _input <= '9')
return _input - '0';
if (_input >= 'A' && _input <= 'F')
return _input - 'A' + 10;
if (_input >= 'a' && _input <= 'f')
return _input - 'a' + 10;
return -1;
}

vector<char> carray2Hex(const unsigned char *d, uint64_t _len) {

CHECK_STATE(d);

vector<char> _hexArray( 2 * _len + 1);

char hexval[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

for (uint64_t j = 0; j < _len; j++) {
_hexArray[j * 2] = hexval[((d[j] >> 4) & 0xF)];
_hexArray[j * 2 + 1] = hexval[(d[j]) & 0x0F];
}

_hexArray[_len * 2] = 0;

return _hexArray;
}

bool hex2carray(const char *_hex, uint64_t *_bin_len,
uint8_t *_bin, uint64_t _max_length) {
CHECK_STATE(_hex);
CHECK_STATE(_bin);
CHECK_STATE(_bin_len)

uint64_t len = strnlen(_hex, 2 * _max_length + 1);

CHECK_STATE(len != 2 * _max_length + 1);

CHECK_STATE(len <= 2 * _max_length);

if (len % 2 == 1)
return false;

*_bin_len = len / 2;

for (uint64_t i = 0; i < len / 2; i++) {
int high = char2int((char) _hex[i * 2]);
int low = char2int((char) _hex[i * 2 + 1]);

if (high < 0 || low < 0) {
return false;
}

_bin[i] = (unsigned char) (high * 16 + low);
}

return true;
}
Loading

0 comments on commit ec057a9

Please sign in to comment.