Botan 3.6.1
Crypto and TLS for C&
ffi_pk_op.cpp File Reference
#include <botan/ffi.h>
#include <botan/pubkey.h>
#include <botan/system_rng.h>
#include <botan/internal/ffi_pkey.h>
#include <botan/internal/ffi_rng.h>
#include <botan/internal/ffi_util.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 103 of file ffi_pk_op.cpp.

104 {
105 return BOTAN_FFI_VISIT(
106 op, [=](const auto& o) { return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len)); });
107}
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:124
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:201

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 71 of file ffi_pk_op.cpp.

74 {
75 if(op == nullptr) {
77 }
78
79 if(flags != 0) {
81 }
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:128
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:129
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:63
int ffi_guard_thunk(const char *func_name, const std::function< int()> &thunk)
Definition ffi.cpp:118
RandomNumberGenerator & system_rng()

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.

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

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 96 of file ffi_pk_op.cpp.

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

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 57 of file ffi_pk_op.cpp.

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

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 28 of file ffi_pk_op.cpp.

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

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 46 of file ffi_pk_op.cpp.

46 {
47 return BOTAN_FFI_CHECKED_DELETE(op);
48}

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 50 of file ffi_pk_op.cpp.

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

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 309 of file ffi_pk_op.cpp.

309 {
310 if(op == nullptr || padding == nullptr) {
312 }
313
314 return ffi_guard_thunk(__func__, [=]() -> int {
315 auto pk = std::make_unique<Botan::PK_KEM_Decryptor>(safe_get(key_obj), Botan::system_rng(), padding);
316 *op = new botan_pk_op_kem_decrypt_struct(std::move(pk));
317 return BOTAN_FFI_SUCCESS;
318 });
319}

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 350 of file ffi_pk_op.cpp.

350 {
351 return BOTAN_FFI_CHECKED_DELETE(op);
352}

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 334 of file ffi_pk_op.cpp.

341 {
342 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
343 const auto shared_key =
344 kem.decrypt(encapsulated_key, encapsulated_key_len, desired_shared_key_len, salt, salt_len);
345
346 return write_vec_output(shared_key_out, shared_key_len, shared_key);
347 });
348}

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 321 of file ffi_pk_op.cpp.

323 {
324 if(output_shared_key_length == nullptr) {
326 }
327
328 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
329 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
330 return BOTAN_FFI_SUCCESS;
331 });
332}

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 247 of file ffi_pk_op.cpp.

247 {
248 if(op == nullptr || padding == nullptr) {
250 }
251
252 return ffi_guard_thunk(__func__, [=]() -> int {
253 auto pk = std::make_unique<Botan::PK_KEM_Encryptor>(safe_get(key_obj), padding);
254 *op = new botan_pk_op_kem_encrypt_struct(std::move(pk));
255 return BOTAN_FFI_SUCCESS;
256 });
257}

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 288 of file ffi_pk_op.cpp.

296 {
297 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
298 const auto result = kem.encrypt(safe_get(rng), desired_shared_key_len, {salt, salt_len});
299
300 int rc = write_vec_output(encapsulated_key_out, encapsulated_key_len, result.encapsulated_shared_key());
301
302 if(rc != 0)
303 return rc;
304
305 return write_vec_output(shared_key_out, shared_key_len, result.shared_key());
306 });
307}

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 259 of file ffi_pk_op.cpp.

259 {
260 return BOTAN_FFI_CHECKED_DELETE(op);
261}

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 276 of file ffi_pk_op.cpp.

277 {
278 if(output_encapsulated_key_length == nullptr) {
280 }
281
282 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
283 *output_encapsulated_key_length = kem.encapsulated_key_length();
284 return BOTAN_FFI_SUCCESS;
285 });
286}

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 263 of file ffi_pk_op.cpp.

265 {
266 if(output_shared_key_length == nullptr) {
268 }
269
270 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
271 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
272 return BOTAN_FFI_SUCCESS;
273 });
274}

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 234 of file ffi_pk_op.cpp.

