Botan 3.0.0
Crypto and TLS for C&
Functions
ffi_pk_op.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_util.h>
#include <botan/internal/ffi_pkey.h>
#include <botan/internal/ffi_rng.h>
#include <botan/pubkey.h>
#include <botan/system_rng.h>

Go to the source code of this file.

Functions

 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_decrypt_struct, Botan::PK_Decryptor, 0x912F3C37)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_encrypt_struct, Botan::PK_Encryptor, 0x891F3FC3)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_ka_struct, Botan::PK_Key_Agreement, 0x2939CAB1)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_kem_decrypt_struct, Botan::PK_KEM_Decryptor, 0x1743D8E6)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_kem_encrypt_struct, Botan::PK_KEM_Encryptor, 0x1D13A446)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_sign_struct, Botan::PK_Signer, 0x1AF0C39F)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_verify_struct, Botan::PK_Verifier, 0x2B91F936)
 
int botan_pk_op_decrypt (botan_pk_op_decrypt_t op, uint8_t out[], size_t *out_len, const uint8_t ciphertext[], size_t ciphertext_len)
 
int botan_pk_op_decrypt_create (botan_pk_op_decrypt_t *op, botan_privkey_t key_obj, const char *padding, uint32_t flags)
 
int botan_pk_op_decrypt_destroy (botan_pk_op_decrypt_t op)
 
int botan_pk_op_decrypt_output_length (botan_pk_op_decrypt_t op, size_t ctext_len, size_t *ptext_len)
 
int botan_pk_op_encrypt (botan_pk_op_encrypt_t op, botan_rng_t rng_obj, uint8_t out[], size_t *out_len, const uint8_t plaintext[], size_t plaintext_len)
 
int botan_pk_op_encrypt_create (botan_pk_op_encrypt_t *op, botan_pubkey_t key_obj, const char *padding, uint32_t flags)
 
int botan_pk_op_encrypt_destroy (botan_pk_op_encrypt_t op)
 
int botan_pk_op_encrypt_output_length (botan_pk_op_encrypt_t op, size_t ptext_len, size_t *ctext_len)
 
int botan_pk_op_kem_decrypt_create (botan_pk_op_kem_decrypt_t *op, botan_privkey_t key_obj, const char *padding)
 
int botan_pk_op_kem_decrypt_destroy (botan_pk_op_kem_decrypt_t op)
 
int botan_pk_op_kem_decrypt_shared_key (botan_pk_op_kem_decrypt_t op, const uint8_t salt[], size_t salt_len, const uint8_t encapsulated_key[], size_t encapsulated_key_len, size_t desired_shared_key_len, uint8_t shared_key_out[], size_t *shared_key_len)
 
int botan_pk_op_kem_decrypt_shared_key_length (botan_pk_op_kem_decrypt_t op, size_t desired_shared_key_length, size_t *output_shared_key_length)
 
int botan_pk_op_kem_encrypt_create (botan_pk_op_kem_encrypt_t *op, botan_pubkey_t key_obj, const char *padding)
 
int botan_pk_op_kem_encrypt_create_shared_key (botan_pk_op_kem_encrypt_t op, botan_rng_t rng, const uint8_t salt[], size_t salt_len, size_t desired_shared_key_len, uint8_t shared_key_out[], size_t *shared_key_len, uint8_t encapsulated_key_out[], size_t *encapsulated_key_len)
 
int botan_pk_op_kem_encrypt_destroy (botan_pk_op_kem_encrypt_t op)
 
int botan_pk_op_kem_encrypt_encapsulated_key_length (botan_pk_op_kem_encrypt_t op, size_t *output_encapsulated_key_length)
 
int botan_pk_op_kem_encrypt_shared_key_length (botan_pk_op_kem_encrypt_t op, size_t desired_shared_key_length, size_t *output_shared_key_length)
 
int botan_pk_op_key_agreement (botan_pk_op_ka_t op, uint8_t out[], size_t *out_len, const uint8_t other_key[], size_t other_key_len, const uint8_t salt[], size_t salt_len)
 
