This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
crypto.hpp
58 lines (42 loc) · 1.77 KB
/
crypto.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (C) 2018 Bluzelle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License, version 3,
// as published by the Free Software Foundation.
//
// This program 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#pragma once
#include <crypto/crypto_base.hpp>
#include <options/options_base.hpp>
#include <proto/bluzelle.pb.h>
#include <openssl/evp.h>
#include <openssl/ec.h>
namespace bzn
{
class crypto : public bzn::crypto_base
{
public:
crypto(std::shared_ptr<bzn::options_base> options);
bool sign(bzn_envelope& msg) override;
bool verify(const bzn_envelope& msg) override;
std::string hash(const std::string& msg) override;
private:
using EC_KEY_ptr_t = std::unique_ptr<EC_KEY, decltype(&::EC_KEY_free)>;
using EVP_PKEY_ptr_t = std::unique_ptr<EVP_PKEY, decltype(&::EVP_PKEY_free)>;
using BIO_ptr_t = std::unique_ptr<BIO, decltype(&::BIO_free)>;
using EVP_MD_CTX_ptr_t = std::unique_ptr<EVP_MD_CTX, decltype(&::EVP_MD_CTX_free)>;
bool load_private_key();
void log_openssl_errors();
const std::string& extract_payload(const bzn_envelope& msg);
std::shared_ptr<bzn::options_base> options;
EVP_PKEY_ptr_t private_key_EVP = EVP_PKEY_ptr_t(nullptr, &EVP_PKEY_free);
EC_KEY_ptr_t private_key_EC = EC_KEY_ptr_t(nullptr, &EC_KEY_free);
};
}