Vanetza
 
Loading...
Searching...
No Matches
ecdsa256.cpp
1#include <vanetza/security/ecc_point.hpp>
2#include <vanetza/security/ecdsa256.hpp>
3#include <boost/functional/hash.hpp>
4#include <algorithm>
5#include <cassert>
6
7namespace vanetza
8{
9namespace security
10{
11namespace ecdsa256
12{
13
14PublicKey create_public_key(const Uncompressed& unc)
15{
16 PublicKey pb;
17 assert(unc.x.size() == pb.x.size());
18 assert(unc.y.size() == pb.y.size());
19 std::copy_n(unc.x.begin(), pb.x.size(), pb.x.begin());
20 std::copy_n(unc.y.begin(), pb.y.size(), pb.y.begin());
21 return pb;
22}
23
24bool operator==(const PublicKey& lhs, const PublicKey& rhs)
25{
26 return lhs.x == rhs.x && lhs.y == rhs.y;
27}
28
29bool operator!=(const PublicKey& lhs, const PublicKey& rhs)
30{
31 return !(lhs == rhs);
32}
33
34bool operator==(const PrivateKey& lhs, const PrivateKey& rhs)
35{
36 return lhs.key == rhs.key;
37}
38
39bool operator!=(const PrivateKey& lhs, const PrivateKey& rhs)
40{
41 return !(lhs == rhs);
42}
43
44} // namespace ecdsa256
45} // namespace security
46} // namespace vanetza
47
48namespace std
49{
50
53
54size_t hash<PublicKey>::operator()(const PublicKey& k) const
55{
56 size_t seed = 0;
57 boost::hash_combine(seed, k.x);
58 boost::hash_combine(seed, k.y);
59 return seed;
60}
61
62size_t hash<PrivateKey>::operator()(const PrivateKey& k) const
63{
64 return boost::hash_range(k.key.begin(), k.key.end());
65}
66
67} // namespace std
STL namespace.