diff --git a/fuzz/core/crypto/hash256_fuzz.cpp b/fuzz/core/crypto/hash256_fuzz.cpp index 07e4632b6e..2f9462b0f0 100644 --- a/fuzz/core/crypto/hash256_fuzz.cpp +++ b/fuzz/core/crypto/hash256_fuzz.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { std::string s((const char*)data, size); diff --git a/fuzz/core/crypto/hash512_fuzz.cpp b/fuzz/core/crypto/hash512_fuzz.cpp index 23763673f3..9d8ce81c0a 100644 --- a/fuzz/core/crypto/hash512_fuzz.cpp +++ b/fuzz/core/crypto/hash512_fuzz.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { std::string s((const char*)data, size); diff --git a/iroha-cli/interactive/impl/interactive_query_cli.cpp b/iroha-cli/interactive/impl/interactive_query_cli.cpp index 688409bbb8..6c091558f7 100644 --- a/iroha-cli/interactive/impl/interactive_query_cli.cpp +++ b/iroha-cli/interactive/impl/interactive_query_cli.cpp @@ -22,8 +22,8 @@ #include "byteutils.hpp" #include "client.hpp" -#include "crypto/crypto.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "crypto/keys_manager_impl.hpp" #include "datetime/time.hpp" #include "grpc_response_handler.hpp" diff --git a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp index 62c3bf1063..54fa5ef8f4 100644 --- a/iroha-cli/interactive/impl/interactive_transaction_cli.cpp +++ b/iroha-cli/interactive/impl/interactive_transaction_cli.cpp @@ -19,7 +19,7 @@ #include #include "client.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "grpc_response_handler.hpp" #include "model/commands/append_role.hpp" #include "model/commands/create_role.hpp" diff --git a/irohad/consensus/yac/impl/yac_crypto_provider_impl.cpp b/irohad/consensus/yac/impl/yac_crypto_provider_impl.cpp index fc56940415..77401f3399 100644 --- a/irohad/consensus/yac/impl/yac_crypto_provider_impl.cpp +++ b/irohad/consensus/yac/impl/yac_crypto_provider_impl.cpp @@ -17,8 +17,8 @@ #include "consensus/yac/impl/yac_crypto_provider_impl.hpp" #include "consensus/yac/transport/yac_pb_converters.hpp" -#include "crypto/crypto.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" namespace iroha { namespace consensus { diff --git a/irohad/main/application.hpp b/irohad/main/application.hpp index 4644b6b143..a3ca7d5215 100644 --- a/irohad/main/application.hpp +++ b/irohad/main/application.hpp @@ -19,7 +19,7 @@ #define IROHA_APPLICATION_HPP #include "ametsuchi/impl/storage_impl.hpp" -#include "crypto/crypto.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" #include "logger/logger.hpp" #include "main/impl/block_loader_init.hpp" #include "main/impl/consensus_init.hpp" diff --git a/irohad/model/converters/impl/json_query_factory.cpp b/irohad/model/converters/impl/json_query_factory.cpp index d8392eb4a7..3935b65ef2 100644 --- a/irohad/model/converters/impl/json_query_factory.cpp +++ b/irohad/model/converters/impl/json_query_factory.cpp @@ -16,7 +16,7 @@ */ #include "model/converters/json_query_factory.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/queries/get_account.hpp" #include "model/queries/get_account_assets.hpp" diff --git a/irohad/model/converters/impl/json_transaction_factory.cpp b/irohad/model/converters/impl/json_transaction_factory.cpp index 2e62772868..199274c8b6 100644 --- a/irohad/model/converters/impl/json_transaction_factory.cpp +++ b/irohad/model/converters/impl/json_transaction_factory.cpp @@ -18,7 +18,7 @@ #include "model/converters/json_transaction_factory.hpp" #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/converters/json_common.hpp" using namespace rapidjson; diff --git a/irohad/model/converters/impl/pb_block_factory.cpp b/irohad/model/converters/impl/pb_block_factory.cpp index f8fb620bb5..af18ae6c3a 100644 --- a/irohad/model/converters/impl/pb_block_factory.cpp +++ b/irohad/model/converters/impl/pb_block_factory.cpp @@ -19,7 +19,7 @@ #include "model/converters/pb_common.hpp" #include "model/converters/pb_transaction_factory.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" namespace iroha { namespace model { diff --git a/irohad/model/converters/impl/pb_query_factory.cpp b/irohad/model/converters/impl/pb_query_factory.cpp index 58a7d29363..f7317a1b6e 100644 --- a/irohad/model/converters/impl/pb_query_factory.cpp +++ b/irohad/model/converters/impl/pb_query_factory.cpp @@ -17,7 +17,7 @@ #include "model/converters/pb_query_factory.hpp" #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/common.hpp" #include "model/queries/get_account.hpp" #include "model/queries/get_account_assets.hpp" diff --git a/irohad/model/converters/impl/pb_transaction_factory.cpp b/irohad/model/converters/impl/pb_transaction_factory.cpp index 0bc4256908..e75b6f5828 100644 --- a/irohad/model/converters/impl/pb_transaction_factory.cpp +++ b/irohad/model/converters/impl/pb_transaction_factory.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include +#include #include "model/converters/pb_transaction_factory.hpp" #include "model/commands/add_asset_quantity.hpp" #include "model/converters/pb_command_factory.hpp" diff --git a/irohad/model/converters/pb_common.hpp b/irohad/model/converters/pb_common.hpp index 2bde152839..2e0159f7db 100644 --- a/irohad/model/converters/pb_common.hpp +++ b/irohad/model/converters/pb_common.hpp @@ -21,8 +21,8 @@ #include "amount/amount.hpp" #include "commands.pb.h" #include "common/types.hpp" -#include "crypto/crypto.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/signature.hpp" namespace iroha { diff --git a/irohad/model/generators/impl/block_generator.cpp b/irohad/model/generators/impl/block_generator.cpp index c5990d0072..00b3170c9f 100644 --- a/irohad/model/generators/impl/block_generator.cpp +++ b/irohad/model/generators/impl/block_generator.cpp @@ -18,7 +18,7 @@ #include "model/generators/block_generator.hpp" #include #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" namespace iroha { namespace model { diff --git a/irohad/model/generators/impl/query_generator.cpp b/irohad/model/generators/impl/query_generator.cpp index 4442fb5826..8508bff079 100644 --- a/irohad/model/generators/impl/query_generator.cpp +++ b/irohad/model/generators/impl/query_generator.cpp @@ -17,7 +17,7 @@ #include #include "model/generators/query_generator.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" namespace iroha { namespace model { diff --git a/irohad/model/generators/impl/transaction_generator.cpp b/irohad/model/generators/impl/transaction_generator.cpp index b31d5209c0..4bb63887b6 100644 --- a/irohad/model/generators/impl/transaction_generator.cpp +++ b/irohad/model/generators/impl/transaction_generator.cpp @@ -17,7 +17,7 @@ #include "model/generators/transaction_generator.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "crypto/keys_manager_impl.hpp" #include "datetime/time.hpp" diff --git a/irohad/model/impl/query_execution.cpp b/irohad/model/impl/query_execution.cpp index ea613a03ba..fb955602c5 100644 --- a/irohad/model/impl/query_execution.cpp +++ b/irohad/model/impl/query_execution.cpp @@ -15,8 +15,8 @@ * limitations under the License. */ +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/query_execution.hpp" -#include "crypto/hash.hpp" #include "model/execution/common_executor.hpp" #include "model/permissions.hpp" #include "model/queries/responses/account_assets_response.hpp" diff --git a/irohad/model/model_crypto_provider_impl.cpp b/irohad/model/model_crypto_provider_impl.cpp index 74bda26824..486e861c2f 100644 --- a/irohad/model/model_crypto_provider_impl.cpp +++ b/irohad/model/model_crypto_provider_impl.cpp @@ -16,8 +16,8 @@ */ #include "model_crypto_provider_impl.hpp" -#include "crypto/crypto.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/queries/get_account.hpp" #include "model/queries/get_account_assets.hpp" diff --git a/irohad/simulator/impl/simulator.cpp b/irohad/simulator/impl/simulator.cpp index 845b7cb30a..70ce71b6f7 100644 --- a/irohad/simulator/impl/simulator.cpp +++ b/irohad/simulator/impl/simulator.cpp @@ -16,7 +16,7 @@ */ #include "simulator/impl/simulator.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" namespace iroha { namespace simulator { diff --git a/irohad/torii/impl/command_service.cpp b/irohad/torii/impl/command_service.cpp index 62d4ddf3aa..c87878dd65 100644 --- a/irohad/torii/impl/command_service.cpp +++ b/irohad/torii/impl/command_service.cpp @@ -14,9 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -#include "torii/command_service.hpp" #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" +#include "torii/command_service.hpp" +#include "common/types.hpp" namespace torii { diff --git a/irohad/torii/impl/query_service.cpp b/irohad/torii/impl/query_service.cpp index 185c3b7386..914f9a0363 100644 --- a/irohad/torii/impl/query_service.cpp +++ b/irohad/torii/impl/query_service.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "torii/query_service.hpp" namespace torii { diff --git a/irohad/torii/processor/impl/query_processor_impl.cpp b/irohad/torii/processor/impl/query_processor_impl.cpp index 95c667846e..5e80cbb90b 100644 --- a/irohad/torii/processor/impl/query_processor_impl.cpp +++ b/irohad/torii/processor/impl/query_processor_impl.cpp @@ -15,7 +15,7 @@ * limitations under the License. */ -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "torii/processor/query_processor_impl.hpp" #include "model/queries/responses/error_response.hpp" diff --git a/irohad/torii/processor/impl/transaction_processor_impl.cpp b/irohad/torii/processor/impl/transaction_processor_impl.cpp index 65f78a3138..323d5c97dc 100644 --- a/irohad/torii/processor/impl/transaction_processor_impl.cpp +++ b/irohad/torii/processor/impl/transaction_processor_impl.cpp @@ -19,7 +19,7 @@ #include #include #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/transaction_response.hpp" namespace iroha { diff --git a/irohad/validation/CMakeLists.txt b/irohad/validation/CMakeLists.txt index 3ecdfab415..ac963bb481 100644 --- a/irohad/validation/CMakeLists.txt +++ b/irohad/validation/CMakeLists.txt @@ -20,7 +20,7 @@ add_library(stateful_validator ) target_link_libraries(stateful_validator optional - ed25519 + ed25519_sha3 rxcpp model logger @@ -38,7 +38,7 @@ add_library(chain_validator impl/chain_validator_impl.cpp) target_link_libraries(chain_validator optional - ed25519 + ed25519_sha3 rxcpp model logger diff --git a/libs/crypto/CMakeLists.txt b/libs/crypto/CMakeLists.txt index a58cfe3b23..7bfae34f88 100644 --- a/libs/crypto/CMakeLists.txt +++ b/libs/crypto/CMakeLists.txt @@ -15,25 +15,6 @@ # limitations under the License. # -add_subdirectory(ed25519) - -add_library(hash - hash.cpp - ) - -target_link_libraries(hash - ed25519 - common - pb_model_converters - ) - -add_library(cryptography - ed25519_impl.cpp - ) -target_link_libraries(cryptography - ed25519 - hash - ) add_library(keys_manager keys_manager_impl.cpp diff --git a/libs/crypto/ed25519/CMakeLists.txt b/libs/crypto/ed25519/CMakeLists.txt deleted file mode 100644 index 7bee43217a..0000000000 --- a/libs/crypto/ed25519/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_library(ed25519 - add_scalar.c - fe.c - ge.c - key_exchange.c - keypair.c - sc.c - seed.c - sha3.c - sha512.c - sign.c - verify.c - ) -target_include_directories(ed25519 INTERFACE .) diff --git a/libs/crypto/keys_manager.hpp b/libs/crypto/keys_manager.hpp index 4bd0d3b662..ac7a61540f 100644 --- a/libs/crypto/keys_manager.hpp +++ b/libs/crypto/keys_manager.hpp @@ -19,7 +19,7 @@ #define IROHA_CLI_KEYS_MANAGER_HPP #include -#include "crypto/crypto.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" namespace iroha { diff --git a/libs/crypto/keys_manager_impl.cpp b/libs/crypto/keys_manager_impl.cpp index e297041004..129a4fd273 100644 --- a/libs/crypto/keys_manager_impl.cpp +++ b/libs/crypto/keys_manager_impl.cpp @@ -16,8 +16,8 @@ */ #include "keys_manager_impl.hpp" -#include "crypto/crypto.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "logger/logger.hpp" #include diff --git a/libs/random/random.hpp b/libs/random/random.hpp index 780fa24238..db4a2c1568 100644 --- a/libs/random/random.hpp +++ b/libs/random/random.hpp @@ -18,7 +18,7 @@ limitations under the License. #define __RANDOM_HPP_ #include -#include "../crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" namespace random_service { diff --git a/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp b/shared_model/backend/protobuf/commands/proto_add_asset_quantity.hpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/shared_model/backend/protobuf/common_objects/amount.hpp b/shared_model/backend/protobuf/common_objects/amount.hpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/shared_model/cryptography/CMakeLists.txt b/shared_model/cryptography/CMakeLists.txt index 4d3b778da1..31ca9b3ae1 100644 --- a/shared_model/cryptography/CMakeLists.txt +++ b/shared_model/cryptography/CMakeLists.txt @@ -12,3 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. +add_subdirectory(ed25519_sha3_impl) diff --git a/shared_model/cryptography/blob_impl.hpp b/shared_model/cryptography/blob_impl.hpp new file mode 100644 index 0000000000..50a0e2d3b3 --- /dev/null +++ b/shared_model/cryptography/blob_impl.hpp @@ -0,0 +1,59 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_SHARED_MODEL_BLOB_IMPL_HPP +#define IROHA_SHARED_MODEL_BLOB_IMPL_HPP + +#include +#include "cryptography/blob.hpp" +#include "utils/lazy_initializer.hpp" + +namespace shared_model { + namespace crypto { + /** + * Blob interface implementation. + */ + class BlobImpl : public Blob { + public: + explicit BlobImpl(const std::string &blob) + : blob_(blob), hex_([this]() { + std::stringstream ss; + ss << std::hex << std::setfill('0'); + for (const auto &c : blob_) { + ss << std::setw(2) << static_cast(c); + } + return ss.str(); + }) {} + + const std::string &blob() const override { return blob_; } + + const std::string &hex() const override { return hex_.get(); } + + size_t size() const override { return blob_.size(); } + + BlobImpl *copy() const override { return new BlobImpl(blob()); }; + + private: + template + using Lazy = detail::LazyInitializer; + + std::string blob_; + Lazy hex_; + }; + } // namespace crypto +} // namespace shared_model +#endif // IROHA_SHARED_MODEL_BLOB_IMPL_HPP diff --git a/shared_model/cryptography/ed25519_sha3_impl/crypto_provider.cpp b/shared_model/cryptography/ed25519_sha3_impl/crypto_provider.cpp new file mode 100644 index 0000000000..a123f9940c --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/crypto_provider.cpp @@ -0,0 +1,56 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "crypto_provider.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" + +namespace shared_model { + namespace crypto { + + Signed CryptoProvider::sign(const Blob &blob, + const Keypair &keypair) const { + return Signer().sign(blob, keypair); + } + + bool CryptoProvider::verify(const Signed &signedData, + const Blob &orig, + const PublicKey &publicKey) const { + return Verifier().verify(signedData, orig, publicKey); + } + + Seed CryptoProvider::generateSeed() const { + return Seed(iroha::create_seed().to_string()); + } + + Seed CryptoProvider::generateSeed(const std::string &passphrase) const { + return Seed(iroha::create_seed(passphrase).to_string()); + } + + Keypair CryptoProvider::generateKeypair() const { + auto keypair = iroha::create_keypair(); + return Keypair(PublicKey(keypair.pubkey.to_string()), + PrivateKey(keypair.privkey.to_string())); + } + + Keypair CryptoProvider::generateKeypair(const Seed &seed) const { + auto keypair = + iroha::create_keypair(seed.makeOldModel()); + return Keypair(PublicKey(keypair.pubkey.to_string()), + PrivateKey(keypair.privkey.to_string())); + } + } // namespace crypto +} // namespace shared_model diff --git a/shared_model/cryptography/ed25519_sha3_impl/crypto_provider.hpp b/shared_model/cryptography/ed25519_sha3_impl/crypto_provider.hpp new file mode 100644 index 0000000000..632766756e --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/crypto_provider.hpp @@ -0,0 +1,83 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_CRYPTOPROVIDER_HPP +#define IROHA_CRYPTOPROVIDER_HPP + +#include "cryptography/ed25519_sha3_impl/signer.hpp" +#include "cryptography/ed25519_sha3_impl/verifier.hpp" +#include "cryptography/seed.hpp" + +namespace shared_model { + namespace crypto { + /** + * Wrapper class for signing-related stuff. + */ + class CryptoProvider { + public: + /** + * Signs the message. + * @param blob - blob to sign + * @param keypair - keypair + * @return Signed object with signed data + */ + Signed sign(const Blob &blob, const Keypair &keypair) const; + + /** + * Verifies signature. + * @param signedData - data to verify + * @param orig - original message + * @param publicKey - public key + * @return true if verify was OK or false otherwise + */ + bool verify(const Signed &signedData, + const Blob &orig, + const PublicKey &publicKey) const; + /** + * Generates nes seed + * @return Seed generated + */ + Seed generateSeed() const; + + /** + * Generates new seed from a provided passphrase + * @param passphrase - passphrase to generate seed from + * @return Seed generated + */ + Seed generateSeed(const std::string &passphrase) const; + + /** + * Generates new keypair with a default seed + * @return Keypair generated + */ + Keypair generateKeypair() const; + + /** + * Generates new keypair from a provided seed + * @param seed - provided seed + * @return generated keypair + */ + Keypair generateKeypair(const Seed &seed) const; + + private: + Signer signer_; + Verifier verifier_; + }; + } // namespace crypto +} // namespace shared_model + +#endif // IROHA_CRYPTOPROVIDER_HPP diff --git a/shared_model/cryptography/ed25519_sha3_impl/hash_provider.cpp b/shared_model/cryptography/ed25519_sha3_impl/hash_provider.cpp new file mode 100644 index 0000000000..47c1d9a985 --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/hash_provider.cpp @@ -0,0 +1,30 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cryptography/ed25519_sha3_impl/hash_provider.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" + +namespace shared_model { + namespace crypto { + Hash HashProvider::sha3_256(const Blob &blob) const { + return Hash(iroha::sha3_256(blob.blob()).to_string()); + } + Hash HashProvider::sha3_512(const Blob &blob) const { + return Hash(iroha::sha3_512(blob.blob()).to_string()); + } + } // namespace crypto +} // namespace shared_model diff --git a/shared_model/cryptography/ed25519_sha3_impl/hash_provider.hpp b/shared_model/cryptography/ed25519_sha3_impl/hash_provider.hpp new file mode 100644 index 0000000000..9ed5a679e1 --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/hash_provider.hpp @@ -0,0 +1,48 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_HASH_PROVIDER_HPP +#define IROHA_HASH_PROVIDER_HPP + +#include "cryptography/blob.hpp" +#include "cryptography/hash.hpp" + +namespace shared_model { + namespace crypto { + /** + * Wrapper class for hashing. + */ + class HashProvider { + public: + /** + * Hash with sha3-256 + * @param blob - blob to hash + * @return Hash of provided blob + */ + Hash sha3_256(const Blob &blob) const; + + /** + * Hash with sha3-512 + * @param blob - blob to hash + * @return Hash of provided blob + */ + Hash sha3_512(const Blob &blob) const; + }; + } // namespace crypto +} // namespace shared_model + +#endif // IROHA_HASH_PROVIDER_HPP diff --git a/libs/crypto/ed25519_impl.cpp b/shared_model/cryptography/ed25519_sha3_impl/internal/ed25519_impl.cpp similarity index 74% rename from libs/crypto/ed25519_impl.cpp rename to shared_model/cryptography/ed25519_sha3_impl/internal/ed25519_impl.cpp index 31ab2e90f8..d83818e4a8 100644 --- a/libs/crypto/ed25519_impl.cpp +++ b/shared_model/cryptography/ed25519_sha3_impl/internal/ed25519_impl.cpp @@ -15,43 +15,48 @@ * limitations under the License. */ -#include #include -#include "crypto.hpp" -#include "hash.hpp" +#include "ed25519_impl.hpp" +#include "cryptography/ed25519_sha3_impl/internal/impl/ed25519.h" +#include "sha3_hash.hpp" namespace iroha { /** * Sign the message */ - sig_t sign(const uint8_t *msg, size_t msgsize, const pubkey_t &pub, + sig_t sign(const uint8_t *msg, + size_t msgsize, + const pubkey_t &pub, const privkey_t &priv) { sig_t sig; ed25519_sign(sig.data(), msg, msgsize, pub.data(), priv.data()); return sig; } - sig_t sign(const std::string &msg, const pubkey_t &pub, + sig_t sign(const std::string &msg, + const pubkey_t &pub, const privkey_t &priv) { sig_t sig; - ed25519_sign(sig.data(), (uint8_t *)msg.data(), msg.size(), pub.data(), - priv.data()); + ed25519_sign( + sig.data(), (uint8_t *)msg.data(), msg.size(), pub.data(), priv.data()); return sig; } - /** * Verify signature */ - bool verify(const uint8_t *msg, size_t msgsize, const pubkey_t &pub, + bool verify(const uint8_t *msg, + size_t msgsize, + const pubkey_t &pub, const sig_t &sig) { return 1 == ed25519_verify(sig.data(), msg, msgsize, pub.data()); } bool verify(const std::string &msg, const pubkey_t &pub, const sig_t &sig) { - return 1 == ed25519_verify(sig.data(), (uint8_t *)msg.data(), msg.size(), - pub.data()); + return 1 + == ed25519_verify( + sig.data(), (uint8_t *)msg.data(), msg.size(), pub.data()); } /** @@ -85,4 +90,4 @@ namespace iroha { } keypair_t create_keypair() { return create_keypair(create_seed()); } -} +} // namespace iroha diff --git a/libs/crypto/crypto.hpp b/shared_model/cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp similarity index 84% rename from libs/crypto/crypto.hpp rename to shared_model/cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp index 50935a05f9..2c7e7a3b6a 100644 --- a/libs/crypto/crypto.hpp +++ b/shared_model/cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp @@ -31,11 +31,13 @@ namespace iroha { * @param priv * @return */ - sig_t sign(const uint8_t *msg, size_t msgsize, - const pubkey_t &pub, - const privkey_t &priv); + sig_t sign(const uint8_t *msg, + size_t msgsize, + const pubkey_t &pub, + const privkey_t &priv); - sig_t sign(const std::string &msg, const pubkey_t &pub, + sig_t sign(const std::string &msg, + const pubkey_t &pub, const privkey_t &priv); /** @@ -46,7 +48,9 @@ namespace iroha { * @param sig * @return true if signature is valid, false otherwise */ - bool verify(const uint8_t *msg, size_t msgsize, const pubkey_t &pub, + bool verify(const uint8_t *msg, + size_t msgsize, + const pubkey_t &pub, const sig_t &sig); bool verify(const std::string &msg, const pubkey_t &pub, const sig_t &sig); @@ -76,6 +80,5 @@ namespace iroha { */ keypair_t create_keypair(); - -} +} // namespace iroha #endif // IROHA_CRYPTO_HPP diff --git a/libs/crypto/ed25519/add_scalar.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/add_scalar.c similarity index 100% rename from libs/crypto/ed25519/add_scalar.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/add_scalar.c diff --git a/libs/crypto/ed25519/ed25519.h b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/ed25519.h similarity index 100% rename from libs/crypto/ed25519/ed25519.h rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/ed25519.h diff --git a/libs/crypto/ed25519/fe.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/fe.c similarity index 100% rename from libs/crypto/ed25519/fe.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/fe.c diff --git a/libs/crypto/ed25519/fe.h b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/fe.h similarity index 100% rename from libs/crypto/ed25519/fe.h rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/fe.h diff --git a/libs/crypto/ed25519/fixedint.h b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/fixedint.h similarity index 100% rename from libs/crypto/ed25519/fixedint.h rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/fixedint.h diff --git a/libs/crypto/ed25519/ge.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/ge.c similarity index 100% rename from libs/crypto/ed25519/ge.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/ge.c diff --git a/libs/crypto/ed25519/ge.h b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/ge.h similarity index 100% rename from libs/crypto/ed25519/ge.h rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/ge.h diff --git a/libs/crypto/ed25519/key_exchange.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/key_exchange.c similarity index 100% rename from libs/crypto/ed25519/key_exchange.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/key_exchange.c diff --git a/libs/crypto/ed25519/keypair.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/keypair.c similarity index 100% rename from libs/crypto/ed25519/keypair.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/keypair.c diff --git a/libs/crypto/ed25519/precomp_data.h b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/precomp_data.h similarity index 100% rename from libs/crypto/ed25519/precomp_data.h rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/precomp_data.h diff --git a/libs/crypto/ed25519/sc.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/sc.c similarity index 100% rename from libs/crypto/ed25519/sc.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/sc.c diff --git a/libs/crypto/ed25519/sc.h b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/sc.h similarity index 100% rename from libs/crypto/ed25519/sc.h rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/sc.h diff --git a/libs/crypto/ed25519/seed.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/seed.c similarity index 100% rename from libs/crypto/ed25519/seed.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/seed.c diff --git a/libs/crypto/ed25519/sha3.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/sha3.c similarity index 100% rename from libs/crypto/ed25519/sha3.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/sha3.c diff --git a/libs/crypto/ed25519/sha3.h b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/sha3.h similarity index 100% rename from libs/crypto/ed25519/sha3.h rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/sha3.h diff --git a/libs/crypto/ed25519/sha512.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/sha512.c similarity index 100% rename from libs/crypto/ed25519/sha512.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/sha512.c diff --git a/libs/crypto/ed25519/sha512.h b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/sha512.h similarity index 100% rename from libs/crypto/ed25519/sha512.h rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/sha512.h diff --git a/libs/crypto/ed25519/sign.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/sign.c similarity index 100% rename from libs/crypto/ed25519/sign.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/sign.c diff --git a/libs/crypto/ed25519/verify.c b/shared_model/cryptography/ed25519_sha3_impl/internal/impl/verify.c similarity index 100% rename from libs/crypto/ed25519/verify.c rename to shared_model/cryptography/ed25519_sha3_impl/internal/impl/verify.c diff --git a/libs/crypto/hash.cpp b/shared_model/cryptography/ed25519_sha3_impl/internal/sha3_hash.cpp similarity index 96% rename from libs/crypto/hash.cpp rename to shared_model/cryptography/ed25519_sha3_impl/internal/sha3_hash.cpp index ea7efd752e..90118bb6eb 100644 --- a/libs/crypto/hash.cpp +++ b/shared_model/cryptography/ed25519_sha3_impl/internal/sha3_hash.cpp @@ -15,10 +15,10 @@ * limitations under the License. */ -#include "crypto/hash.hpp" +#include "sha3_hash.hpp" extern "C" { -#include +#include "cryptography/ed25519_sha3_impl/internal/impl/sha3.h" } #include "common/types.hpp" diff --git a/libs/crypto/hash.hpp b/shared_model/cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp similarity index 100% rename from libs/crypto/hash.hpp rename to shared_model/cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp diff --git a/shared_model/cryptography/ed25519_sha3_impl/proto/ed25519_proto_signature.cpp b/shared_model/cryptography/ed25519_sha3_impl/proto/ed25519_proto_signature.cpp new file mode 100644 index 0000000000..0e697df851 --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/proto/ed25519_proto_signature.cpp @@ -0,0 +1,17 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + diff --git a/shared_model/cryptography/ed25519_sha3_impl/signer.cpp b/shared_model/cryptography/ed25519_sha3_impl/signer.cpp new file mode 100644 index 0000000000..2c4ff28a8b --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/signer.cpp @@ -0,0 +1,33 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cryptography/ed25519_sha3_impl/signer.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" + +namespace shared_model { + namespace crypto { + Signed Signer::sign(const Blob &blob, const Keypair &keypair) const { + return Signed( + iroha::sign( + blob.blob(), + keypair.publicKey().makeOldModel(), + keypair.privateKey() + .makeOldModel()) + .to_string()); + } + } // namespace crypto +} // namespace shared_model diff --git a/shared_model/cryptography/ed25519_sha3_impl/signer.hpp b/shared_model/cryptography/ed25519_sha3_impl/signer.hpp new file mode 100644 index 0000000000..f8d41565dd --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/signer.hpp @@ -0,0 +1,43 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_SHARED_MODEL_SIGNER_HPP +#define IROHA_SHARED_MODEL_SIGNER_HPP + +#include "cryptography/blob.hpp" +#include "cryptography/keypair.hpp" +#include "cryptography/signed.hpp" + +namespace shared_model { + namespace crypto { + /** + * Class which signs provided data with a provided private key. + */ + class Signer { + public: + /** + * Signs provided blob. + * @param blob - to sign + * @param keypair - keypair with public and private keys + * @return Signed object with signed data + */ + Signed sign(const Blob &blob, const Keypair &keypair) const; + }; + } // namespace crypto +} // namespace shared_model + +#endif // IROHA_SHARED_MODEL_SIGNER_HPP diff --git a/shared_model/cryptography/ed25519_sha3_impl/verifier.cpp b/shared_model/cryptography/ed25519_sha3_impl/verifier.cpp new file mode 100644 index 0000000000..ef9be3f7dc --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/verifier.cpp @@ -0,0 +1,32 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "verifier.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" + +namespace shared_model { + namespace crypto { + bool Verifier::verify(const Signed &signedData, + const Blob &orig, + const PublicKey &publicKey) const { + return iroha::verify( + orig.blob(), + publicKey.makeOldModel(), + signedData.makeOldModel()); + } + } // namespace crypto +} // namespace shared_model diff --git a/shared_model/cryptography/ed25519_sha3_impl/verifier.hpp b/shared_model/cryptography/ed25519_sha3_impl/verifier.hpp new file mode 100644 index 0000000000..ccb13a684d --- /dev/null +++ b/shared_model/cryptography/ed25519_sha3_impl/verifier.hpp @@ -0,0 +1,39 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_SHARED_MODEL_VERIFIER_HPP +#define IROHA_SHARED_MODEL_VERIFIER_HPP + +#include "cryptography/public_key.hpp" +#include "cryptography/signed.hpp" + +namespace shared_model { + namespace crypto { + /** + * Class for signature verification. + */ + class Verifier { + public: + bool verify(const Signed &signedData, + const Blob &orig, + const PublicKey &publicKey) const; + }; + + } // namespace crypto +} // namespace shared_model + +#endif // IROHA_SHARED_MODEL_VERIFIER_HPP diff --git a/shared_model/cryptography/hash.hpp b/shared_model/cryptography/hash.hpp index 9d53a3ef5c..6703440ad2 100644 --- a/shared_model/cryptography/hash.hpp +++ b/shared_model/cryptography/hash.hpp @@ -18,7 +18,7 @@ #ifndef IROHA_SHARED_MODEL_HASH_HPP #define IROHA_SHARED_MODEL_HASH_HPP -#include "cryptography/blob.hpp" +#include "cryptography/blob_impl.hpp" #include "utils/string_builder.hpp" namespace shared_model { @@ -28,8 +28,10 @@ namespace shared_model { * make difference between Hash which should represent a hashing result and * a generic Blob which should represent any binary data. */ - class Hash : public Blob { + class Hash : public BlobImpl { public: + explicit Hash(const std::string &hash) : BlobImpl(hash) {} + std::string toString() const override { return detail::PrettyStringBuilder() .init("Hash") diff --git a/shared_model/cryptography/keypair.hpp b/shared_model/cryptography/keypair.hpp index 3176c8b68b..88435f3da0 100644 --- a/shared_model/cryptography/keypair.hpp +++ b/shared_model/cryptography/keypair.hpp @@ -18,33 +18,39 @@ #ifndef IROHA_SHARED_MODEL_KEYPAIR_HPP #define IROHA_SHARED_MODEL_KEYPAIR_HPP +#include "cryptography/blob_impl.hpp" #include "cryptography/private_key.hpp" #include "cryptography/public_key.hpp" -#include "interfaces/model_primitive.hpp" +#include "interfaces/primitive.hpp" #include "utils/string_builder.hpp" +#include "common/types.hpp" + namespace shared_model { namespace crypto { /** * Class for holding a keypair: public key and private key */ - class Keypair : public interface::ModelPrimitive { + class Keypair : public interface::Primitive { public: /// Type of public key using PublicKeyType = PublicKey; + /// Type of private key + using PrivateKeyType = PrivateKey; + + explicit Keypair(PublicKeyType publickKey, PrivateKeyType privateKey) + : publicKey_(publickKey), privateKey_(privateKey) {} + /** * @return public key */ - virtual const PublicKeyType &publicKey() const = 0; - - /// Type of private key - using PrivateKeyType = PrivateKey; + const PublicKeyType &publicKey() const { return publicKey_; }; /** * @return private key */ - virtual const PrivateKeyType &privateKey() const = 0; + const PrivateKeyType &privateKey() const { return privateKey_; }; bool operator==(const Keypair &keypair) const override { return publicKey() == keypair.publicKey() @@ -58,6 +64,21 @@ namespace shared_model { .append("privateKey", privateKey().toString()) .finalize(); } + + OldModelType *makeOldModel() const override { + return new iroha::keypair_t{ + .pubkey = publicKey().makeOldModel(), + .privkey = + privateKey().makeOldModel()}; + } + + Keypair *copy() const override { + return new Keypair(publicKey(), privateKey()); + }; + + private: + PublicKey publicKey_; + PrivateKey privateKey_; }; } }; diff --git a/shared_model/cryptography/private_key.hpp b/shared_model/cryptography/private_key.hpp index 7099bca450..564a479ef8 100644 --- a/shared_model/cryptography/private_key.hpp +++ b/shared_model/cryptography/private_key.hpp @@ -18,16 +18,21 @@ #ifndef IROHA_SHARED_MODEL_PRIVATE_KEY_HPP #define IROHA_SHARED_MODEL_PRIVATE_KEY_HPP -#include "cryptography/blob.hpp" +#include "cryptography/blob_impl.hpp" #include "utils/string_builder.hpp" +#include "common/types.hpp" + namespace shared_model { namespace crypto { /** * A special class for storing private keys. */ - class PrivateKey : public Blob { + class PrivateKey : public BlobImpl { public: + explicit PrivateKey(const std::string &privateKey) + : BlobImpl(privateKey) {} + using OldPrivateKeyType = iroha::privkey_t; std::string toString() const override { return detail::PrettyStringBuilder() .init("PrivateKey") @@ -35,7 +40,7 @@ namespace shared_model { .finalize(); } }; - } -} + } // namespace crypto +} // namespace shared_model #endif // IROHA_SHARED_MODEL_PRIVATE_KEY_HPP diff --git a/shared_model/cryptography/public_key.hpp b/shared_model/cryptography/public_key.hpp index 70e6352a08..244d3081d5 100644 --- a/shared_model/cryptography/public_key.hpp +++ b/shared_model/cryptography/public_key.hpp @@ -18,16 +18,20 @@ #ifndef IROHA_SHARED_MODEL_PUBLIC_KEY_HPP #define IROHA_SHARED_MODEL_PUBLIC_KEY_HPP -#include "cryptography/blob.hpp" +#include "cryptography/blob_impl.hpp" #include "utils/string_builder.hpp" +#include "common/types.hpp" + namespace shared_model { namespace crypto { /** * A special class for storing public keys. */ - class PublicKey : public Blob { + class PublicKey : public BlobImpl { public: + explicit PublicKey(const std::string &publicKey) : BlobImpl(publicKey) {} + using OldPublicKeyType = iroha::pubkey_t; std::string toString() const override { return detail::PrettyStringBuilder() .init("PublicKey") @@ -35,7 +39,7 @@ namespace shared_model { .finalize(); } }; - } -} + } // namespace crypto +} // namespace shared_model #endif // IROHA_SHARED_MODEL_PUBLIC_KEY_HPP diff --git a/shared_model/cryptography/seed.hpp b/shared_model/cryptography/seed.hpp new file mode 100644 index 0000000000..8e62fb093f --- /dev/null +++ b/shared_model/cryptography/seed.hpp @@ -0,0 +1,46 @@ +/** + * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved. + * http://soramitsu.co.jp + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IROHA_SEED_HPP +#define IROHA_SEED_HPP + +#include "cryptography/blob_impl.hpp" +#include "utils/string_builder.hpp" + +#include "common/types.hpp" + +namespace shared_model { + namespace crypto { + /** + * Class for seed representation. + */ + class Seed : public BlobImpl { + public: + explicit Seed(const std::string &seed) : BlobImpl(seed) {} + /// Old model seed does not have a pretty-looking typedef + using OldSeedType = iroha::blob_t<32>; + std::string toString() const override { + return detail::PrettyStringBuilder() + .init("Seed") + .append(Blob::hex()) + .finalize(); + } + }; + } // namespace crypto +}; // namespace shared_model + +#endif // IROHA_SEED_HPP diff --git a/shared_model/cryptography/signed.hpp b/shared_model/cryptography/signed.hpp index c4ce8f20b1..45a2442b07 100644 --- a/shared_model/cryptography/signed.hpp +++ b/shared_model/cryptography/signed.hpp @@ -21,14 +21,18 @@ #include "cryptography/blob.hpp" #include "utils/string_builder.hpp" +#include "common/types.hpp" + namespace shared_model { namespace crypto { /** * Class for storing signed data. It could be used not only for storing * signed hashes but for other signed objects too. */ - class Signed : public Blob { + class Signed : public BlobImpl { public: + using OldSignatureType = iroha::sig_t; + explicit Signed(const std::string &blob) : BlobImpl(blob) {} std::string toString() const override { return detail::PrettyStringBuilder() .init("Signed") @@ -36,7 +40,7 @@ namespace shared_model { .finalize(); } }; - } -} + } // namespace crypto +} // namespace shared_model #endif // IROHA_SHARED_MODEL_SIGNED_HPP diff --git a/shared_model/interfaces/commands/add_asset_quantity.hpp b/shared_model/interfaces/commands/add_asset_quantity.hpp index 446a9edbd1..a62a540bba 100644 --- a/shared_model/interfaces/commands/add_asset_quantity.hpp +++ b/shared_model/interfaces/commands/add_asset_quantity.hpp @@ -57,8 +57,8 @@ namespace shared_model { OldModelType *makeOldModel() const override { auto oldModel = new iroha::model::AddAssetQuantity; using OldAmountType = iroha::Amount; - /// Use shared_ptr and placement-new to copy new model field to oldModel's field and - /// to return raw pointer + /// Use shared_ptr and placement-new to copy new model field to + /// oldModel's field and to return raw pointer auto p = std::shared_ptr(amount().makeOldModel()); new (&oldModel->amount) OldAmountType(*p); oldModel->account_id = accountId(); diff --git a/shared_model/interfaces/common_objects/amount.hpp b/shared_model/interfaces/common_objects/amount.hpp index 841edcbe79..fce10ea443 100644 --- a/shared_model/interfaces/common_objects/amount.hpp +++ b/shared_model/interfaces/common_objects/amount.hpp @@ -22,7 +22,6 @@ #include #include #include "amount/amount.hpp" -#include "interfaces/common_objects/amount.hpp" #include "interfaces/common_objects/types.hpp" #include "interfaces/hashable.hpp" #include "interfaces/polymorphic_wrapper.hpp" diff --git a/shared_model/interfaces/impl.cpp b/shared_model/interfaces/impl.cpp index 678969c627..3a2bcec51a 100644 --- a/shared_model/interfaces/impl.cpp +++ b/shared_model/interfaces/impl.cpp @@ -18,7 +18,6 @@ #include "interfaces/common_objects/account.hpp" #include "interfaces/common_objects/account_asset.hpp" #include "interfaces/common_objects/asset.hpp" -#include "interfaces/queries/query.hpp" #include "interfaces/iroha_internal/block.hpp" #include "interfaces/iroha_internal/proposal.hpp" #include "interfaces/queries/query.hpp" diff --git a/test/framework/test_block_generator.cpp b/test/framework/test_block_generator.cpp index 7d1bdb685a..abb44be64e 100644 --- a/test/framework/test_block_generator.cpp +++ b/test/framework/test_block_generator.cpp @@ -17,7 +17,7 @@ #include #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "framework/test_block_generator.hpp" #include "model/commands/add_peer.hpp" #include "model/commands/create_domain.hpp" diff --git a/test/integration/client_test.cpp b/test/integration/client_test.cpp index b433a358c9..5ccc632dfd 100644 --- a/test/integration/client_test.cpp +++ b/test/integration/client_test.cpp @@ -19,7 +19,7 @@ #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "module/irohad/ametsuchi/ametsuchi_mocks.hpp" #include "module/irohad/network/network_mocks.hpp" #include "module/irohad/validation/validation_mocks.hpp" diff --git a/test/module/irohad/ametsuchi/ametsuchi_test.cpp b/test/module/irohad/ametsuchi/ametsuchi_test.cpp index b68ebe61aa..55f70bf37b 100644 --- a/test/module/irohad/ametsuchi/ametsuchi_test.cpp +++ b/test/module/irohad/ametsuchi/ametsuchi_test.cpp @@ -22,7 +22,7 @@ #include #include "ametsuchi/impl/storage_impl.hpp" #include "common/byteutils.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "framework/test_subscriber.hpp" #include "model/commands/add_asset_quantity.hpp" #include "model/commands/add_peer.hpp" diff --git a/test/module/irohad/consensus/yac/yac_crypto_provider_test.cpp b/test/module/irohad/consensus/yac/yac_crypto_provider_test.cpp index ff88103738..55574185b1 100644 --- a/test/module/irohad/consensus/yac/yac_crypto_provider_test.cpp +++ b/test/module/irohad/consensus/yac/yac_crypto_provider_test.cpp @@ -19,7 +19,7 @@ #include -#include "crypto/crypto.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" namespace iroha { namespace consensus { diff --git a/test/module/irohad/model/converters/json_query_factory_test.cpp b/test/module/irohad/model/converters/json_query_factory_test.cpp index d3378c53c1..7a78c21971 100644 --- a/test/module/irohad/model/converters/json_query_factory_test.cpp +++ b/test/module/irohad/model/converters/json_query_factory_test.cpp @@ -17,7 +17,7 @@ #include #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/converters/json_common.hpp" #include "model/converters/json_query_factory.hpp" #include "model/generators/query_generator.hpp" diff --git a/test/module/irohad/model/converters/pb_block_test.cpp b/test/module/irohad/model/converters/pb_block_test.cpp index 8b667241f1..5fedec53b8 100644 --- a/test/module/irohad/model/converters/pb_block_test.cpp +++ b/test/module/irohad/model/converters/pb_block_test.cpp @@ -16,7 +16,7 @@ */ #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "commands.pb.h" #include "model/block.hpp" #include "model/converters/pb_block_factory.hpp" diff --git a/test/module/irohad/model/converters/pb_query_factory_test.cpp b/test/module/irohad/model/converters/pb_query_factory_test.cpp index 70bde355c9..4af88264f4 100644 --- a/test/module/irohad/model/converters/pb_query_factory_test.cpp +++ b/test/module/irohad/model/converters/pb_query_factory_test.cpp @@ -16,7 +16,7 @@ */ #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/converters/pb_query_factory.hpp" #include "model/generators/query_generator.hpp" diff --git a/test/module/irohad/model/model_crypto_provider_test.cpp b/test/module/irohad/model/model_crypto_provider_test.cpp index 5bc956bc0c..8083c0547e 100644 --- a/test/module/irohad/model/model_crypto_provider_test.cpp +++ b/test/module/irohad/model/model_crypto_provider_test.cpp @@ -17,8 +17,8 @@ #include -#include "crypto/crypto.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/generators/query_generator.hpp" #include "model/generators/transaction_generator.hpp" #include "model/model_crypto_provider_impl.hpp" diff --git a/test/module/irohad/model/operators/model_operators_test.cpp b/test/module/irohad/model/operators/model_operators_test.cpp index abef9f631f..1ce8ddf6b0 100644 --- a/test/module/irohad/model/operators/model_operators_test.cpp +++ b/test/module/irohad/model/operators/model_operators_test.cpp @@ -16,7 +16,7 @@ */ #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/block.hpp" #include "model/commands/add_asset_quantity.hpp" #include "model/commands/subtract_asset_quantity.hpp" diff --git a/test/module/irohad/network/block_loader_test.cpp b/test/module/irohad/network/block_loader_test.cpp index 27ada03a29..2168637bcc 100644 --- a/test/module/irohad/network/block_loader_test.cpp +++ b/test/module/irohad/network/block_loader_test.cpp @@ -20,7 +20,7 @@ #include #include -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "framework/test_subscriber.hpp" #include "module/irohad/ametsuchi/ametsuchi_mocks.hpp" #include "module/irohad/model/model_mocks.hpp" diff --git a/test/module/irohad/torii/torii_service_test.cpp b/test/module/irohad/torii/torii_service_test.cpp index 328c784337..c1c594751e 100644 --- a/test/module/irohad/torii/torii_service_test.cpp +++ b/test/module/irohad/torii/torii_service_test.cpp @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "model/converters/pb_transaction_factory.hpp" #include "module/irohad/ametsuchi/ametsuchi_mocks.hpp" #include "module/irohad/network/network_mocks.hpp" diff --git a/test/module/irohad/validation/stateless/transaction_validator_test.cpp b/test/module/irohad/validation/stateless/transaction_validator_test.cpp index f9a4c65f99..e243a3a7f7 100644 --- a/test/module/irohad/validation/stateless/transaction_validator_test.cpp +++ b/test/module/irohad/validation/stateless/transaction_validator_test.cpp @@ -21,8 +21,8 @@ #include -#include "crypto/crypto.hpp" -#include "crypto/hash.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" +#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp" #include "module/irohad/model/model_mocks.hpp" #include "datetime/time.hpp" diff --git a/test/module/libs/crypto/hash_test.cpp b/test/module/libs/crypto/hash_test.cpp index 07483c3185..3f081d646a 100644 --- a/test/module/libs/crypto/hash_test.cpp +++ b/test/module/libs/crypto/hash_test.cpp @@ -15,7 +15,7 @@ limitations under the License. */ #include -#include +#include #define LOOP_N (100) diff --git a/test/module/libs/crypto/signature_test.cpp b/test/module/libs/crypto/signature_test.cpp index 64aa61c159..b94d49dcbd 100644 --- a/test/module/libs/crypto/signature_test.cpp +++ b/test/module/libs/crypto/signature_test.cpp @@ -17,7 +17,7 @@ limitations under the License. #include "common/byteutils.hpp" #include "common/types.hpp" #include "crypto/base64.hpp" -#include "crypto/crypto.hpp" +#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp" #include