Botan 3.7.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:128
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:1687

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

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

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

354 {
355 return BOTAN_FFI_CHECKED_DELETE(op);
356}

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

345 {
346 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
347 const auto shared_key =
348 kem.decrypt(encapsulated_key, encapsulated_key_len, desired_shared_key_len, salt, salt_len);
349
350 return write_vec_output(shared_key_out, shared_key_len, shared_key);
351 });
352}

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

327 {
328 if(output_shared_key_length == nullptr) {
330 }
331
332 return BOTAN_FFI_VISIT(op, [=](auto& kem) {
333 *output_shared_key_length = kem.shared_key_length(desired_shared_key_length);
334 return BOTAN_FFI_SUCCESS;
335 });
336}

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

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

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

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

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

262 {
263 return BOTAN_FFI_CHECKED_DELETE(op);
264}

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

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

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

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

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

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

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

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

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

209 {
210 return BOTAN_FFI_CHECKED_DELETE(op);
211}

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

213 {
214 return copy_view_bin(out, out_len, botan_pk_op_key_agreement_view_public, key);
215}
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 227 of file ffi_pk_op.cpp.

227 {
228 return BOTAN_FFI_VISIT(op, [=](const auto& o) {
229 if(out_len == nullptr) {
231 }
232 *out_len = o.agreed_value_size();
233 return BOTAN_FFI_SUCCESS;
234 });
235}

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

217 {
218 return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int {
219 if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k)) {
220 return invoke_view_callback(view, ctx, kak->public_value());
221 } else {
223 }
224 });
225}
@ 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 });
190}
@ 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.