Botan 2.19.2
Crypto and TLS for C&
pk_keys.cpp
Go to the documentation of this file.
1/*
2* PK Key Types
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/pk_keys.h>
9#include <botan/pk_ops.h>
10#include <botan/der_enc.h>
11#include <botan/oids.h>
12#include <botan/hash.h>
13#include <botan/hex.h>
14
15namespace Botan {
16
17std::string create_hex_fingerprint(const uint8_t bits[],
18 size_t bits_len,
19 const std::string& hash_name)
20 {
21 std::unique_ptr<HashFunction> hash_fn(HashFunction::create_or_throw(hash_name));
22 const std::string hex_hash = hex_encode(hash_fn->process(bits, bits_len));
23
24 std::string fprint;
25
26 for(size_t i = 0; i != hex_hash.size(); i += 2)
27 {
28 if(i != 0)
29 fprint.push_back(':');
30
31 fprint.push_back(hex_hash[i]);
32 fprint.push_back(hex_hash[i+1]);
33 }
34
35 return fprint;
36 }
37
38std::vector<uint8_t> Public_Key::subject_public_key() const
39 {
40 std::vector<uint8_t> output;
41
45 .end_cons();
46
47 return output;
48 }
49
50/*
51* Default OID access
52*/
54 {
56 if(o.empty())
57 throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs");
58 return o;
59 }
60
62 {
63 const size_t PKCS8_VERSION = 0;
64
65 return DER_Encoder()
67 .encode(PKCS8_VERSION)
70 .end_cons()
71 .get_contents();
72 }
73
74/*
75* Hash of the X.509 subjectPublicKey encoding
76*/
77std::string Public_Key::fingerprint_public(const std::string& hash_algo) const
78 {
80 }
81
82/*
83* Hash of the PKCS #8 encoding for this key object
84*/
85std::string Private_Key::fingerprint_private(const std::string& hash_algo) const
86 {
88 }
89
90std::unique_ptr<PK_Ops::Encryption>
92 const std::string& /*params*/,
93 const std::string& /*provider*/) const
94 {
95 throw Lookup_Error(algo_name() + " does not support encryption");
96 }
97
98std::unique_ptr<PK_Ops::KEM_Encryption>
100 const std::string& /*params*/,
101 const std::string& /*provider*/) const
102 {
103 throw Lookup_Error(algo_name() + " does not support KEM encryption");
104 }
105
106std::unique_ptr<PK_Ops::Verification>
107Public_Key::create_verification_op(const std::string& /*params*/,
108 const std::string& /*provider*/) const
109 {
110 throw Lookup_Error(algo_name() + " does not support verification");
111 }
112
113std::unique_ptr<PK_Ops::Decryption>
115 const std::string& /*params*/,
116 const std::string& /*provider*/) const
117 {
118 throw Lookup_Error(algo_name() + " does not support decryption");
119 }
120
121std::unique_ptr<PK_Ops::KEM_Decryption>
123 const std::string& /*params*/,
124 const std::string& /*provider*/) const
125 {
126 throw Lookup_Error(algo_name() + " does not support KEM decryption");
127 }
128
129std::unique_ptr<PK_Ops::Signature>
131 const std::string& /*params*/,
132 const std::string& /*provider*/) const
133 {
134 throw Lookup_Error(algo_name() + " does not support signatures");
135 }
136
137std::unique_ptr<PK_Ops::Key_Agreement>
139 const std::string& /*params*/,
140 const std::string& /*provider*/) const
141 {
142 throw Lookup_Error(algo_name() + " does not support key agreement");
143 }
144
145}
secure_vector< uint8_t > get_contents()
Definition: der_enc.cpp:152
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: der_enc.cpp:181
DER_Encoder & end_cons()
Definition: der_enc.cpp:191
DER_Encoder & encode(bool b)
Definition: der_enc.cpp:285
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:329
bool empty() const
Definition: asn1_obj.h:232
std::string fingerprint_private(const std::string &alg) const
Definition: pk_keys.cpp:85
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Definition: pk_keys.h:204
virtual std::unique_ptr< PK_Ops::Signature > create_signature_op(RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
Definition: pk_keys.cpp:130
virtual std::unique_ptr< PK_Ops::Key_Agreement > create_key_agreement_op(RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
Definition: pk_keys.cpp:138
secure_vector< uint8_t > private_key_info() const
Definition: pk_keys.cpp:61
virtual std::unique_ptr< PK_Ops::Decryption > create_decryption_op(RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
Definition: pk_keys.cpp:114
virtual std::unique_ptr< PK_Ops::KEM_Decryption > create_kem_decryption_op(RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
Definition: pk_keys.cpp:122
virtual secure_vector< uint8_t > private_key_bits() const =0
virtual OID get_oid() const
Definition: pk_keys.cpp:53
virtual std::unique_ptr< PK_Ops::Encryption > create_encryption_op(RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
Definition: pk_keys.cpp:91
virtual AlgorithmIdentifier algorithm_identifier() const =0
virtual std::vector< uint8_t > public_key_bits() const =0
std::string fingerprint_public(const std::string &alg="SHA-256") const
Definition: pk_keys.cpp:77
virtual std::unique_ptr< PK_Ops::KEM_Encryption > create_kem_encryption_op(RandomNumberGenerator &rng, const std::string &params, const std::string &provider) const
Definition: pk_keys.cpp:99
std::vector< uint8_t > subject_public_key() const
Definition: pk_keys.cpp:38
virtual std::string algo_name() const =0
virtual std::unique_ptr< PK_Ops::Verification > create_verification_op(const std::string &params, const std::string &provider) const
Definition: pk_keys.cpp:107
BOTAN_UNSTABLE_API OID str2oid_or_empty(const std::string &name)
Definition: oids.cpp:116
Definition: alg_id.cpp:13
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:31
std::string create_hex_fingerprint(const uint8_t bits[], size_t bits_len, const std::string &hash_name)
Definition: pk_keys.cpp:17
@ BIT_STRING
Definition: asn1_obj.h:37
@ SEQUENCE
Definition: asn1_obj.h:42
@ OCTET_STRING
Definition: asn1_obj.h:38
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22