Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. 2017 All Rights Reserved.
3 : * http://soramitsu.co.jp
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #include "cryptography/ed25519_sha3_impl/crypto_provider.hpp"
19 : #include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp"
20 : #include "cryptography/ed25519_sha3_impl/signer.hpp"
21 : #include "cryptography/ed25519_sha3_impl/verifier.hpp"
22 :
23 : namespace shared_model {
24 : namespace crypto {
25 :
26 : Signed CryptoProviderEd25519Sha3::sign(const Blob &blob,
27 : const Keypair &keypair) {
28 5189 : return Signer::sign(blob, keypair);
29 : }
30 :
31 : bool CryptoProviderEd25519Sha3::verify(const Signed &signedData,
32 : const Blob &orig,
33 : const PublicKey &publicKey) {
34 4648 : return Verifier::verify(signedData, orig, publicKey);
35 : }
36 :
37 : Seed CryptoProviderEd25519Sha3::generateSeed() {
38 2774 : return Seed(iroha::create_seed().to_string());
39 0 : }
40 :
41 : Seed CryptoProviderEd25519Sha3::generateSeed(
42 : const std::string &passphrase) {
43 0 : return Seed(iroha::create_seed(passphrase).to_string());
44 0 : }
45 :
46 : Keypair CryptoProviderEd25519Sha3::generateKeypair() {
47 2774 : return generateKeypair(generateSeed());
48 0 : }
49 :
50 : Keypair CryptoProviderEd25519Sha3::generateKeypair(const Seed &seed) {
51 2758 : auto keypair = iroha::create_keypair(
52 2776 : iroha::blob_t<32>::from_string(toBinaryString(seed)));
53 2776 : return Keypair(PublicKey(keypair.pubkey.to_string()),
54 2757 : PrivateKey(keypair.privkey.to_string()));
55 0 : }
56 :
57 : const size_t CryptoProviderEd25519Sha3::kHashLength = 256 / 8;
58 : const size_t CryptoProviderEd25519Sha3::kPublicKeyLength = 256 / 8;
59 : const size_t CryptoProviderEd25519Sha3::kPrivateKeyLength = 512 / 8;
60 : const size_t CryptoProviderEd25519Sha3::kSignatureLength = 512 / 8;
61 : const size_t CryptoProviderEd25519Sha3::kSeedLength = 256 / 8;
62 : } // namespace crypto
63 : } // namespace shared_model
|