Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Functions
ffi_fpe.cpp File Reference
`#include <botan/ffi.h>`
`#include <botan/internal/ffi_util.h>`
`#include <botan/internal/ffi_mp.h>`
`#include <memory>`

Go to the source code of this file.

## Functions
int | botan_fpe_decrypt (botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
int | botan_fpe_destroy (botan_fpe_t fpe)
int | botan_fpe_encrypt (botan_fpe_t fpe, botan_mp_t x, const uint8_t tweak[], size_t tweak_len)
int | botan_fpe_fe1_init (botan_fpe_t *fpe, botan_mp_t n, const uint8_t key[], size_t key_len, size_t rounds, uint32_t flags)

## Function Documentation

int botan_fpe_decrypt | ( | botan_fpe_t | fpe,
|  | botan_mp_t | x,
|  | const uint8_t | tweak[],
|  | size_t | tweak_len
| ) |  |

Definition at line 80 of file ffi_fpe.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

81 {
82 #if defined(BOTAN_HAS_FPE_FE1)
83 return ffi_guard_thunk(__func__, [=]() {
84 Botan::BigInt r = safe_get(fpe).decrypt(safe_get(x), tweak, tweak_len);
85 safe_get(x) = r;
86 return BOTAN_FFI_SUCCESS;
87 });
88
89 #else
90 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
91 #endif
92 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_fpe_destroy | ( | botan_fpe_t | fpe | ) |

Returns
  0 if success, error if invalid object handle

Definition at line 58 of file ffi_fpe.cpp.

References BOTAN_FFI_CHECKED_DELETE, and BOTAN_FFI_ERROR_NOT_IMPLEMENTED.

59 {
60 #if defined(BOTAN_HAS_FPE_FE1)
61 return BOTAN_FFI_CHECKED_DELETE(fpe);
62 #else
63 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
64 #endif
65 }
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

int botan_fpe_encrypt | ( | botan_fpe_t | fpe,
|  | botan_mp_t | x,
|  | const uint8_t | tweak[],
|  | size_t | tweak_len
| ) |  |

Definition at line 67 of file ffi_fpe.cpp.

References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

68 {
69 #if defined(BOTAN_HAS_FPE_FE1)
70 return ffi_guard_thunk(__func__, [=]() {
71 Botan::BigInt r = safe_get(fpe).encrypt(safe_get(x), tweak, tweak_len);
72 safe_get(x) = r;
73 return BOTAN_FFI_SUCCESS;
74 });
75 #else
76 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
77 #endif
78 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::BigInt
Definition: bigint.h:24
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_SUCCESS
Definition: ffi.h:62

int botan_fpe_fe1_init | ( | botan_fpe_t * | fpe,
|  | botan_mp_t | n,
|  | const uint8_t | key[],
|  | size_t | key_len,
|  | size_t | rounds,
|  | uint32_t | flags
| ) |  |

Definition at line 26 of file ffi_fpe.cpp.

References BOTAN_FFI_ERROR_BAD_FLAG, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FPE_FLAG_FE1_COMPAT_MODE, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

29 {
30 #if defined(BOTAN_HAS_FPE_FE1)
31
32 return ffi_guard_thunk(__func__, [=]() {
33
34 if(fpe == nullptr || key == nullptr)
35 return BOTAN_FFI_ERROR_NULL_POINTER;
36
37 *fpe = nullptr;
38
39 if(flags != 0 && flags != BOTAN_FPE_FLAG_FE1_COMPAT_MODE)
40 return BOTAN_FFI_ERROR_BAD_FLAG;
41
42 const bool compat_mode = (flags & BOTAN_FPE_FLAG_FE1_COMPAT_MODE);
43
44 std::unique_ptr<Botan::FPE_FE1> fpe_obj(
45 new Botan::FPE_FE1(safe_get(n), rounds, compat_mode));
46
47 fpe_obj->set_key(key, key_len);
48
49 *fpe = new botan_fpe_struct(fpe_obj.release());
50 return BOTAN_FFI_SUCCESS;
51 });
52 #else
53 *fpe = nullptr;
54 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
55 #endif
56 }
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89
Botan::PKCS11::flags
Flags flags(Flag flags)
Definition: p11.h:858
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:82
Botan::FPE_FE1
Definition: fpe_fe1.h:24
BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:76
BOTAN_FPE_FLAG_FE1_COMPAT_MODE
#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE
Definition: ffi.h:1737
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61
BOTAN_FFI_ERROR_BAD_FLAG
Definition: ffi.h:75
BOTAN_FFI_SUCCESS
Definition: ffi.h:62