Botan  2.4.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_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_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_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_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 84 of file ffi_pk_op.cpp.

References BOTAN_FFI_DO, and Botan_FFI::write_vec_output().

87  {
88  return BOTAN_FFI_DO(Botan::PK_Decryptor, op, o, {
89  return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len));
90  });
91  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

64  {
65  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
67 
68  *op = nullptr;
69 
70  if(flags != 0)
72 
73  std::unique_ptr<Botan::PK_Decryptor> pk(new Botan::PK_Decryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
74  *op = new botan_pk_op_decrypt_struct(pk.release());
75  return BOTAN_FFI_SUCCESS;
76  });
77  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#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 79 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

80  {
81  return BOTAN_FFI_CHECKED_DELETE(op);
82  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

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

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

51  {
52  return BOTAN_FFI_DO(Botan::PK_Encryptor, op, o, {
53  return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj)));
54  });
55  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ 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_ASSERT_NONNULL, BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::system_rng().

27  {
28  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
30 
31  *op = nullptr;
32 
33  if(flags != 0)
35 
36  std::unique_ptr<Botan::PK_Encryptor> pk(new Botan::PK_Encryptor_EME(safe_get(key_obj), Botan::system_rng(), padding));
37  *op = new botan_pk_op_encrypt_struct(pk.release());
38  return BOTAN_FFI_SUCCESS;
39  });
40  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#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 42 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

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

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

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

209  {
210  return BOTAN_FFI_DO(Botan::PK_Key_Agreement, op, o, {
211  auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of();
212  return write_vec_output(out, out_len, k);
213  });
214  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
size_t salt_len
Definition: x509_obj.cpp:25
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:203
secure_vector< uint8_t > bits_of() const
Definition: symkey.h:31
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

175  {
176  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
178 
179  *op = nullptr;
180 
181  if(flags != 0)
183 
184  std::unique_ptr<Botan::PK_Key_Agreement> pk(new Botan::PK_Key_Agreement(safe_get(key_obj), Botan::system_rng(), kdf));
185  *op = new botan_pk_op_ka_struct(pk.release());
186  return BOTAN_FFI_SUCCESS;
187  });
188  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#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 190 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

191  {
192  return BOTAN_FFI_CHECKED_DELETE(op);
193  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

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

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

197  {
198  return BOTAN_FFI_DO(Botan::Private_Key, key, k, {
199  if(auto kak = dynamic_cast<const Botan::PK_Key_Agreement_Key*>(&k))
200  return write_vec_output(out, out_len, kak->public_value());
202  });
203  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

100  {
101  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
103 
104  *op = nullptr;
105 
106  if(flags != 0)
108 
109  std::unique_ptr<Botan::PK_Signer> pk(new Botan::PK_Signer(safe_get(key_obj),Botan::system_rng(), hash));
110  *op = new botan_pk_op_sign_struct(pk.release());
111  return BOTAN_FFI_SUCCESS;
112  });
113  }
RandomNumberGenerator & system_rng()
Definition: system_rng.cpp:230
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#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 115 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

116  {
117  return BOTAN_FFI_CHECKED_DELETE(op);
118  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

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

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

126  {
127  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, {
128  return write_vec_output(out, out_len, o.signature(safe_get(rng_obj)));
129  });
130  }
int write_vec_output(uint8_t out[], size_t *out_len, const std::vector< uint8_t, Alloc > &buf)
Definition: ffi_util.h:146
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

121  {
122  return BOTAN_FFI_DO(Botan::PK_Signer, op, o, { o.update(in, in_len); });
123  }
void update(uint8_t in)
Definition: pubkey.h:238
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

References BOTAN_ASSERT_NONNULL, BOTAN_CURRENT_FUNCTION, BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

136  {
137  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
139 
140  if(flags != 0)
142 
143  std::unique_ptr<Botan::PK_Verifier> pk(new Botan::PK_Verifier(safe_get(key_obj), hash));
144  *op = new botan_pk_op_verify_struct(pk.release());
145  return BOTAN_FFI_SUCCESS;
146  });
147  }
#define BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:146
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
Flags flags(Flag flags)
Definition: p11.h:858
#define BOTAN_ASSERT_NONNULL(ptr)
Definition: assert.h:81
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#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 149 of file ffi_pk_op.cpp.

References BOTAN_FFI_CHECKED_DELETE.

150  {
151  return BOTAN_FFI_CHECKED_DELETE(op);
152  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

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

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

160  {
161  return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, {
162  const bool legit = o.check_signature(sig, sig_len);
163 
164  if(legit)
165  return BOTAN_FFI_SUCCESS;
166  else
168  });
169  }
#define BOTAN_FFI_INVALID_VERIFIER
Definition: ffi.h:139
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:293
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

155  {
156  return BOTAN_FFI_DO(Botan::PK_Verifier, op, o, { o.update(in, in_len); });
157  }
void update(uint8_t in)
Definition: pubkey.h:335
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98