int botan_pk_op_key_agreement_create (botan_pk_op_ka_t *op, botan_privkey_t key_obj, const char *kdf, uint32_t flags)
 
int botan_pk_op_key_agreement_destroy (botan_pk_op_ka_t op)
 
int botan_pk_op_key_agreement_export_public (botan_privkey_t key, uint8_t out[], size_t *out_len)
 
int botan_pk_op_key_agreement_size (botan_pk_op_ka_t op, size_t *out_len)
 
int botan_pk_op_key_agreement_view_public (botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
 
int botan_pk_op_sign_create (botan_pk_op_sign_t *op, botan_privkey_t key_obj, const char *hash, uint32_t flags)
 
int botan_pk_op_sign_destroy (botan_pk_op_sign_t op)
 
int botan_pk_op_sign_finish (botan_pk_op_sign_t op, botan_rng_t rng_obj, uint8_t out[], size_t *out_len)
 
int botan_pk_op_sign_output_length (botan_pk_op_sign_t op, size_t *sig_len)
 
int botan_pk_op_sign_update (botan_pk_op_sign_t op, const uint8_t in[], size_t in_len)
 
int botan_pk_op_verify_create (botan_pk_op_verify_t *op, botan_pubkey_t key_obj, const char *hash, uint32_t flags)
 
int botan_pk_op_verify_destroy (botan_pk_op_verify_t op)
 
int botan_pk_op_verify_finish (botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len)
 
int botan_pk_op_verify_update (botan_pk_op_verify_t op, const uint8_t in[], size_t in_len)
 

Function Documentation

◆ BOTAN_FFI_DECLARE_STRUCT() [1/7]

BOTAN_FFI_DECLARE_STRUCT ( botan_pk_op_decrypt_struct  ,
Botan::PK_Decryptor  ,
0x912F3C37   
)

◆ BOTAN_FFI_DECLARE_STRUCT() [2/7]

BOTAN_FFI_DECLARE_STRUCT ( botan_pk_op_encrypt_struct  ,
Botan::PK_Encryptor  ,
0x891F3FC3   
)

◆ BOTAN_FFI_DECLARE_STRUCT() [3/7]

BOTAN_FFI_DECLARE_STRUCT ( botan_pk_op_ka_struct  ,
Botan::PK_Key_Agreement  ,
0x2939CAB1   
)

◆ BOTAN_FFI_DECLARE_STRUCT() [4/7]

BOTAN_FFI_DECLARE_STRUCT ( botan_pk_op_kem_decrypt_struct  ,
Botan::PK_KEM_Decryptor  ,
0x1743D8E6   
)

◆ BOTAN_FFI_DECLARE_STRUCT() [5/7]

BOTAN_FFI_DECLARE_STRUCT ( botan_pk_op_kem_encrypt_struct  ,
Botan::PK_KEM_Encryptor  ,
0x1D13A446   
)

◆ BOTAN_FFI_DECLARE_STRUCT() [6/7]

BOTAN_FFI_DECLARE_STRUCT ( botan_pk_op_sign_struct  ,
Botan::PK_Signer  ,
0x1AF0C39F   
)

◆ BOTAN_FFI_DECLARE_STRUCT() [7/7]

BOTAN_FFI_DECLARE_STRUCT ( botan_pk_op_verify_struct  ,
Botan::PK_Verifier  ,
0x2B91F936   
)

◆ botan_pk_op_decrypt()

int botan_pk_op_decrypt ( botan_pk_op_decrypt_t  op,
uint8_t  out[],
size_t *  out_len,
const uint8_t  ciphertext[],
size_t  ciphertext_len 
)

Definition at line 104 of file ffi_pk_op.cpp.

107 {
108 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
109 return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
110 });
111 }
#define BOTAN_FFI_VISIT(obj, lambda)
Definition: ffi_util.h:126
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:214

References BOTAN_FFI_VISIT, and Botan_FFI::write_vec_output().

◆ botan_pk_op_decrypt_create()

int botan_pk_op_decrypt_create ( botan_pk_op_decrypt_t op,
botan_privkey_t  key_obj,
const char *  padding,
uint32_t  flags 
)

