-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrsa_authority.hpp
executable file
·85 lines (68 loc) · 1.82 KB
/
rsa_authority.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef RSA_AUTHORITY_HPP
#define RSA_AUTHORITY_HPP
#include "core.hpp"
#include <openssl/rsa.h>
#include <boost/serialization/split_member.hpp>
#include <string>
enum signature_scheme
{
rsassa_pkcs1v15_sha = 0
};
class author
{
public:
author() : key_(NULL) {}
explicit author(unsigned int bits);
boost::uint16_t signature_length() { return boost::uint16_t(RSA_size(key_)); }
mutable_buffer sign(const_buffer message, mutable_buffer signature) const;
private:
friend class authority;
friend class boost::serialization::access;
RSA* key_;
template<class Archive>
void save(Archive & ar, const unsigned int version)
{
std::vector<unsigned char> buf(i2d_RSAPrivateKey(key_, NULL));
unsigned char* buf_ptr = &buf[0];
i2d_RSAPrivateKey(key_, &buf_ptr);
ar & buf;
}
template<class Archive>
void load(Archive & ar, const unsigned int version)
{
std::vector<unsigned char> buf;
ar & buf;
unsigned char* buf_ptr = &buf[0];
key_ = d2i_RSAPrivateKey(&key_, &buf_ptr, buf.size());
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
class authority
{
public:
explicit authority() : key_(NULL) {}
authority(const_buffer key);
authority(const author& auth) : key_(RSAPublicKey_dup(auth.key_)) {}
bool verify(const_buffer message, const_buffer signature) const;
private:
friend class boost::serialization::access;
RSA* key_;
template<class Archive>
void save(Archive & ar, const unsigned int version)
{
std::vector<unsigned char> buf(i2d_RSAPublicKey(key_, NULL));
unsigned char* buf_ptr = &buf[0];
i2d_RSAPublicKey(key_, &buf_ptr);
ar & buf;
}
template<class Archive>
void load(Archive & ar, const unsigned int version)
{
std::vector<unsigned char> buf;
ar & buf;
unsigned char* buf_ptr = &buf[0];
key_ = d2i_RSAPublicKey(&key_, &buf_ptr, buf.size());
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
#endif