Botan  2.8.0
Crypto and TLS for C++11
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>

Go to the source code of this file.

Functions

 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_encrypt_struct, Botan::PK_Encryptor, 0x891F3FC3)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_decrypt_struct, Botan::PK_Decryptor, 0x912F3C37)
 
 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)
 
 BOTAN_FFI_DECLARE_STRUCT (botan_pk_op_ka_struct, Botan::PK_Key_Agreement, 0x2939CAB1)
 
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_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_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/5]

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

◆ BOTAN_FFI_DECLARE_STRUCT() [2/5]

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

◆ BOTAN_FFI_DECLARE_STRUCT() [3/5]

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

◆ BOTAN_FFI_DECLARE_STRUCT() [4/5]

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

◆ BOTAN_FFI_DECLARE_STRUCT() [5/5]

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

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

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

103  {
104  return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, {
105  return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
106  });
107  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:140
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

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

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

72  {
73  if(op == nullptr)
75 
76  if(flags != 0)
78 
79  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
80  *op = nullptr;
81 
82  std::unique_ptr<Botan::PK_Decryptor> pk(new Botan::PK_Decryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
83  *op = new botan_pk_op_decrypt_struct(pk.release());
84  return BOTAN_FFI_SUCCESS;
85  });
86  }
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:28
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Flags flags(Flag flags)
Definition: p11.h:858
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:59
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pk_op_decrypt_destroy()

int botan_pk_op_decrypt_destroy ( botan_pk_op_decrypt_t  op)

Definition at line 88 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

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

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

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::PK_Decryptor::plaintext_length().

94  {
95  if(ptext_len == nullptr)
97  return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, { *ptext_len = o.plaintext_length(ctext_len); });
98  }
virtual size_t plaintext_length(size_t ctext_len) const =0
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

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

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

59  {
60  return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, {
61  return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
62  });
63  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:140
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:59
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

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

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

27  {
28  if(op == nullptr)
30 
31  if(flags != 0)
33 
34  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
35  *op = nullptr;
36 
37  std::unique_ptr<Botan::PK_Encryptor> pk(new Botan::PK_Encryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
38  *op = new botan_pk_op_encrypt_struct(pk.release());
39  return BOTAN_FFI_SUCCESS;
40  });
41  }
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:28
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Flags flags(Flag flags)
Definition: p11.h:858
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:59
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pk_op_encrypt_destroy()

int botan_pk_op_encrypt_destroy ( botan_pk_op_encrypt_t  op)

Definition at line 43 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

44  {
45  return BOTAN_FFI_CHECKED_DELETE(op);
46  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:114

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

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::PK_Encryptor::ciphertext_length().

49  {
50  if(ctext_len == nullptr)
52  return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, { *ctext_len = o.ciphertext_length(ptext_len); });
53  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86
virtual size_t ciphertext_length(size_t ctext_len) const =0

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

References Botan::OctetString::bits_of(), BOTAN_FFI_DO, Botan::PK_Key_Agreement::derive_key(), salt_len, and Botan_FFI::write_vec_output().

245  {
246  return BOTAN_FFI_DO(Botan::PK_Key_Agreement, op, o, {
247  auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
248  return write_vec_output(out, out_len, k);
249  });
250  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:140
size_t salt_len
Definition: x509_obj.cpp:26
SymmetricKey derive_key(size_t key_len, const uint8_t in[], size_t in_len, const uint8_t params[], size_t params_len) const
Definition: pubkey.cpp:218
secure_vector< uint8_t > bits_of() const
Definition: symkey.h:31
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

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

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

202  {
203  if(op == nullptr)
205 
206  if(flags != 0)
208 
209  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
210  *op = nullptr;
211  std::unique_ptr<Botan::PK_Key_Agreement> pk(new Botan::PK_Key_Agreement(safe_get(key_obj), Botan::system_rng(), kdf));
212  *op = new botan_pk_op_ka_struct(pk.release());
213  return BOTAN_FFI_SUCCESS;
214  });
215  }
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:28
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Flags flags(Flag flags)
Definition: p11.h:858
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:59
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143

