Skip to content

Commit

Permalink
Add crypto implementation to shared model:
Browse files Browse the repository at this point in the history
- Move all crypto and hash code to shared model
- Add BlobImpl class as implementation of Blob interface
- Inherit BlobImpl instead of Blob for public and private keys, Signed, Hash
- Replace Keypair interface with implementation
- Inherit Keypair from Primitive; add makeOldModel
- Introduce new Seed object for storing seeds
- Add Signer and Verifier as low-level crypto wrappers
- Add CryptoProvider as a wrapper for all crypto operations
- Add HashProvider as a wrapper for all low-level hashing operations
- Use real hashes in proto Amount and AddAssetQuantity

Signed-off-by: luckychess <[email protected]>
  • Loading branch information
luckychess authored and lebdron committed Dec 19, 2017
1 parent 850e065 commit 7caae6f
Show file tree
Hide file tree
Showing 87 changed files with 624 additions and 127 deletions.
2 changes: 1 addition & 1 deletion fuzz/core/crypto/hash256_fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <string>
#include <vector>
#include <crypto/hash.hpp>
#include <cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
std::string s((const char*)data, size);
Expand Down
2 changes: 1 addition & 1 deletion fuzz/core/crypto/hash512_fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <string>
#include <vector>
#include <crypto/hash.hpp>
#include <cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
std::string s((const char*)data, size);
Expand Down
4 changes: 2 additions & 2 deletions iroha-cli/interactive/impl/interactive_query_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion iroha-cli/interactive/impl/interactive_transaction_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <fstream>
#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"
Expand Down
4 changes: 2 additions & 2 deletions irohad/consensus/yac/impl/yac_crypto_provider_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion irohad/main/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/converters/impl/json_query_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/converters/impl/json_transaction_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "model/converters/json_transaction_factory.hpp"

#include <algorithm>
#include "crypto/hash.hpp"
#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp"
#include "model/converters/json_common.hpp"

using namespace rapidjson;
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/converters/impl/pb_block_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/converters/impl/pb_query_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "model/converters/pb_query_factory.hpp"
#include <queries.pb.h>
#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"
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/converters/impl/pb_transaction_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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 "model/commands/add_asset_quantity.hpp"
#include "model/converters/pb_command_factory.hpp"
Expand Down
4 changes: 2 additions & 2 deletions irohad/model/converters/pb_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/generators/impl/block_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "model/generators/block_generator.hpp"
#include <chrono>
#include <utility>
#include "crypto/hash.hpp"
#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp"

namespace iroha {
namespace model {
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/generators/impl/query_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <memory>

#include "model/generators/query_generator.hpp"
#include "crypto/hash.hpp"
#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp"

namespace iroha {
namespace model {
Expand Down
2 changes: 1 addition & 1 deletion irohad/model/generators/impl/transaction_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion irohad/model/impl/query_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions irohad/model/model_crypto_provider_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion irohad/simulator/impl/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions irohad/torii/impl/command_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include "torii/command_service.hpp"
#include <endpoint.pb.h>
#include "crypto/hash.hpp"
#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp"
#include "torii/command_service.hpp"
#include "common/types.hpp"

namespace torii {

Expand Down
2 changes: 1 addition & 1 deletion irohad/torii/impl/query_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion irohad/torii/processor/impl/query_processor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion irohad/torii/processor/impl/transaction_processor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <endpoint.pb.h>
#include <iostream>
#include <utility>
#include "crypto/hash.hpp"
#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp"
#include "model/transaction_response.hpp"

namespace iroha {
Expand Down
4 changes: 2 additions & 2 deletions irohad/validation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_library(stateful_validator
)
target_link_libraries(stateful_validator
optional
ed25519
ed25519_sha3
rxcpp
model
logger
Expand All @@ -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
Expand Down
19 changes: 0 additions & 19 deletions libs/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions libs/crypto/ed25519/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion libs/crypto/keys_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define IROHA_CLI_KEYS_MANAGER_HPP

#include <nonstd/optional.hpp>
#include "crypto/crypto.hpp"
#include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp"

namespace iroha {

Expand Down
4 changes: 2 additions & 2 deletions libs/crypto/keys_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fstream>
Expand Down
2 changes: 1 addition & 1 deletion libs/random/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
#define __RANDOM_HPP_

#include <random>
#include "../crypto/hash.hpp"
#include "cryptography/ed25519_sha3_impl/internal/sha3_hash.hpp"

namespace random_service {

Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions shared_model/cryptography/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

add_subdirectory(ed25519_sha3_impl)
59 changes: 59 additions & 0 deletions shared_model/cryptography/blob_impl.hpp
Original file line number Diff line number Diff line change
@@ -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 <iomanip>
#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<int>(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 <typename Value>
using Lazy = detail::LazyInitializer<Value>;

std::string blob_;
Lazy<std::string> hex_;
};
} // namespace crypto
} // namespace shared_model
#endif // IROHA_SHARED_MODEL_BLOB_IMPL_HPP
Loading

0 comments on commit 7caae6f

Please sign in to comment.