Botan 3.9.0
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 // TODO(Botan4) remove this implicit algorithm choice and reject nullptr algo_name
34 if(algo_name == nullptr) {
35 return botan_privkey_create(key_obj, "RSA", algo_params, rng_obj);
36 }
37
38 return ffi_guard_thunk(__func__, [=]() -> int {
39 if(key_obj == nullptr) {
41 }
42
43 *key_obj = nullptr;
44 if(rng_obj == nullptr) {
46 }
47
48 const std::string params(algo_params != nullptr ? algo_params : "");
49
51
52 if(auto key = Botan::create_private_key(algo_name, rng, params)) {
53 return ffi_new_object(key_obj, std::move(key));
54 } else {
56 }
57 });
58}
59
61 const char* algo_name,
62 botan_ec_group_t ec_group_obj,
63 botan_rng_t rng_obj) {
64 // TODO(Botan4) remove this implicit algorithm choice and reject nullptr algo_name
65 if(algo_name == nullptr) {
66 return botan_ec_privkey_create(key_obj, "ECDSA", ec_group_obj, rng_obj);
67 }
68
69 return ffi_guard_thunk(__func__, [=]() -> int {
70 if(key_obj == nullptr) {
72 }
73 *key_obj = nullptr;
74
75 Botan::EC_Group ec_group = safe_get(ec_group_obj);
77
78 if(auto key = Botan::create_ec_private_key(algo_name, ec_group, rng)) {
79 return ffi_new_object(key_obj, std::move(key));
80 } else {
82 }
83 });
84}
85
87 botan_privkey_t* key, botan_rng_t rng_obj, const uint8_t bits[], size_t len, const char* password) {
88 BOTAN_UNUSED(rng_obj);
89
90 *key = nullptr;
91
92 return ffi_guard_thunk(__func__, [=]() -> int {
93 Botan::DataSource_Memory src(bits, len);
94
95 std::unique_ptr<Botan::Private_Key> pkcs8;
96
97 if(password == nullptr) {
98 pkcs8 = Botan::PKCS8::load_key(src);
99 } else {
100 pkcs8 = Botan::PKCS8::load_key(src, std::string(password));
101 }
102
103 if(pkcs8) {
104 ffi_new_object(key, std::move(pkcs8));
105 return BOTAN_FFI_SUCCESS;
106 }
108 });
109}
110
114
115int botan_pubkey_load(botan_pubkey_t* key, const uint8_t bits[], size_t bits_len) {
116 *key = nullptr;
117
118 return ffi_guard_thunk(__func__, [=]() -> int {
119 Botan::DataSource_Memory src(bits, bits_len);
120 std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(src));
121
122 if(pubkey == nullptr) {
124 }
125
126 ffi_new_object(key, std::move(pubkey));
127 return BOTAN_FFI_SUCCESS;
128 });
129}
130
134
136 return ffi_guard_thunk(__func__, [=]() -> int {
137 auto public_key = safe_get(key_obj).public_key();
138 ffi_new_object(pubout, std::move(public_key));
139 return BOTAN_FFI_SUCCESS;
140 });
141}
142
143int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t* out_len) {
144 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
145}
146
147int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len) {
148 return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); });
149}
150
151int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags) {
152 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS) != 0;
153
154 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
155 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
156 });
157}
158
160 const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS) != 0;
161 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
162 return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT;
163 });
164}
165
166int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint32_t flags) {
167 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
168 return copy_view_bin(out, out_len, botan_pubkey_view_der, key);
169 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
170 return copy_view_str(out, out_len, botan_pubkey_view_pem, key);
171 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
172 return copy_view_bin(out, out_len, botan_pubkey_view_raw, key);
173 } else {
175 }
176}
177
179 return BOTAN_FFI_VISIT(
180 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.subject_public_key()); });
181}
182
184 return BOTAN_FFI_VISIT(
185 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::X509::PEM_encode(k)); });
186}
187
189 return BOTAN_FFI_VISIT(
190 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_public_key_bits()); });
191}
192
193int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t* out_len, uint32_t flags) {
194 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
195 return copy_view_bin(out, out_len, botan_privkey_view_der, key);
196 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
197 return copy_view_str(out, out_len, botan_privkey_view_pem, key);
198 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_RAW) {
199 return copy_view_bin(out, out_len, botan_privkey_view_raw, key);
200 } else {
202 }
203}
204
206 return BOTAN_FFI_VISIT(key,
207 [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.private_key_info()); });
208}
209
211 return BOTAN_FFI_VISIT(
212 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::PEM_encode(k)); });
213}
214
216 return BOTAN_FFI_VISIT(
217 key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_private_key_bits()); });
218}
219
221 uint8_t out[],
222 size_t* out_len,
223 botan_rng_t rng_obj,
224 const char* pass,
225 const char* /*ignored - pbe*/,
226 uint32_t flags) {
227 return botan_privkey_export_encrypted_pbkdf_iter(key, out, out_len, rng_obj, pass, 100000, nullptr, nullptr, flags);
228}
229
231 uint8_t out[],
232 size_t* out_len,
233 botan_rng_t rng,
234 const char* passphrase,
235 uint32_t pbkdf_msec,
236 size_t* pbkdf_iters_out,
237 const char* cipher,
238 const char* pbkdf_hash,
239 uint32_t flags) {
240 if(pbkdf_iters_out != nullptr) {
241 *pbkdf_iters_out = 0;
242 }
243
244 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
245 return copy_view_bin(
246 out, out_len, botan_privkey_view_encrypted_der_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
247 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
248 return copy_view_str(
249 out, out_len, botan_privkey_view_encrypted_pem_timed, key, rng, passphrase, cipher, pbkdf_hash, pbkdf_msec);
250 } else {
252 }
253}
254
256 botan_rng_t rng_obj,
257 const char* passphrase,
258 const char* maybe_cipher,
259 const char* maybe_pbkdf_algo,
260 size_t pbkdf_runtime_msec,
261 botan_view_ctx ctx,
262 botan_view_bin_fn view) {
263 if(passphrase == nullptr) {
265 }
266
267 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
268 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
270
271 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
272 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
273
274 auto pkcs8 =
275 Botan::PKCS8::BER_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
276
277 return invoke_view_callback(view, ctx, pkcs8);
278 });
279}
280
282 botan_rng_t rng_obj,
283 const char* passphrase,
284 const char* maybe_cipher,
285 const char* maybe_pbkdf_algo,
286 size_t pbkdf_runtime_msec,
287 botan_view_ctx ctx,
288 botan_view_str_fn view) {
289 if(passphrase == nullptr) {
291 }
292
293 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
294 const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec);
296
297 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
298 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
299
300 auto pkcs8 =
301 Botan::PKCS8::PEM_encode_encrypted_pbkdf_msec(k, rng, passphrase, pbkdf_time, nullptr, cipher, pbkdf_algo);
302
303 return invoke_view_callback(view, ctx, pkcs8);
304 });
305}
306
308 uint8_t out[],
309 size_t* out_len,
310 botan_rng_t rng,
311 const char* passphrase,
312 size_t pbkdf_iter,
313 const char* cipher,
314 const char* pbkdf_algo,
315 uint32_t flags) {
316 if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) {
317 return copy_view_bin(
318 out, out_len, botan_privkey_view_encrypted_der, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
319 } else if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_PEM) {
320 return copy_view_str(
321 out, out_len, botan_privkey_view_encrypted_pem, key, rng, passphrase, cipher, pbkdf_algo, pbkdf_iter);
322 } else {
324 }
325}
326
328 botan_rng_t rng_obj,
329 const char* passphrase,
330 const char* maybe_cipher,
331 const char* maybe_pbkdf_algo,
332 size_t maybe_pbkdf_iterations,
333 botan_view_ctx ctx,
334 botan_view_bin_fn view) {
335 if(passphrase == nullptr) {
337 }
338
339 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
341
342 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
343 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
344 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
345
346 auto pkcs8 = Botan::PKCS8::BER_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
347
348 return invoke_view_callback(view, ctx, pkcs8);
349 });
350}
351
353 botan_rng_t rng_obj,
354 const char* passphrase,
355 const char* maybe_cipher,
356 const char* maybe_pbkdf_algo,
357 size_t maybe_pbkdf_iterations,
358 botan_view_ctx ctx,
359 botan_view_str_fn view) {
360 if(passphrase == nullptr) {
362 }
363
364 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
366
367 const std::string cipher = (maybe_cipher ? maybe_cipher : "");
368 const std::string pbkdf_algo = (maybe_pbkdf_algo ? maybe_pbkdf_algo : "");
369 const size_t pbkdf_iter = (maybe_pbkdf_iterations ? maybe_pbkdf_iterations : 100000);
370
371 auto pkcs8 = Botan::PKCS8::PEM_encode_encrypted_pbkdf_iter(k, rng, passphrase, pbkdf_iter, cipher, pbkdf_algo);
372
373 return invoke_view_callback(view, ctx, pkcs8);
374 });
375}
376
378 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
379 if(oid == nullptr) {
381 }
382
383 auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
384 ffi_new_object(oid, std::move(oid_ptr));
385
386 return BOTAN_FFI_SUCCESS;
387 });
388}
389
391 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
392 if(oid == nullptr) {
394 }
395
396 auto oid_ptr = std::make_unique<Botan::OID>(k.object_identifier());
397 ffi_new_object(oid, std::move(oid_ptr));
398
399 return BOTAN_FFI_SUCCESS;
400 });
401}
402
404 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
405 if(out == nullptr) {
407 }
408
409 if(k.stateful_operation()) {
410 *out = 1;
411 } else {
412 *out = 0;
413 }
414 return BOTAN_FFI_SUCCESS;
415 });
416}
417
419 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
420 if(out == nullptr) {
422 }
423
424 if(auto remaining = k.remaining_operations()) {
425 *out = remaining.value();
426 return BOTAN_FFI_SUCCESS;
427 } else {
429 }
430 });
431}
432
434 return BOTAN_FFI_VISIT(key, [=](const auto& k) { *estimate = k.estimated_strength(); });
435}
436
437int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash_fn, uint8_t out[], size_t* out_len) {
438 return BOTAN_FFI_VISIT(key, [=](const auto& k) {
439 auto h = Botan::HashFunction::create_or_throw(hash_fn);
440 return write_vec_output(out, out_len, h->process(k.public_key_bits()));
441 });
442}
443
444int botan_pkcs_hash_id(const char* hash_name, uint8_t pkcs_id[], size_t* pkcs_id_len) {
445#if defined(BOTAN_HAS_HASH_ID)
446 return ffi_guard_thunk(__func__, [=]() -> int {
447 const std::vector<uint8_t> hash_id = Botan::pkcs_hash_id(hash_name);
448 return write_output(pkcs_id, pkcs_id_len, hash_id.data(), hash_id.size());
449 });
450#else
451 BOTAN_UNUSED(hash_name, pkcs_id, pkcs_id_len);
453#endif
454}
455}
#define BOTAN_UNUSED
Definition assert.h:144
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:1537
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:281
struct botan_asn1_oid_struct * botan_asn1_oid_t
Definition ffi.h:1121
struct botan_privkey_struct * botan_privkey_t
Definition ffi.h:1304
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:327
#define BOTAN_PRIVKEY_EXPORT_FLAG_RAW
Definition ffi.h:1399
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:183
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:205
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:215
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:255
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:178
struct botan_ec_group_struct * botan_ec_group_t
Definition ffi.h:1170
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:352
int(* botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t *data, size_t len)
Definition ffi.h:161
#define BOTAN_PRIVKEY_EXPORT_FLAG_PEM
Definition ffi.h:1398
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:188
#define BOTAN_CHECK_KEY_EXPENSIVE_TESTS
Definition ffi.h:1327
void * botan_view_ctx
Definition ffi.h:152
struct botan_rng_struct * botan_rng_t
Definition ffi.h:289
#define BOTAN_PRIVKEY_EXPORT_FLAG_DER
Definition ffi.h:1397
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:138
@ BOTAN_FFI_ERROR_UNKNOWN_ERROR
Definition ffi.h:146
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:131
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition ffi.h:119
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:132
@ BOTAN_FFI_SUCCESS
Definition ffi.h:115
@ BOTAN_FFI_ERROR_NO_VALUE
Definition ffi.h:121
int(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
Definition ffi.h:170
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:210
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:220
int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags)
Definition ffi_pkey.cpp:159
int botan_pubkey_fingerprint(botan_pubkey_t key, const char *hash_fn, uint8_t out[], size_t *out_len)
Definition ffi_pkey.cpp:437
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:86
int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t *estimate)
Definition ffi_pkey.cpp:433
int botan_pkcs_hash_id(const char *hash_name, uint8_t pkcs_id[], size_t *pkcs_id_len)
Definition ffi_pkey.cpp:444
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:255
int botan_pubkey_load(botan_pubkey_t *key, const uint8_t bits[], size_t bits_len)
Definition ffi_pkey.cpp:115
int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition ffi_pkey.cpp:193
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:281
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:230
int botan_pubkey_oid(botan_asn1_oid_t *oid, botan_pubkey_t key)
Definition ffi_pkey.cpp:377
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:327
int botan_privkey_destroy(botan_privkey_t key)
Definition ffi_pkey.cpp:111
int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t *out_len)
Definition ffi_pkey.cpp:147
int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:183
int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:205
int botan_privkey_stateful_operation(botan_privkey_t key, int *out)
Definition ffi_pkey.cpp:403
int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:215
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:60
int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:178
int botan_privkey_remaining_operations(botan_privkey_t key, uint64_t *out)
Definition ffi_pkey.cpp:418
int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t *out_len, uint32_t flags)
Definition ffi_pkey.cpp:166
int botan_privkey_oid(botan_asn1_oid_t *oid, botan_privkey_t key)
Definition ffi_pkey.cpp:390
int botan_pubkey_destroy(botan_pubkey_t key)
Definition ffi_pkey.cpp:131
int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t *out_len)
Definition ffi_pkey.cpp:143
int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition ffi_pkey.cpp:188
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:135
int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags)
Definition ffi_pkey.cpp:151
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:307
int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view)
Definition ffi_pkey.cpp:210
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:352
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:185
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:231
std::string PEM_encode(const Private_Key &key)
Definition pkcs8.cpp:116
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:278
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:201
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:244
std::unique_ptr< Private_Key > load_key(DataSource &source, const std::function< std::string()> &get_pass)
Definition pkcs8.cpp:314
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:187
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:211
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:178
int copy_view_str(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:217
int write_output(T out[], size_t *out_len, const T buf[], size_t buf_len)
Definition ffi_util.h:226
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:247
int write_str_output(char out[], size_t *out_len, const std::string &str)
Definition ffi_util.h:251
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