◆ botan_pk_op_key_agreement_destroy()

int botan_pk_op_key_agreement_destroy ( botan_pk_op_ka_t  op)

Definition at line 217 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

218  {
219  return BOTAN_FFI_CHECKED_DELETE(op);
220  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:114

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

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_BAD_FLAG, and Botan_FFI::write_vec_output().

224  {
225  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
226  if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
227  return write_vec_output(out, out_len, kak->public_value());
229  });
230  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:140
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

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

References BOTAN_FFI_DO, and BOTAN_FFI_ERROR_NULL_POINTER.

233  {
234  return BOTAN_FFI_DO(Botan::PK_Key_Agreement, op, o, {
235  if(out_len == nullptr)
237  *out_len = o.agreed_value_size();
238  });
239  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

◆ 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.

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan::PKCS11::flags(), hash, Botan_FFI::safe_get(), and Botan::system_rng().

116  {
117  if(op == nullptr)
119 
120  if(flags != 0)
122 
123  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
124  *op = nullptr;
125 
126  std::unique_ptr<Botan::PK_Signer> pk(new Botan::PK_Signer(safe_get(key_obj), Botan::system_rng(), hash));
127  *op = new botan_pk_op_sign_struct(pk.release());
128  return BOTAN_FFI_SUCCESS;
129  });
130  }
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:28
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:279
Flags flags(Flag flags)
Definition: p11.h:858
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:59
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
MechanismType hash

◆ botan_pk_op_sign_destroy()

int botan_pk_op_sign_destroy ( botan_pk_op_sign_t  op)

Definition at line 132 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

133  {
134  return BOTAN_FFI_CHECKED_DELETE(op);
135  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:114

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

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

151  {
152  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, {
153  return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
154  });
155  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:140
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:59
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

◆ 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.

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::PK_Signer::signature_length().

138  {
139  if(sig_len == nullptr)
141 
142  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { *sig_len = o.signature_length(); });
143  }
size_t signature_length() const
Definition: pubkey.cpp:270
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

◆ 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.

References BOTAN_FFI_DO, and Botan::PK_Signer::update().

146  {
147  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { o.update(in, in_len); });
148  }
void update(uint8_t in)
Definition: pubkey.h:242
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

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

References BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan::PKCS11::flags(), hash, and Botan_FFI::safe_get().

161  {
162  if(op == nullptr)
164 
165  if(flags != 0)
167 
168  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
169  *op = nullptr;
170  std::unique_ptr<Botan::PK_Verifier> pk(new Botan::PK_Verifier(safe_get(key_obj), hash));
171  *op = new botan_pk_op_verify_struct(pk.release());
172  return BOTAN_FFI_SUCCESS;
173  });
174  }
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:28
Flags flags(Flag flags)
Definition: p11.h:858
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:59
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
MechanismType hash

◆ botan_pk_op_verify_destroy()

int botan_pk_op_verify_destroy ( botan_pk_op_verify_t  op)

Definition at line 176 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

177  {
178  return BOTAN_FFI_CHECKED_DELETE(op);
179  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:114

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

References BOTAN_FFI_DO, BOTAN_FFI_INVALID_VERIFIER, BOTAN_FFI_SUCCESS, and Botan::PK_Verifier::check_signature().

187  {
188  return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, {
189  const bool legit = o.check_signature(sig, sig_len);
190 
191  if(legit)
192  return BOTAN_FFI_SUCCESS;
193  else
195  });
196  }
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:336
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86

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

References BOTAN_FFI_DO, and Botan::PK_Verifier::update().

182  {
183  return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, { o.update(in, in_len); });
184  }
void update(uint8_t in)
Definition: pubkey.h:351
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:86