From 6717143d74afc904afec604b8b9e2b24e17d49e7 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Wed, 12 Jun 2024 17:58:12 +0800 Subject: [PATCH] add support of sm3 hash (#29) --- CMakeLists.txt | 2 + Changelog.md | 2 +- cmake/EthDependencies.cmake | 18 +-- cmake/EthOptions.cmake | 7 + cmake/ProjectBoost.cmake | 119 ++++++++++++++ libsolutil/CMakeLists.txt | 7 + libsolutil/GmHash.cpp | 38 +++++ libsolutil/sm3/sm3.cpp | 281 ++++++++++++++++++++++++++++++++++ libsolutil/sm3/sm3.h | 55 +++++++ solc/CommandLineInterface.cpp | 10 +- 10 files changed, 527 insertions(+), 12 deletions(-) create mode 100644 cmake/ProjectBoost.cmake create mode 100644 libsolutil/GmHash.cpp create mode 100644 libsolutil/sm3/sm3.cpp create mode 100644 libsolutil/sm3/sm3.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 91c1056ec3a4..9e76578f5cc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,8 @@ if (NOT USE_SYSTEM_LIBRARIES) include(fmtlib) include(nlohmann-json) include(range-v3) + include_directories(SYSTEM ${JSONCPP_INCLUDE_DIR}) + include(ProjectBoost) endif() find_package(Threads) diff --git a/Changelog.md b/Changelog.md index 0837a7170e4b..487d0e675b56 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1777,7 +1777,7 @@ Compiler Features: * Static Analyzer: Do not warn about unused variables or state mutability for functions with an empty body. * Type Checker: Add an additional reason to be displayed when type conversion fails. * Yul: Support object access via ``datasize``, ``dataoffset`` and ``datacopy`` in standalone assembly mode. - + * Feature: Add guomi. Bugfixes: * Standard JSON Interface: Report specific error message for json input errors instead of internal compiler error. diff --git a/cmake/EthDependencies.cmake b/cmake/EthDependencies.cmake index 16f30a640d27..5c5f34b94ed5 100644 --- a/cmake/EthDependencies.cmake +++ b/cmake/EthDependencies.cmake @@ -29,16 +29,16 @@ if (WIN32) option(Boost_USE_STATIC_RUNTIME "Link Boost against static C++ runtime libraries" ON) endif() -set(BOOST_COMPONENTS "filesystem;unit_test_framework;program_options;system") +# set(BOOST_COMPONENTS "filesystem;unit_test_framework;program_options;system") -if (WIN32) - # Boost 1.77 fixes a bug that causes crashes on Windows for some relative paths in --allow-paths. - # See https://github.com/boostorg/filesystem/issues/201 - find_package(Boost 1.77.0 QUIET REQUIRED COMPONENTS ${BOOST_COMPONENTS}) -else() - # Boost 1.65 is the first to also provide boost::get for rvalue-references (#5787). - find_package(Boost 1.65.0 QUIET REQUIRED COMPONENTS ${BOOST_COMPONENTS}) -endif() +# if (WIN32) +# # Boost 1.77 fixes a bug that causes crashes on Windows for some relative paths in --allow-paths. +# # See https://github.com/boostorg/filesystem/issues/201 +# find_package(Boost 1.77.0 QUIET REQUIRED COMPONENTS ${BOOST_COMPONENTS}) +# else() +# # Boost 1.65 is the first to also provide boost::get for rvalue-references (#5787). +# find_package(Boost 1.65.0 QUIET REQUIRED COMPONENTS ${BOOST_COMPONENTS}) +# endif() # If cmake is older than boost and boost is older than 1.70, # find_package does not define imported targets, so we have to diff --git a/cmake/EthOptions.cmake b/cmake/EthOptions.cmake index cd6fe8133732..3e7bb160f620 100644 --- a/cmake/EthOptions.cmake +++ b/cmake/EthOptions.cmake @@ -8,6 +8,12 @@ macro(configure_project) eth_default_option(COVERAGE OFF) eth_default_option(OSSFUZZ OFF) + # guomi + eth_default_option(BUILD_GM OFF) + if (BUILD_GM) + add_definitions(-DFISCO_GM) + endif() + # components eth_default_option(TESTS ON) eth_default_option(TOOLS ON) @@ -33,6 +39,7 @@ macro(print_config NAME) message("--------------------------------------------------------------- features") message("-- COVERAGE Coverage support ${COVERAGE}") message("------------------------------------------------------------- components") + message("-- BUILD_GM BUILD GM ${BUILD_GM}") if (SUPPORT_TESTS) message("-- TESTS Build tests ${TESTS}") endif() diff --git a/cmake/ProjectBoost.cmake b/cmake/ProjectBoost.cmake new file mode 100644 index 000000000000..722b330410ee --- /dev/null +++ b/cmake/ProjectBoost.cmake @@ -0,0 +1,119 @@ +include(ExternalProject) +include(GNUInstallDirs) + +set(BOOST_CXXFLAGS "") +if (WIN32) + set(BOOST_BOOTSTRAP_COMMAND bootstrap.bat) + set(BOOST_BUILD_TOOL b2.exe) + set(BOOST_LIBRARY_SUFFIX -vc141-mt-x64-1_68.lib) +elseif(EMSCRIPTEN) + set(BOOST_BOOTSTRAP_COMMAND ./bootstrap.sh) + set(BOOST_BUILD_TOOL ./b2 toolset=emscripten) + set(BOOST_LIBRARY_SUFFIX .bc) +else() + set(BOOST_BOOTSTRAP_COMMAND ./bootstrap.sh) + set(BOOST_BUILD_TOOL ./b2) + set(BOOST_LIBRARY_SUFFIX .a) + if (${BUILD_SHARED_LIBS}) + set(BOOST_CXXFLAGS "cxxflags=-fPIC") + endif() +endif() + +#set(BOOST_CXXFLAGS "cxxflags=-Wa,-march=generic64") +if(APPLE) + set(BOOST_CXXFLAGS "cxxflags=-fPIC -std=c++14") +else() + set(BOOST_CXXFLAGS "cxxflags=-fPIC") +endif() + +ExternalProject_Add(boost + PREFIX ${CMAKE_SOURCE_DIR}/deps + DOWNLOAD_NO_PROGRESS 1 + URL https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/deps/boost_1_76_0.tar.bz2 + https://downloads.sourceforge.net/project/boost/boost/1.76.0/source/boost_1_76_0.tar.bz2 + https://nchc.dl.sourceforge.net/project/boost/boost/1.76.0/boost_1_76_0.tar.bz2 + URL_HASH SHA256=f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41 + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND ${BOOST_BOOTSTRAP_COMMAND} + LOG_CONFIGURE 1 + BUILD_COMMAND ${BOOST_BUILD_TOOL} stage + ${BOOST_CXXFLAGS} + threading=multi + link=static + variant=release + address-model=64 + --disable-icu + --with-thread + --with-date_time + --with-system + --with-regex + --with-chrono + --with-filesystem + --with-program_options + --with-random + --with-test + LOG_BUILD 1 + INSTALL_COMMAND "" +) + +ExternalProject_Get_Property(boost SOURCE_DIR) +set(BOOST_INCLUDE_DIR ${SOURCE_DIR}) +set(BOOST_LIB_DIR ${SOURCE_DIR}/stage/lib) + +add_library(Boost::system STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::system PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_system${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::system PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +add_dependencies(Boost::system boost) + +add_library(Boost::Chrono STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Chrono PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_chrono${BOOST_LIBRARY_SUFFIX}) +add_dependencies(Boost::Chrono boost) + +add_library(Boost::DataTime STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::DataTime PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_date_time${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::DataTime PROPERTY INTERFACE_LINK_LIBRARIES Boost::system) +add_dependencies(Boost::DataTime boost) + +add_library(Boost::Regex STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Regex PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_regex${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Regex PROPERTY INTERFACE_LINK_LIBRARIES Boost::system) +add_dependencies(Boost::Regex boost) + +add_library(Boost::filesystem STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::filesystem PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_filesystem${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::filesystem PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +set_property(TARGET Boost::filesystem PROPERTY INTERFACE_LINK_LIBRARIES Boost::system) +add_dependencies(Boost::filesystem boost) + +add_library(Boost::Random STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Random PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_random${BOOST_LIBRARY_SUFFIX}) +add_dependencies(Boost::Random boost) + +add_library(Boost::unit_test_framework STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::unit_test_framework PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_unit_test_framework${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::unit_test_framework PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +add_dependencies(Boost::unit_test_framework boost) + +add_library(Boost::Thread STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Thread PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_thread${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Thread PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +set_property(TARGET Boost::Thread PROPERTY INTERFACE_LINK_LIBRARIES Boost::Chrono Boost::DataTime Boost::Regex) +add_dependencies(Boost::Thread boost) + +add_library(Boost::program_options STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::program_options PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_program_options${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::program_options PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +add_dependencies(Boost::program_options boost) + +add_library(Boost::Log STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Log PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_log${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Log PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +set_property(TARGET Boost::Log PROPERTY INTERFACE_LINK_LIBRARIES Boost::Filesystem Boost::Thread) +add_dependencies(Boost::Log boost) + +add_library(Boost::Serialization STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Serialization PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_serialization${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Serialization PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +add_dependencies(Boost::Serialization boost) + +unset(SOURCE_DIR) \ No newline at end of file diff --git a/libsolutil/CMakeLists.txt b/libsolutil/CMakeLists.txt index 0fdb23b0445f..7fb5ab1a9830 100644 --- a/libsolutil/CMakeLists.txt +++ b/libsolutil/CMakeLists.txt @@ -42,6 +42,13 @@ set(sources Whiskers.h ) +if(BUILD_GM) + aux_source_directory(./sm3 sources) + include_directories(./sm3) + list(REMOVE_ITEM sources Keccak256.cpp) + list(APPEND sources GmHash.cpp) +endif() + add_library(solutil ${sources}) target_link_libraries(solutil PUBLIC Boost::boost Boost::filesystem Boost::system range-v3 fmt::fmt-header-only nlohmann-json) target_include_directories(solutil PUBLIC "${PROJECT_SOURCE_DIR}") diff --git a/libsolutil/GmHash.cpp b/libsolutil/GmHash.cpp new file mode 100644 index 000000000000..19376905a6d6 --- /dev/null +++ b/libsolutil/GmHash.cpp @@ -0,0 +1,38 @@ +/* + This file is part of FISCO-BCOS. + FISCO-BCOS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + FISCO-BCOS 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 General Public License for more details. + You should have received a copy of the GNU General Public License + along with FISCO-BCOS. If not, see . +*/ +/** @file GmHash.cpp + * @author asherli + * @date 2018 + */ + +#include "Keccak256.h" + +#include "sm3/sm3.h" +#include +#include +#include +#include + +using namespace std; + +namespace solidity::util +{ +h256 keccak256(bytesConstRef _input) +{ + h256 ret; + SM3((unsigned char*) _input.data(), (int) _input.size(), (unsigned char*) ret.data()); + return ret; +} + +} // namespace dev diff --git a/libsolutil/sm3/sm3.cpp b/libsolutil/sm3/sm3.cpp new file mode 100644 index 000000000000..f9c5259e0348 --- /dev/null +++ b/libsolutil/sm3/sm3.cpp @@ -0,0 +1,281 @@ +/* + This file is part of fisco-solc. + fisco-solc is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + fisco-solc 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 General Public License for more details. + You should have received a copy of the GNU General Public License + along with fisco-solc. If not, see . +*/ +/** + * @file: sm3.cpp + * @author: websterchen + * + * @date: 2018 + */ +#include +#include +#include +#include "sm3.h" + +/* +* 32-bit integer manipulation macros (big endian) +*/ +#ifndef GET_ULONG_BE +#define GET_ULONG_BE(n,b,i) \ +{ \ + (n) = ( (unsigned int) (b)[(i) ] << 24 ) \ + | ( (unsigned int) (b)[(i) + 1] << 16 ) \ + | ( (unsigned int) (b)[(i) + 2] << 8 ) \ + | ( (unsigned int) (b)[(i) + 3] ); \ +} +#endif + +#ifndef PUT_ULONG_BE +#define PUT_ULONG_BE(n,b,i) \ +{ \ + (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ + (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ + (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ + (b)[(i) + 3] = (unsigned char) ( (n) ); \ +} +#endif + +/* +* SM3 context setup +*/ +void sm3_starts(sm3_context *ctx) +{ + ctx->total[0] = 0; + ctx->total[1] = 0; + + ctx->state[0] = 0x7380166F; + ctx->state[1] = 0x4914B2B9; + ctx->state[2] = 0x172442D7; + ctx->state[3] = 0xDA8A0600; + ctx->state[4] = 0xA96F30BC; + ctx->state[5] = 0x163138AA; + ctx->state[6] = 0xE38DEE4D; + ctx->state[7] = 0xB0FB0E4E; + +} + +static void sm3_process(sm3_context *ctx, unsigned char data[64]) +{ + unsigned int SS1, SS2, TT1, TT2, W[68], W1[64]; + unsigned int A, B, C, D, E, F, G, H; + unsigned int T[64]; + unsigned int Temp1, Temp2, Temp3, Temp4, Temp5; + int j; + + // for(j=0; j < 68; j++) + // W[j] = 0; + // for(j=0; j < 64; j++) + // W1[j] = 0; + + for (j = 0; j < 16; j++) + T[j] = 0x79CC4519; + for (j = 16; j < 64; j++) + T[j] = 0x7A879D8A; + + GET_ULONG_BE(W[0], data, 0); + GET_ULONG_BE(W[1], data, 4); + GET_ULONG_BE(W[2], data, 8); + GET_ULONG_BE(W[3], data, 12); + GET_ULONG_BE(W[4], data, 16); + GET_ULONG_BE(W[5], data, 20); + GET_ULONG_BE(W[6], data, 24); + GET_ULONG_BE(W[7], data, 28); + GET_ULONG_BE(W[8], data, 32); + GET_ULONG_BE(W[9], data, 36); + GET_ULONG_BE(W[10], data, 40); + GET_ULONG_BE(W[11], data, 44); + GET_ULONG_BE(W[12], data, 48); + GET_ULONG_BE(W[13], data, 52); + GET_ULONG_BE(W[14], data, 56); + GET_ULONG_BE(W[15], data, 60); + + +#define FF0(x,y,z) ( (x) ^ (y) ^ (z)) +#define FF1(x,y,z) (((x) & (y)) | ( (x) & (z)) | ( (y) & (z))) + +#define GG0(x,y,z) ( (x) ^ (y) ^ (z)) +#define GG1(x,y,z) (((x) & (y)) | ( (~(x)) & (z)) ) + + +#define SHL(x,n) (((x) & 0xFFFFFFFF) << n%32) +#define ROTL(x,n) (SHL((x),n) | ((x) >> (32 - n%32))) + +#define P0(x) ((x) ^ ROTL((x),9) ^ ROTL((x),17)) +#define P1(x) ((x) ^ ROTL((x),15) ^ ROTL((x),23)) + + for (j = 16; j < 68; j++) + { + //W[j] = P1( W[j-16] ^ W[j-9] ^ ROTL(W[j-3],15)) ^ ROTL(W[j - 13],7 ) ^ W[j-6]; + //Why thd release's result is different with the debug's ? + //Below is okay. Interesting, Perhaps VC6 has a bug of Optimizaiton. + + Temp1 = W[j - 16] ^ W[j - 9]; + Temp2 = ROTL(W[j - 3], 15); + Temp3 = Temp1 ^ Temp2; + Temp4 = P1(Temp3); + Temp5 = ROTL(W[j - 13], 7) ^ W[j - 6]; + W[j] = Temp4 ^ Temp5; + } + + + for (j = 0; j < 64; j++) + { + W1[j] = W[j] ^ W[j + 4]; + } + + + A = ctx->state[0]; + B = ctx->state[1]; + C = ctx->state[2]; + D = ctx->state[3]; + E = ctx->state[4]; + F = ctx->state[5]; + G = ctx->state[6]; + H = ctx->state[7]; + + for (j = 0; j < 16; j++) + { + SS1 = ROTL((ROTL(A, 12) + E + ROTL(T[j], j)), 7); + SS2 = SS1 ^ ROTL(A, 12); + TT1 = FF0(A, B, C) + D + SS2 + W1[j]; + TT2 = GG0(E, F, G) + H + SS1 + W[j]; + D = C; + C = ROTL(B, 9); + B = A; + A = TT1; + H = G; + G = ROTL(F, 19); + F = E; + E = P0(TT2); + } + + for (j = 16; j < 64; j++) + { + SS1 = ROTL((ROTL(A, 12) + E + ROTL(T[j], j)), 7); + SS2 = SS1 ^ ROTL(A, 12); + TT1 = FF1(A, B, C) + D + SS2 + W1[j]; + TT2 = GG1(E, F, G) + H + SS1 + W[j]; + D = C; + C = ROTL(B, 9); + B = A; + A = TT1; + H = G; + G = ROTL(F, 19); + F = E; + E = P0(TT2); + } + + ctx->state[0] ^= A; + ctx->state[1] ^= B; + ctx->state[2] ^= C; + ctx->state[3] ^= D; + ctx->state[4] ^= E; + ctx->state[5] ^= F; + ctx->state[6] ^= G; + ctx->state[7] ^= H; +} + +/* +* SM3 process buffer +*/ +void sm3_update(sm3_context *ctx, unsigned char *input, int ilen) +{ + int fill; + unsigned int left; + + if (ilen <= 0) + return; + + left = ctx->total[0] & 0x3F; + fill = (int) (64 - left); + + ctx->total[0] += (unsigned int) ilen; + ctx->total[0] &= 0xFFFFFFFF; + + if (ctx->total[0] < (unsigned int)ilen) + ctx->total[1]++; + + if (left && ilen >= fill) + { + memcpy((void *)(ctx->buffer + left), + (void *)input, (size_t) fill); + sm3_process(ctx, ctx->buffer); + input += fill; + ilen -= fill; + left = 0; + } + + while (ilen >= 64) + { + sm3_process(ctx, input); + input += 64; + ilen -= 64; + } + + if (ilen > 0) + { + memcpy((void *)(ctx->buffer + left), + (void *)input, (size_t) ilen); + } +} + +static const unsigned char sm3_padding[64] = +{ + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* +* SM3 final digest +*/ +void sm3_finish(sm3_context *ctx, unsigned char output[32]) +{ + unsigned int last, padn; + unsigned int high, low; + unsigned char msglen[8]; + + high = (ctx->total[0] >> 29) + | (ctx->total[1] << 3); + low = (ctx->total[0] << 3); + + PUT_ULONG_BE(high, msglen, 0); + PUT_ULONG_BE(low, msglen, 4); + + last = ctx->total[0] & 0x3F; + padn = (last < 56) ? (56 - last) : (120 - last); + + sm3_update(ctx, (unsigned char *)sm3_padding, (int) padn); + sm3_update(ctx, msglen, 8); + + PUT_ULONG_BE(ctx->state[0], output, 0); + PUT_ULONG_BE(ctx->state[1], output, 4); + PUT_ULONG_BE(ctx->state[2], output, 8); + PUT_ULONG_BE(ctx->state[3], output, 12); + PUT_ULONG_BE(ctx->state[4], output, 16); + PUT_ULONG_BE(ctx->state[5], output, 20); + PUT_ULONG_BE(ctx->state[6], output, 24); + PUT_ULONG_BE(ctx->state[7], output, 28); +} + + +void SM3(unsigned char *input, int ilen, + unsigned char output[32]) +{ + sm3_context ctx; + + sm3_starts(&ctx); + sm3_update(&ctx, input, ilen); + sm3_finish(&ctx, output); +} diff --git a/libsolutil/sm3/sm3.h b/libsolutil/sm3/sm3.h new file mode 100644 index 000000000000..95185915d8cf --- /dev/null +++ b/libsolutil/sm3/sm3.h @@ -0,0 +1,55 @@ +/* + This file is part of fisco-solc. + fisco-solc is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + fisco-solc 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 General Public License for more details. + You should have received a copy of the GNU General Public License + along with fisco-solc. If not, see . +*/ +/** + * @file: sm3.h + * @author: websterchen + * + * @date: 2018 + */ +#ifndef SM3_H +#define SM3_H + + +/** +* \brief SM3 context structure +*/ +typedef struct +{ + unsigned int total[2]; /*!< number of bytes processed */ + unsigned int state[8]; /*!< intermediate digest state */ + unsigned char buffer[64]; /*!< data block being processed */ + + unsigned char ipad[64]; /*!< HMAC: inner padding */ + unsigned char opad[64]; /*!< HMAC: outer padding */ + +} +sm3_context; + +#ifdef __cplusplus +extern "C" { +#endif + + void sm3_starts(sm3_context *ctx); + + void sm3_update(sm3_context *ctx, unsigned char *input, int ilen); + + void sm3_finish(sm3_context *ctx, unsigned char output[32]); + + void SM3(unsigned char *input, int ilen, + unsigned char output[32]); +#ifdef __cplusplus +} +#endif + +#endif /* sm3.h */ diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 514f84c209df..e842583bc9af 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -778,8 +778,14 @@ void CommandLineInterface::processInput() void CommandLineInterface::printVersion() { - sout() << "solc, the solidity compiler commandline interface" << std::endl; - sout() << "Version: " << solidity::frontend::VersionString << std::endl; + sout() << "solc, the solidity compiler commandline interface" << std::endl + << +#if FISCO_GM + "Gm version: " << +#else + "Version: " << +#endif + solidity::frontend::VersionString << std::endl; } void CommandLineInterface::printLicense()