Botan 3.9.0
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 101 of file ffi_pk_op.cpp.

102 {
103 return BOTAN_FFI_VISIT(
104 op, [=](const auto& o) { return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len)); });
105}
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158
int write_vec_output(uint8_t out[], size_t *out_len, std::span< const uint8_t > buf)
Definition ffi_util.h:247

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

73 {
74 if(op == nullptr) {
76 }
77
78 if(flags != 0) {
80 }
81
82 return ffi_guard_thunk(__func__, [=]() -> int {
83 *op = nullptr;
84
85 auto pk = std::make_unique<Botan::PK_Decryptor_EME>(safe_get(key_obj), Botan::system_rng(), padding);
86 return ffi_new_object(op, std::move(pk));
87 });
88}
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:131
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:132
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 ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95
RandomNumberGenerator & system_rng()

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 90 of file ffi_pk_op.cpp.

90 {
91 return BOTAN_FFI_CHECKED_DELETE(op);
92}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:185

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

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

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

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

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 return ffi_new_object(op, std::move(pk));
42 });
43}
#define BOTAN_PUBKEY_DER_FORMAT_SIGNATURE
Definition ffi.h:1943

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 45 of file ffi_pk_op.cpp.

45 {
46 return BOTAN_FFI_CHECKED_DELETE(op);
47}

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

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

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

307 {
308 if(op == nullptr || padding == nullptr) {
310 }
311
312 return ffi_guard_thunk(__func__, [=]() -> int {
313 auto pk = std::make_unique<Botan::PK_KEM_Decryptor>(safe_get(key_obj), Botan::system_rng(), padding);
314 return ffi_new_object(op, std::move(pk));
315 });
316}

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 347 of file ffi_pk_op.cpp.

347 {
348 return BOTAN_FFI_CHECKED_DELETE(op);
349}

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

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

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

320 {
321 if(output_shared_key_length == nullptr) {
323 }
324
325 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
326 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
327 return BOTAN_FFI_SUCCESS;
328 });
329}
@ BOTAN_FFI_SUCCESS
Definition ffi.h:115

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

245 {
246 if(op == nullptr || padding == nullptr) {
248 }
249
250 return ffi_guard_thunk(__func__, [=]() -> int {
251 auto pk = std::make_unique<Botan::PK_KEM_Encryptor>(safe_get(key_obj), padding);
252 return ffi_new_object(op, std::move(pk));
253 });
254}

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 285 of file ffi_pk_op.cpp.

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

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

256 {
257 return BOTAN_FFI_CHECKED_DELETE(op);
258}

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

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

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

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

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

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

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

188 {
189 if(op == nullptr) {
191 }
192
193 if(flags != 0) {
195 }
196
197 return ffi_guard_thunk(__func__, [=]() -> int {
198 *op = nullptr;
199 auto pk = std::make_unique<Botan::PK_Key_Agreement>(safe_get(key_obj), Botan::system_rng(), kdf);
200 return ffi_new_object(op, std::move(pk));
201 });
202}

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 204 of file ffi_pk_op.cpp.

204 {
205 return BOTAN_FFI_CHECKED_DELETE(op);
206}

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

208 {
209 return copy_view_bin(out, out_len, botan_pk_op_key_agreement_view_public, key);
210}
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:211

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

222 {
223 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
224 if(out_len == nullptr) {
226 }
227 *out_len = o.agreed_value_size();
228 return BOTAN_FFI_SUCCESS;
229 });
230}

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

212 {
213 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
214 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k)) {
215 return invoke_view_callback(view, ctx, kak->public_value());
216 } else {
218 }
219 });
220}
@ BOTAN_FFI_ERROR_INVALID_INPUT
Definition ffi.h:119
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:187

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

110 {
111 if(op == nullptr) {
113 }
114
115 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
117 }
118
119 return ffi_guard_thunk(__func__, [=]() -> int {
120 *op = nullptr;
121
122 const bool use_der = (flags & BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) != 0;
124
125 auto pk = std::make_unique<Botan::PK_Signer>(safe_get(key_obj), Botan::system_rng(), hash, format);
126 return ffi_new_object(op, std::move(pk));
127 });
128}
Flags flags(Flag flags)
Definition p11.h:848

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DerSequence, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 130 of file ffi_pk_op.cpp.

130 {
131 return BOTAN_FFI_CHECKED_DELETE(op);
132}

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

146 {
147 return BOTAN_FFI_VISIT(op, [=](auto& o) { return write_vec_output(out, out_len, o.signature(safe_get(rng_obj))); });
148}

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

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

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

142 {
143 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
144}

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

150 {
151 if(op == nullptr) {
153 }
154
155 if(flags != 0 && flags != BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) {
157 }
158
159 return ffi_guard_thunk(__func__, [=]() -> int {
160 *op = nullptr;
161 const bool use_der = (flags & BOTAN_PUBKEY_DER_FORMAT_SIGNATURE) != 0;
163 auto pk = std::make_unique<Botan::PK_Verifier>(safe_get(key_obj), hash, format);
164 return ffi_new_object(op, std::move(pk));
165 });
166}

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_PUBKEY_DER_FORMAT_SIGNATURE, Botan::DerSequence, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), 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 168 of file ffi_pk_op.cpp.

168 {
169 return BOTAN_FFI_CHECKED_DELETE(op);
170}

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

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

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

172 {
173 return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); });
174}

References BOTAN_FFI_VISIT.