blob: d3dbd75f5e5131eb31b3158f4a0a40d90774ee63 (
plain)
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
|
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2025
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/utils/common.h"
#include "td/utils/SharedSlice.h"
#include "td/utils/Slice.h"
#include "td/utils/Status.h"
#if TD_HAVE_OPENSSL
namespace td {
class Ed25519 {
public:
class PublicKey {
public:
static constexpr size_t LENGTH = 32;
PublicKey() = default;
explicit PublicKey(SecureString octet_string);
PublicKey(const PublicKey &other) : octet_string_(other.octet_string_.copy()) {
}
PublicKey(PublicKey &&) noexcept = default;
PublicKey &operator=(const PublicKey &other) {
CHECK(octet_string_.empty());
octet_string_ = other.octet_string_.copy();
return *this;
}
PublicKey &operator=(PublicKey &&) noexcept = delete;
~PublicKey() = default;
SecureString as_octet_string() const;
Status verify_signature(Slice data, Slice signature) const;
bool operator==(const PublicKey &other) const {
return octet_string_ == other.octet_string_;
}
bool operator!=(const PublicKey &other) const {
return octet_string_ != other.octet_string_;
}
private:
SecureString octet_string_;
};
class PrivateKey {
public:
static constexpr size_t LENGTH = 32;
explicit PrivateKey(SecureString octet_string);
SecureString as_octet_string() const;
Result<PublicKey> get_public_key() const;
Result<SecureString> sign(Slice data) const;
Result<SecureString> as_pem(Slice password) const;
static Result<PrivateKey> from_pem(Slice pem, Slice password);
private:
SecureString octet_string_;
};
static Result<PrivateKey> generate_private_key();
static Result<SecureString> compute_shared_secret(const PublicKey &public_key, const PrivateKey &private_key);
static Result<SecureString> get_public_key(Slice private_key);
};
} // namespace td
#endif
|