Skip to content

Commit

Permalink
SKALE-4472 format code
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Aug 18, 2021
1 parent 00c75c6 commit 0ea6740
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 1 addition & 2 deletions threshold_encryption/threshold_encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ std::pair< Ciphertext, std::vector< uint8_t > > TE::encryptWithAES(
return {{U, V, W}, encrypted_message};
}

std::string TE::encryptMessage(
const std::string& message, const std::string& common_public_str ) {
std::string TE::encryptMessage( const std::string& message, const std::string& common_public_str ) {
libff::alt_bn128_G2 common_public = ThresholdUtils::stringToG2( common_public_str );
auto ciphertext_with_aes = encryptWithAES( message, common_public );
return aesCiphertextToString( ciphertext_with_aes.first, ciphertext_with_aes.second );
Expand Down
20 changes: 12 additions & 8 deletions tools/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,32 @@ std::string ThresholdUtils::convertHexToDec( const std::string& hex_str ) {

libff::alt_bn128_G2 ThresholdUtils::stringToG2( const std::string& str ) {
if ( str.size() != 256 ) {
throw IncorrectInput("Wrong string size to convert to G2");
throw IncorrectInput( "Wrong string size to convert to G2" );
}

libff::alt_bn128_G2 ret;

ret.Z = libff::alt_bn128_Fq2::one();

ret.X.c0 = libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 0, 64 ) ).c_str() );
ret.X.c1 = libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 64, 64 ) ).c_str() );
ret.Y.c0 = libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 128, 64 ) ).c_str() );
ret.Y.c1 = libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 192, std::string::npos ) ).c_str() );
ret.X.c0 =
libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 0, 64 ) ).c_str() );
ret.X.c1 =
libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 64, 64 ) ).c_str() );
ret.Y.c0 =
libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 128, 64 ) ).c_str() );
ret.Y.c1 = libff::alt_bn128_Fq(
ThresholdUtils::convertHexToDec( str.substr( 192, std::string::npos ) ).c_str() );

return ret;
}

libff::alt_bn128_G1 ThresholdUtils::stringToG1( const std::string& str ) {
if ( str.size() != 128 ) {
throw IncorrectInput("Wrong string size to convert to G1");
throw IncorrectInput( "Wrong string size to convert to G1" );
}

libff::alt_bn128_G1 ret;

ret.Z = libff::alt_bn128_Fq::one();
ret.X = libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 0, 64 ) ).c_str() );
ret.Y = libff::alt_bn128_Fq( ThresholdUtils::convertHexToDec( str.substr( 64, 64 ) ).c_str() );
Expand Down

0 comments on commit 0ea6740

Please sign in to comment.