240 {
241 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
242 auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
243 return write_vec_output(out, out_len, k);
244 });
245}

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 191 of file ffi_pk_op.cpp.

191 {
192 if(op == nullptr) {
194 }
195
196 if(flags != 0) {
198 }
199
200 return ffi_guard_thunk(__func__, [=]() -> int {
201 *op = nullptr;
202 auto pk = std::make_unique<Botan::PK_Key_Agreement>(safe_get(key_obj), Botan::system_rng(), kdf);
203 *op = new botan_pk_op_ka_struct(std::move(pk));
204 return BOTAN_FFI_SUCCESS;
205 });
206}

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 208 of file ffi_pk_op.cpp.

208 {
209 return BOTAN_FFI_CHECKED_DELETE(op);
210}

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 212 of file ffi_pk_op.cpp.

212 {
213 return copy_view_bin(out, out_len, botan_pk_op_key_agreement_view_public, key);
214}
int botan_pk_op_key_agreement_view_public(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view)
int copy_view_bin(uint8_t out[], size_t *out_len, Fn fn, Args... args)
Definition ffi_util.h:163

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 225 of file ffi_pk_op.cpp.

225 {
226 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
227 if(out_len == nullptr)
229 *out_len = o.agreed_value_size();
230 return BOTAN_FFI_SUCCESS;
231 });
232}

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 216 of file ffi_pk_op.cpp.

216 {
217 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
218 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
219 return invoke_view_callback(view, ctx, kak->public_value());
220 else
222 });
223}
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition ffi.h:117
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, const std::vector< uint8_t, Alloc > &buf)
Definition ffi_util.h:146

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 112 of file ffi_pk_op.cpp.

112 {
113 if(op == nullptr) {
115 }
116
117 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
119 }
120
121 return ffi_guard_thunk(__func__, [=]() -> int {
122 *op = nullptr;
123
126
127 auto pk = std::make_unique<Botan::PK_Signer>(safe_get(key_obj), Botan::system_rng(), hash, format);
128 *op = new botan_pk_op_sign_struct(std::move(pk));
129 return BOTAN_FFI_SUCCESS;
130 });
131}
Flags flags(Flag flags)
Definition p11.h:838
Signature_Format
Definition pk_keys.h:31

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 133 of file ffi_pk_op.cpp.

133 {
134 return BOTAN_FFI_CHECKED_DELETE(op);
135}

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 149 of file ffi_pk_op.cpp.

149 {
150 return BOTAN_FFI_VISIT(op, [=](auto& o) { return write_vec_output(out, out_len, o.signature(safe_get(rng_obj))); });
151}

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 137 of file ffi_pk_op.cpp.

137 {
138 if(sig_len == nullptr) {
140 }
141
142 return BOTAN_FFI_VISIT(op, [=](const auto& o) { *sig_len = o.signature_length(); });
143}

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 145 of file ffi_pk_op.cpp.

145 {
146 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
147}

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 153 of file ffi_pk_op.cpp.

153 {
154 if(op == nullptr) {
156 }
157
158 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
160 }
161
162 return ffi_guard_thunk(__func__, [=]() -> int {
163 *op = nullptr;
166 auto pk = std::make_unique<Botan::PK_Verifier>(safe_get(key_obj), hash, format);
167 *op = new botan_pk_op_verify_struct(std::move(pk));
168 return BOTAN_FFI_SUCCESS;
169 });
170}

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 172 of file ffi_pk_op.cpp.

172 {
173 return BOTAN_FFI_CHECKED_DELETE(op);
174}

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 180 of file ffi_pk_op.cpp.

180 {
181 return BOTAN_FFI_VISIT(op, [=](auto& o) {
182 const bool legit = o.check_signature(sig, sig_len);
183
184 if(legit)
185 return BOTAN_FFI_SUCCESS;
186 else
188 });
189}
@ BOTAN_FFI_INVALID_VERIFIER
Definition ffi.h:115

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 176 of file ffi_pk_op.cpp.

176 {
177 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
178}

References BOTAN_FFI_VISIT.