Definition at line 72 of file ffi_pk_op.cpp.

76 {
77 if(op == nullptr)
79
80 if(flags != 0)
82
83 return ffi_guard_thunk(__func__, [=]() -> int {
84 *op = nullptr;
85
86 auto pk = std::make_unique<Botan::PK_Decryptor_EME>(safe_get(key_obj), Botan::system_rng(), padding);
87 *op = new botan_pk_op_decrypt_struct(std::move(pk));
88 return BOTAN_FFI_SUCCESS;
89 });
90 }
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:84
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:85
@ BOTAN_FFI_SUCCESS
Definition: ffi.h:70
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:69
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition: ffi.cpp:120
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:376

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_decrypt_destroy()

int botan_pk_op_decrypt_destroy ( botan_pk_op_decrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 92 of file ffi_pk_op.cpp.

93 {
94 return BOTAN_FFI_CHECKED_DELETE(op);
95 }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:145

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_decrypt_output_length()

int botan_pk_op_decrypt_output_length ( botan_pk_op_decrypt_t  op,
size_t  ctext_len,
size_t *  ptext_len 
)

Definition at line 97 of file ffi_pk_op.cpp.

98 {
99 if(ptext_len == nullptr)
101 return BOTAN_FFI_VISIT(op, [=](const auto& o) { *ptext_len = o.plaintext_length(ctext_len); });
102 }

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_pk_op_encrypt()

int botan_pk_op_encrypt ( botan_pk_op_encrypt_t  op,
botan_rng_t  rng_obj,
uint8_t  out[],
size_t *  out_len,
const uint8_t  plaintext[],
size_t  plaintext_len 
)

Definition at line 59 of file ffi_pk_op.cpp.

63 {
64 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
65 return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
66 });
67 }

References BOTAN_FFI_VISIT, Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

◆ botan_pk_op_encrypt_create()

int botan_pk_op_encrypt_create ( botan_pk_op_encrypt_t op,
botan_pubkey_t  key_obj,
const char *  padding,
uint32_t  flags 
)

Definition at line 27 of file ffi_pk_op.cpp.

31 {
32 if(op == nullptr)
34
35 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE)
37
38 return ffi_guard_thunk(__func__, [=]() -> int {
39 *op = nullptr;
40
41 auto pk = std::make_unique<Botan::PK_Encryptor_EME>(safe_get(key_obj), Botan::system_rng(), padding);
42 *op = new botan_pk_op_encrypt_struct(std::move(pk));
43 return BOTAN_FFI_SUCCESS;
44 });
45 }
#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE
Definition: ffi.h:1592

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_encrypt_destroy()

