Botan 3.8.1
Crypto and TLS for C&
ffi_pkey.cpp
Go to the documentation of this file.
1/*
2* (C) 2015,2017 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/ffi.h>
8
9#include <botan/data_src.h>
10#include <botan/hash.h>
11#include <botan/pk_algs.h>
12#include <botan/pk_keys.h>
13#include <botan/pkcs8.h>
14#include <botan/x509_key.h>
15#include <botan/internal/ffi_ec.h>
16#include <botan/internal/ffi_oid.h>
17#include <botan/internal/ffi_pkey.h>
18#include <botan/internal/ffi_rng.h>
19#include <botan/internal/ffi_util.h>
20
21#if defined(BOTAN_HAS_HASH_ID)
22 #include <botan/internal/hash_id.h>
23#endif
24
25extern "C" {
26
27using namespace Botan_FFI;
28
30 const char* algo_name,
31 const char* algo_params,
32 botan_rng_t rng_obj) {
33 return ffi_guard_thunk(__func__, [=]() -> int {
34 if(key_obj == nullptr) {
36 }
37
38 *key_obj = nullptr;
39 if(rng_obj == nullptr) {
41 }
42
44 std::unique_ptr<Botan::Private_Key> key(
45 Botan::create_private_key(algo_name ? algo_name : "RSA", rng, algo_params ? algo_params : ""));
46
47 if(key) {
48 *key_obj = new botan_privkey_struct(std::move(key));
49 return BOTAN_FFI_SUCCESS;
50 } else {
52 }
53 });
54}
55
57 const char* algo_name,
58 botan_ec_group_t ec_group_obj,
59 botan_rng_t rng_obj) {
60 return ffi_guard_thunk(__func__, [=]() -> int {
61 if(key_obj == nullptr) {
63 }
64 *key_obj = nullptr;
65
66 Botan::EC_Group ec_group = safe_get(ec_group_obj);
68 std::unique_ptr<Botan::Private_Key> key(
69 Botan::create_ec_private_key(algo_name ? algo_name : "ECDSA", ec_group, rng));
70
71 if(key) {
72 *key_obj = new botan_privkey_struct(std::move(key));
73 return BOTAN_FFI_SUCCESS;
74 } else {
76 }
77 });
78}
79
81 botan_privkey_t* key, botan_rng_t rng_obj, const uint8_t bits[], size_t len, const char* password) {
82 BOTAN_UNUSED(rng_obj);
83
84 *key = nullptr;
85
86 return ffi_guard_thunk(__func__, [=]() -> int {
87 Botan::DataSource_Memory src(bits, len);
88
89 std::unique_ptr<Botan::Private_Key> pkcs8;
90
91 if(password == nullptr) {
92 pkcs8 = Botan::PKCS8::load_key(src);
93 } else {
94 pkcs8 = Botan::PKCS8::load_key(src, std::string(password));
95 }
96
97 if(pkcs8) {
98 *key = new botan_privkey_struct(std::move(pkcs8));
99 return BOTAN_FFI_SUCCESS;
100 }
102 });
103}
104
108
109int botan_pubkey_load(botan_pubkey_t* key, const uint8_t bits[], size_t bits_len) {
110 *key = nullptr;
111
112 return ffi_guard_thunk(__func__, [=]() -> int {
113 Botan::DataSource_Memory src(bits, bits_len);
114 std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
115
116 if(pubkey == nullptr) {
118 }
119
120 *key = new botan_pubkey_struct(std::move(pubkey));
121 return BOTAN_FFI_SUCCESS;
122 });
123}
124
128
130 return ffi_guard_thunk(__func__, [=]() -> int {
131 auto public_key = safe_get(key_obj).public_key();
132 *pubout = new botan_pubkey_struct(std::move(public_key));
133 return BOTAN_FFI_SUCCESS;
134 });
135}
136
137int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t* out_len) {
138 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
139}
140
141int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len) {
142 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
143}
144
145int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags) {
146 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
147
148 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
149 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
150 });
151}
152
154 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS);
155 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
156 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
157 });
158}
159
160int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags) {
161 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
162 return copy_view_bin(out, out_len, botan_pubkey_view_der, key);
163 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
164 return copy_view_str(out, out_len, botan_pubkey_view_pem, key);
165 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
166 return copy_view_bin(out, out_len, botan_pubkey_view_raw, key);
167 } else {
169 }
170}
171
173 return BOTAN_FFI_VISIT(
174 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.subject_public_key()); });
175}
176
178 return BOTAN_FFI_VISIT(
179 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::X509::PEM_encode(k)); });
180}
181
183 return BOTAN_FFI_VISIT(
184 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_public_key_bits()); });
185}
186
187int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t* out_len, uint32_t flags) {
188 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
189 return copy_view_bin(out, out_len, botan_privkey_view_der, key);
190 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
191 return copy_view_str(out, out_len, botan_privkey_view_pem, key);
192 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
193 return copy_view_bin(out, out_len, botan_privkey_view_raw, key);
194 } else {
196 }
197}
198
200 return BOTAN_FFI_VISIT(
201 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::BER_encode(k)); });
202}
203
205 return BOTAN_FFI_VISIT(
206 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::PEM_encode(k)); });
207}
208
210 return BOTAN_FFI_VISIT(
211 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_private_key_bits()); });
212}
213
215 uint8_t out[],
216 size_t* out_len,
217 botan_rng_t rng_obj,
218 const char* pass,
219 const char* /*ignored - pbe*/,
220 uint32_t flags) {
221 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
222}
223
225 uint8_t out[],
226 size_t* out_len,
227 botan_rng_t rng,
228 const char* passphrase,
229 uint32_t pbkdf_msec,
230 size_t* pbkdf_iters_out,
231 const char* cipher,
232 const char* pbkdf_hash,
233 uint32_t flags) {
234 if(pbkdf_iters_out) {
235 *pbkdf_iters_out = 0;
236 }
237
238 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
239 return copy_view_bin(
240 out, out_len, botan_privkey_view_encrypted_der_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
241 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
242 return copy_view_str(
243 out, out_len, botan_privkey_view_encrypted_pem_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
244 } else {
246 }
247}
248
250 botan_rng_t rng_obj,
251 const char* passphrase,
252 const char* maybe_cipher,
253 const char* maybe_pbkdf_algo,
254 size_t pbkdf_runtime_msec,
255 botan_view_ctx ctx,
256 botan_view_bin_fn view) {
257 if(passphrase == nullptr) {
259 }
260
261 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
262 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
264
265 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
266 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
267
268 auto pkcs8 =
269 Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
270
271 return invoke_view_callback(view, ctx, pkcs8);
272 });
273}
274
276 botan_rng_t rng_obj,
277 const char* passphrase,
278 const char* maybe_cipher,
279 const char* maybe_pbkdf_algo,
280 size_t pbkdf_runtime_msec,
281 botan_view_ctx ctx,
282 botan_view_str_fn view) {
283 if(passphrase == nullptr) {
285 }
286
287 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
288 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
290
291 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
292 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
293
294 auto pkcs8 =
295 Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
296
297 return invoke_view_callback(view, ctx, pkcs8);
298 });
299}
300
302 uint8_t out[],
303 size_t* out_len,
304 botan_rng_t rng,
305 const char* passphrase,
306 size_t pbkdf_iter,
307 const char* cipher,
308 const char* pbkdf_algo,
309 uint32_t flags) {
310 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
311 return copy_view_bin(
312 out, out_len, botan_privkey_view_encrypted_der, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
313 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
314 return copy_view_str(
315 out, out_len, botan_privkey_view_encrypted_pem, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
316 } else {
318 }
319}
320
322 botan_rng_t rng_obj,
323 const char* passphrase,
324 const char* maybe_cipher,
325 const char* maybe_pbkdf_algo,
326 size_t maybe_pbkdf_iterations,
327 botan_view_ctx ctx,
328 botan_view_bin_fn view) {
329 if(passphrase == nullptr) {
331 }
332
333 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
335
336 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
337 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
338 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
339
340 auto pkcs8 = Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
341
342 return invoke_view_callback(view, ctx, pkcs8);
343 });
344}
345
347 botan_rng_t rng_obj,
348 const char* passphrase,
349 const char* maybe_cipher,
350 const char* maybe_pbkdf_algo,
351 size_t maybe_pbkdf_iterations,
352 botan_view_ctx ctx,
353 botan_view_str_fn view) {
354 if(passphrase == nullptr) {
356 }
357
358 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
360
361 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
362 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
363 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
364
365 auto pkcs8 = Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
366
367 return invoke_view_callback(view, ctx, pkcs8);
368 });
369}
370
372 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
373 if(oid == nullptr) {
375 }
376
377 auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
378 *oid = new botan_asn1_oid_struct(std::move(oid_ptr));
379
380 return BOTAN_FFI_SUCCESS;
381 });
382}
383
385 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
386 if(oid == nullptr) {
388 }
389
390 auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
391 *oid = new botan_asn1_oid_struct(std::move(oid_ptr));
392
393 return BOTAN_FFI_SUCCESS;
394 });
395}
396
398 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
399 if(out == nullptr) {
401 }
402
403 if(k.stateful_operation()) {
404 *out = 1;
405 } else {
406 *out = 0;
407 }
408 return BOTAN_FFI_SUCCESS;
409 });
410}
411
413 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
414 if(out == nullptr) {
416 }
417
418 if(auto remaining = k.remaining_operations()) {
419 *out = remaining.value();
420 return BOTAN_FFI_SUCCESS;
421 } else {
423 }
424 });
425}
426
428 return BOTAN_FFI_VISIT(key, [=](const auto& k) { *estimate = k.estimated_strength(); });
429}
430
431int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash_fn, uint8_t out[], size_t* out_len) {
432 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
433 auto h = Botan::HashFunction::create_or_throw(hash_fn);
434 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
435 });
436}
437
438int botan_pkcs_hash_id(const char* hash_name, uint8_t pkcs_id[], size_t* pkcs_id_len) {
439#if defined(BOTAN_HAS_HASH_ID)
440 return ffi_guard_thunk(__func__, [=]() -> int {
441 const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
442 return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
443 });
444#else
445 BOTAN_UNUSED(hash_name, pkcs_id, pkcs_id_len);
447#endif
448}
449}
#define BOTAN_UNUSED
Definition assert.h:120
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298
struct botan_pubkey_struct * botan_pubkey_t
Definition ffi.h:1533
int botan_privkey_view_encrypted_pem_timed(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:275
struct botan_asn1_oid_struct * botan_asn1_oid_t
Definition ffi.h:1117
struct botan_privkey_struct * botan_privkey_t
Definition ffi.h:1300
int botan_privkey_view_encrypted_der(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_iterations, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:321
#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW
Definition ffi.h:1395
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:177
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:199
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:209
int botan_privkey_view_encrypted_der_timed(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:249
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:172
struct botan_ec_group_struct * botan_ec_group_t
Definition ffi.h:1166
int botan_privkey_view_encrypted_pem(botan_privkey_t key, botan_rng_t rng, const char *passphrase, const char *cipher_algo, const char *pbkdf_algo, size_t pbkdf_iterations, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:346
int(* botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t *data, size_t len)
Definition ffi.h:159
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1394
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:182
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition ffi.h:1323
void * botan_view_ctx
Definition ffi.h:150
struct botan_rng_struct * botan_rng_t
Definition ffi.h:287
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1393
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:136
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:144
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:129
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition ffi.h:117
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:130
@ BOTAN_FFI_SUCCESS
Definition ffi.h:113
@ BOTAN_FFI_ERROR_NO_VALUE
Definition ffi.h:119
int(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
Definition ffi.h:168
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:204
int botan_privkey_export_encrypted(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng_obj, const char *pass, const char *, uint32_t flags)
Definition ffi_pkey.cpp:214
int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags)
Definition ffi_pkey.cpp:153
int botan_pubkey_fingerprint(botan_pubkey_t key, const char *hash_fn, uint8_t out[], size_t *out_len)
Definition ffi_pkey.cpp:431
int botan_privkey_load(botan_privkey_t *key, botan_rng_t rng_obj, const uint8_t bits[], size_t len, const char *password)
Definition ffi_pkey.cpp:80
int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t *estimate)
Definition ffi_pkey.cpp:427
int botan_pkcs_hash_id(const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
Definition ffi_pkey.cpp:438
int botan_privkey_view_encrypted_der_timed(botan_privkey_t key, botan_rng_t rng_obj, const char *passphrase, const char *maybe_cipher, const char *maybe_pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:249
int botan_pubkey_load(botan_pubkey_t *key, const uint8_t bits[], size_t bits_len)
Definition ffi_pkey.cpp:109
int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition ffi_pkey.cpp:187
int botan_privkey_view_encrypted_pem_timed(botan_privkey_t key, botan_rng_t rng_obj, const char *passphrase, const char *maybe_cipher, const char *maybe_pbkdf_algo, size_t pbkdf_runtime_msec, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:275
int botan_privkey_export_encrypted_pbkdf_msec(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, uint32_t pbkdf_msec, size_t *pbkdf_iters_out, const char *cipher, const char *pbkdf_hash, uint32_t flags)
Definition ffi_pkey.cpp:224
int botan_pubkey_oid(botan_asn1_oid_t *oid, botan_pubkey_t key)
Definition ffi_pkey.cpp:371
int botan_privkey_view_encrypted_der(botan_privkey_t key, botan_rng_t rng_obj, const char *passphrase, const char *maybe_cipher, const char *maybe_pbkdf_algo, size_t maybe_pbkdf_iterations, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:321
int botan_privkey_destroy(botan_privkey_t key)
Definition ffi_pkey.cpp:105
int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t *out_len)
Definition ffi_pkey.cpp:141
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:177
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:199
int botan_privkey_stateful_operation(botan_privkey_t key, int *out)
Definition ffi_pkey.cpp:397
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:209
int botan_ec_privkey_create(botan_privkey_t *key_obj, const char *algo_name, botan_ec_group_t ec_group_obj, botan_rng_t rng_obj)
Definition ffi_pkey.cpp:56
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:172
int botan_privkey_remaining_operations(botan_privkey_t key, uint64_t *out)
Definition ffi_pkey.cpp:412
int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition ffi_pkey.cpp:160
int botan_privkey_oid(botan_asn1_oid_t *oid, botan_privkey_t key)
Definition ffi_pkey.cpp:384
int botan_pubkey_destroy(botan_pubkey_t key)
Definition ffi_pkey.cpp:125
int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t *out_len)
Definition ffi_pkey.cpp:137
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:182
int botan_privkey_create(botan_privkey_t *key_obj, const char *algo_name, const char *algo_params, botan_rng_t rng_obj)
Definition ffi_pkey.cpp:29
int botan_privkey_export_pubkey(botan_pubkey_t *pubout, botan_privkey_t key_obj)
Definition ffi_pkey.cpp:129
int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
Definition ffi_pkey.cpp:145
int botan_privkey_export_encrypted_pbkdf_iter(botan_privkey_t key, uint8_t out[], size_t *out_len, botan_rng_t rng, const char *passphrase, size_t pbkdf_iter, const char *cipher, const char *pbkdf_algo, uint32_t flags)
Definition ffi_pkey.cpp:301
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:204
int botan_privkey_view_encrypted_pem(botan_privkey_t key, botan_rng_t rng_obj, const char *passphrase, const char *maybe_cipher, const char *maybe_pbkdf_algo, size_t maybe_pbkdf_iterations, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:346
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:145
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:164
std::vector< uint8_t > BER_encode(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, std::chrono::milliseconds msec, std::string_view pbe_algo)
Definition pkcs8.cpp:164
std::string PEM_encode_encrypted_pbkdf_iter(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, size_t pbkdf_iterations, std::string_view cipher, std::string_view pbkdf_hash)
Definition pkcs8.cpp:234
std::string PEM_encode(const Private_Key &key)
Definition pkcs8.cpp:119
std::string PEM_encode_encrypted_pbkdf_msec(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, std::chrono::milliseconds pbkdf_msec, size_t *pbkdf_iterations, std::string_view cipher, std::string_view pbkdf_hash)
Definition pkcs8.cpp:281
std::vector< uint8_t > BER_encode_encrypted_pbkdf_iter(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, size_t pbkdf_iterations, std::string_view cipher, std::string_view pbkdf_hash)
Definition pkcs8.cpp:204
std::vector< uint8_t > BER_encode_encrypted_pbkdf_msec(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, std::chrono::milliseconds pbkdf_msec, size_t *pbkdf_iterations, std::string_view cipher, std::string_view pbkdf_hash)
Definition pkcs8.cpp:247
std::unique_ptr< Private_Key > load_key(DataSource &source, const std::function< std::string()> &get_pass)
Definition pkcs8.cpp:317
std::unique_ptr< Public_Key > load_key(DataSource &source)
Definition x509_key.cpp:28
std::string PEM_encode(const Public_Key &key)
Definition x509_key.cpp:21
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:166
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:189
int write_str_output(uint8_t out[], size_t *out_len, std::string_view str)
Definition ffi_util.h:230
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:67
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:197
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:83
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:226
int write_output(uint8_t out[], size_t *out_len, const uint8_t buf[], size_t buf_len)
Definition ffi_util.h:207
std::unique_ptr< Private_Key > create_private_key(std::string_view alg_name, RandomNumberGenerator &rng, std::string_view params, std::string_view provider)
Definition pk_algs.cpp:487
std::vector< uint8_t > pkcs_hash_id(std::string_view name)
Definition hash_id.cpp:78
std::unique_ptr< Private_Key > create_ec_private_key(std::string_view alg_name, const EC_Group &ec_group, RandomNumberGenerator &rng)
Definition pk_algs.cpp:442