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