int botan_pk_op_encrypt_destroy ( botan_pk_op_encrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 47 of file ffi_pk_op.cpp.

48 {
49 return BOTAN_FFI_CHECKED_DELETE(op);
50 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_encrypt_output_length()

int botan_pk_op_encrypt_output_length ( botan_pk_op_encrypt_t  op,
size_t  ptext_len,
size_t *  ctext_len 
)

Definition at line 52 of file ffi_pk_op.cpp.

53 {
54 if(ctext_len == nullptr)
56 return BOTAN_FFI_VISIT(op, [=](const auto& o) { *ctext_len = o.ciphertext_length(ptext_len); });
57 }

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_pk_op_kem_decrypt_create()

int botan_pk_op_kem_decrypt_create ( botan_pk_op_kem_decrypt_t op,
botan_privkey_t  key_obj,
const char *  padding 
)

Definition at line 348 of file ffi_pk_op.cpp.

351 {
352 if(op == nullptr || padding == nullptr)
354
355 return ffi_guard_thunk(__func__, [=]() -> int {
356 auto pk = std::make_unique<Botan::PK_KEM_Decryptor>(safe_get(key_obj), Botan::system_rng(), padding);
357 *op = new botan_pk_op_kem_decrypt_struct(std::move(pk));
358 return BOTAN_FFI_SUCCESS;
359 });
360 }

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_kem_decrypt_destroy()

int botan_pk_op_kem_decrypt_destroy ( botan_pk_op_kem_decrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 399 of file ffi_pk_op.cpp.

400 {
401 return BOTAN_FFI_CHECKED_DELETE(op);
402 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_kem_decrypt_shared_key()

int botan_pk_op_kem_decrypt_shared_key ( botan_pk_op_kem_decrypt_t  op,
const uint8_t  salt[],
size_t  salt_len,
const uint8_t  encapsulated_key[],
size_t  encapsulated_key_len,
size_t  desired_shared_key_len,
uint8_t  shared_key_out[],
size_t *  shared_key_len 
)

Definition at line 376 of file ffi_pk_op.cpp.

385 {
386 return BOTAN_FFI_VISIT(op, [=](auto& kem)
387 {
388 const auto shared_key =
389 kem.decrypt(encapsulated_key,
390 encapsulated_key_len,
391 desired_shared_key_len,
392 salt,
393 salt_len);
394
395 write_vec_output(shared_key_out, shared_key_len, shared_key);
396 });
397 }

References BOTAN_FFI_VISIT, and Botan_FFI::write_vec_output().

◆ botan_pk_op_kem_decrypt_shared_key_length()

int botan_pk_op_kem_decrypt_shared_key_length ( botan_pk_op_kem_decrypt_t  op,
size_t  desired_shared_key_length,
size_t *  output_shared_key_length 
)

Definition at line 362 of file ffi_pk_op.cpp.

365 {
366 if(output_shared_key_length == nullptr)
368
369 return BOTAN_FFI_VISIT(op, [=](auto& kem)
370 {
371 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
372 return BOTAN_FFI_SUCCESS;
373 });
374 }

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_kem_encrypt_create()

int botan_pk_op_kem_encrypt_create ( botan_pk_op_kem_encrypt_t op,
botan_pubkey_t  key_obj,
const char *  padding 
)

Definition at line 269 of file ffi_pk_op.cpp.

272 {
273 if(op == nullptr || padding == nullptr)
275
276 return ffi_guard_thunk(__func__, [=]() -> int {
277 auto pk = std::make_unique<Botan::PK_KEM_Encryptor>(safe_get(key_obj), padding);
278 *op = new botan_pk_op_kem_encrypt_struct(std::move(pk));
279 return BOTAN_FFI_SUCCESS;
280 });
281 }

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_pk_op_kem_encrypt_create_shared_key()

int botan_pk_op_kem_encrypt_create_shared_key ( botan_pk_op_kem_encrypt_t  op,
botan_rng_t  rng,
const uint8_t  salt[],
size_t  salt_len,
size_t  desired_shared_key_len,
uint8_t  shared_key_out[],
size_t *  shared_key_len,
uint8_t  encapsulated_key_out[],
size_t *  encapsulated_key_len 
)

Definition at line 315 of file ffi_pk_op.cpp.

325 {
326 return BOTAN_FFI_VISIT(op, [=](auto& kem)
327 {
328 Botan::secure_vector<uint8_t> encapsulated_key;
330
331 kem.encrypt(encapsulated_key, shared_key,
332 desired_shared_key_len,
333 safe_get(rng),
334 salt,
335 salt_len);
336
337 int rc = write_vec_output(encapsulated_key_out,
338 encapsulated_key_len,
339 encapsulated_key);
340
341 if(rc != 0)
342 return rc;
343
344 return write_vec_output(shared_key_out, shared_key_len, shared_key);
345 });
346 }
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64

References BOTAN_FFI_VISIT, Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

◆ botan_pk_op_kem_encrypt_destroy()

int botan_pk_op_kem_encrypt_destroy ( botan_pk_op_kem_encrypt_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 283 of file ffi_pk_op.cpp.

284 {
285 return BOTAN_FFI_CHECKED_DELETE(op);
286 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_kem_encrypt_encapsulated_key_length()

int botan_pk_op_kem_encrypt_encapsulated_key_length ( botan_pk_op_kem_encrypt_t  op,
size_t *  output_encapsulated_key_length 
)

Definition at line 302 of file ffi_pk_op.cpp.

304 {
305 if(output_encapsulated_key_length == nullptr)
307
308 return BOTAN_FFI_VISIT(op, [=](auto& kem)
309 {
310 *output_encapsulated_key_length = kem.encapsulated_key_length();
311 return BOTAN_FFI_SUCCESS;
312 });
313 }

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_kem_encrypt_shared_key_length()

int botan_pk_op_kem_encrypt_shared_key_length ( botan_pk_op_kem_encrypt_t  op,
size_t  desired_shared_key_length,
size_t *  output_shared_key_length 
)

Definition at line 288 of file ffi_pk_op.cpp.

291 {
292 if(output_shared_key_length == nullptr)
294
295 return BOTAN_FFI_VISIT(op, [=](auto& kem)
296 {
297 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
298 return BOTAN_FFI_SUCCESS;
299 });
300 }

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_key_agreement()

int botan_pk_op_key_agreement ( botan_pk_op_ka_t  op,
uint8_t  out[],
size_t *  out_len,
const uint8_t  other_key[],
size_t  other_key_len,
const uint8_t  salt[],
size_t  salt_len 
)

Definition at line 258 of file ffi_pk_op.cpp.

262 {
263 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
264 auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
265 return write_vec_output(out, out_len, k);
266 });
267 }

References BOTAN_FFI_VISIT, and Botan_FFI::write_vec_output().

◆ botan_pk_op_key_agreement_create()

int botan_pk_op_key_agreement_create ( botan_pk_op_ka_t op,
botan_privkey_t  key_obj,
const char *  kdf,
uint32_t  flags 
)

Definition at line 205 of file ffi_pk_op.cpp.

209 {
210 if(op == nullptr)
212
213 if(flags != 0)
215
216 return ffi_guard_thunk(__func__, [=]() -> int {
217 *op = nullptr;
218 auto pk = std::make_unique<Botan::PK_Key_Agreement>(safe_get(key_obj), Botan::system_rng(), kdf);
219 *op = new botan_pk_op_ka_struct(std::move(pk));
220 return BOTAN_FFI_SUCCESS;
221 });
222 }

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

◆ botan_pk_op_key_agreement_destroy()

int botan_pk_op_key_agreement_destroy ( botan_pk_op_ka_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 224 of file ffi_pk_op.cpp.

225 {
226 return BOTAN_FFI_CHECKED_DELETE(op);
227 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_key_agreement_export_public()

int botan_pk_op_key_agreement_export_public ( botan_privkey_t  key,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 229 of file ffi_pk_op.cpp.

231 {
232 return copy_view_bin(out, out_len, botan_pk_op_key_agreement_view_public, key);
233 }
int botan_pk_op_key_agreement_view_public(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
Definition: ffi_pk_op.cpp:235
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition: ffi_util.h:171

References botan_pk_op_key_agreement_view_public(), and Botan_FFI::copy_view_bin().

◆ botan_pk_op_key_agreement_size()

int botan_pk_op_key_agreement_size ( botan_pk_op_ka_t  op,
size_t *  out_len 
)

Definition at line 248 of file ffi_pk_op.cpp.

249 {
250 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
251 if(out_len == nullptr)
253 *out_len = o.agreed_value_size();
254 return BOTAN_FFI_SUCCESS;
255 });
256 }

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_key_agreement_view_public()

int botan_pk_op_key_agreement_view_public ( botan_privkey_t  key,
botan_view_ctx  ctx,
botan_view_bin_fn  view 
)

Definition at line 235 of file ffi_pk_op.cpp.

239 {
240 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
241 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
242 return invoke_view_callback(view, ctx, kak->public_value());
243 else
245 });
246 }
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition: ffi.h:73
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:148

References BOTAN_FFI_ERROR_INVALID_INPUT, BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

Referenced by botan_pk_op_key_agreement_export_public().

◆ botan_pk_op_sign_create()

int botan_pk_op_sign_create ( botan_pk_op_sign_t op,
botan_privkey_t  key_obj,
const char *  hash,
uint32_t  flags 
)

Definition at line 116 of file ffi_pk_op.cpp.

120 {
121 if(op == nullptr)
123
124 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE)
126
127 return ffi_guard_thunk(__func__, [=]() -> int {
128 *op = nullptr;
129
131
132 auto pk = std::make_unique<Botan::PK_Signer>(safe_get(key_obj), Botan::system_rng(), hash, format);
133 *op = new botan_pk_op_sign_struct(std::move(pk));
134 return BOTAN_FFI_SUCCESS;
135 });
136 }
Flags flags(Flag flags)
Definition: p11.h:860

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DerSequence, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::Standard, and Botan::system_rng().

◆ botan_pk_op_sign_destroy()

int botan_pk_op_sign_destroy ( botan_pk_op_sign_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 138 of file ffi_pk_op.cpp.

139 {
140 return BOTAN_FFI_CHECKED_DELETE(op);
141 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_sign_finish()

int botan_pk_op_sign_finish ( botan_pk_op_sign_t  op,
botan_rng_t  rng_obj,
uint8_t  out[],
size_t *  out_len 
)

Definition at line 156 of file ffi_pk_op.cpp.

157 {
158 return BOTAN_FFI_VISIT(op, [=](auto& o) {
159 return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
160 });
161 }

References BOTAN_FFI_VISIT, Botan_FFI::safe_get(), and Botan_FFI::write_vec_output().

◆ botan_pk_op_sign_output_length()

int botan_pk_op_sign_output_length ( botan_pk_op_sign_t  op,
size_t *  sig_len 
)

Definition at line 143 of file ffi_pk_op.cpp.

144 {
145 if(sig_len == nullptr)
147
148 return BOTAN_FFI_VISIT(op, [=](const auto& o) { *sig_len = o.signature_length(); });
149 }

References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.

◆ botan_pk_op_sign_update()

int botan_pk_op_sign_update ( botan_pk_op_sign_t  op,
const uint8_t  in[],
size_t  in_len 
)

Definition at line 151 of file ffi_pk_op.cpp.

152 {
153 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
154 }

References BOTAN_FFI_VISIT.

◆ botan_pk_op_verify_create()

int botan_pk_op_verify_create ( botan_pk_op_verify_t op,
botan_pubkey_t  key_obj,
const char *  hash,
uint32_t  flags 
)

Definition at line 163 of file ffi_pk_op.cpp.

167 {
168 if(op == nullptr)
170
171 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE)
173
174 return ffi_guard_thunk(__func__, [=]() -> int {
175 *op = nullptr;
177 auto pk = std::make_unique<Botan::PK_Verifier>(safe_get(key_obj), hash, format);
178 *op = new botan_pk_op_verify_struct(std::move(pk));
179 return BOTAN_FFI_SUCCESS;
180 });
181 }

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DerSequence, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::Standard.

◆ botan_pk_op_verify_destroy()

int botan_pk_op_verify_destroy ( botan_pk_op_verify_t  op)
Returns
0 if success, error if invalid object handle

Definition at line 183 of file ffi_pk_op.cpp.

184 {
185 return BOTAN_FFI_CHECKED_DELETE(op);
186 }

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_pk_op_verify_finish()

int botan_pk_op_verify_finish ( botan_pk_op_verify_t  op,
const uint8_t  sig[],
size_t  sig_len 
)

Definition at line 193 of file ffi_pk_op.cpp.

194 {
195 return BOTAN_FFI_VISIT(op, [=](auto& o) {
196 const bool legit = o.check_signature(sig, sig_len);
197
198 if(legit)
199 return BOTAN_FFI_SUCCESS;
200 else
202 });
203 }
@ BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:71

References BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_SUCCESS, and BOTAN_FFI_VISIT.

◆ botan_pk_op_verify_update()

int botan_pk_op_verify_update ( botan_pk_op_verify_t  op,
const uint8_t  in[],
size_t  in_len 
)

Definition at line 188 of file ffi_pk_op.cpp.

189 {
190 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
191 }

References BOTAN_FFI_VISIT.