Botan 3.14.1
Crypto and TLS for C&
dl_scheme.h
Go to the documentation of this file.
1/*
2* (C) 2023 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_DL_SCHEME_H_
8#define BOTAN_DL_SCHEME_H_
9
10#include <botan/bigint.h>
11#include <botan/dl_group.h>
12#include <memory>
13#include <span>
14#include <string_view>
15
16namespace Botan {
17
20
21class DL_PublicKey final {
22 public:
24
25 DL_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits, DL_Group_Format format);
26
27 bool check_key(RandomNumberGenerator& rng, bool strong) const;
28
29 const DL_Group& group() const { return m_group; }
30
31 const BigInt& public_key() const { return m_public_key; }
32
33 // Return the binary representation of the integer public key
34 std::vector<uint8_t> public_key_as_bytes() const;
35
36 const BigInt& get_int_field(std::string_view algo_name, std::string_view field) const;
37
38 std::vector<uint8_t> DER_encode() const;
39
40 size_t estimated_strength() const;
41
42 size_t p_bits() const;
43
44 private:
45 const DL_Group m_group;
46 const BigInt m_public_key;
47};
48
49class DL_PrivateKey final {
50 public:
52
54
55 DL_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits, DL_Group_Format format);
56
57 bool check_key(RandomNumberGenerator& rng, bool strong) const;
58
59 /**
60 * Return a new shared_ptr of the associated public key
61 */
62 std::shared_ptr<DL_PublicKey> public_key() const;
63
64 /**
65 * Return the group this key operates in
66 */
67 const DL_Group& group() const { return m_group; }
68
69 /**
70 * Return the integer value of the private key
71 */
72 const BigInt& private_key() const { return m_private_key; }
73
74 /**
75 * Return a public upper bound on the bit length of the private key,
76 * for use as the exponent length when exponentiating by it
77 */
78 size_t max_private_key_bits() const { return m_max_private_key_bits; }
79
80 /**
81 * DER encode the private key
82 */
84
85 /**
86 * Return the raw serialization of the private key
87 */
89
90 const BigInt& get_int_field(std::string_view algo_name, std::string_view field) const;
91
92 private:
93 const DL_Group m_group;
94 const BigInt m_private_key;
95 const size_t m_max_private_key_bits;
96 const BigInt m_public_key;
97};
98
99} // namespace Botan
100
101#endif
DL_PrivateKey(const DL_Group &group, const BigInt &private_key)
const BigInt & private_key() const
Definition dl_scheme.h:72
secure_vector< uint8_t > DER_encode() const
size_t max_private_key_bits() const
Definition dl_scheme.h:78
const BigInt & get_int_field(std::string_view algo_name, std::string_view field) const
secure_vector< uint8_t > raw_private_key_bits() const
const DL_Group & group() const
Definition dl_scheme.h:67
std::shared_ptr< DL_PublicKey > public_key() const
bool check_key(RandomNumberGenerator &rng, bool strong) const
std::vector< uint8_t > public_key_as_bytes() const
Definition dl_scheme.cpp:78
const BigInt & get_int_field(std::string_view algo_name, std::string_view field) const
size_t p_bits() const
Definition dl_scheme.cpp:96
size_t estimated_strength() const
Definition dl_scheme.cpp:92
std::vector< uint8_t > DER_encode() const
Definition dl_scheme.cpp:82
bool check_key(RandomNumberGenerator &rng, bool strong) const
Definition dl_scheme.cpp:88
const BigInt & public_key() const
Definition dl_scheme.h:31
DL_PublicKey(const DL_Group &group, const BigInt &public_key)
Definition dl_scheme.cpp:69
const DL_Group & group() const
Definition dl_scheme.h:29
DL_Group_Format
Definition dl_group.h:30
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128