Botan 3.6.1
Crypto and TLS for C&
ffi_fpe.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_mp.h>
#include <botan/internal/ffi_util.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

◆ botan_fpe_decrypt()

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

Definition at line 78 of file ffi_fpe.cpp.

78 {
79#if defined(BOTAN_HAS_FPE_FE1)
80 return ffi_guard_thunk(__func__, [=]() {
81 Botan::BigInt r = safe_get(fpe).decrypt(safe_get(x), tweak, tweak_len);
82 safe_get(x) = r;
83 return BOTAN_FFI_SUCCESS;
84 });
85
86#else
87 BOTAN_UNUSED(fpe, x, tweak, tweak_len);
89#endif
90}
#define BOTAN_UNUSED
Definition assert.h:118
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:135
@ 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:118

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

◆ botan_fpe_destroy()

int botan_fpe_destroy ( botan_fpe_t fpe)
Returns
0 if success, error if invalid object handle

Definition at line 56 of file ffi_fpe.cpp.

56 {
57#if defined(BOTAN_HAS_FPE_FE1)
58 return BOTAN_FFI_CHECKED_DELETE(fpe);
59#else
60 BOTAN_UNUSED(fpe);
62#endif
63}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:143

References BOTAN_FFI_CHECKED_DELETE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, and BOTAN_UNUSED.

◆ botan_fpe_encrypt()

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

Definition at line 65 of file ffi_fpe.cpp.

65 {
66#if defined(BOTAN_HAS_FPE_FE1)
67 return ffi_guard_thunk(__func__, [=]() {
68 Botan::BigInt r = safe_get(fpe).encrypt(safe_get(x), tweak, tweak_len);
69 safe_get(x) = r;
70 return BOTAN_FFI_SUCCESS;
71 });
72#else
73 BOTAN_UNUSED(fpe, x, tweak, tweak_len);
75#endif
76}

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

◆ botan_fpe_fe1_init()

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 27 of file ffi_fpe.cpp.

28 {
29#if defined(BOTAN_HAS_FPE_FE1)
30 return ffi_guard_thunk(__func__, [=]() {
31 if(fpe == nullptr || key == nullptr) {
33 }
34
35 *fpe = nullptr;
36
37 if(flags != 0 && flags != BOTAN_FPE_FLAG_FE1_COMPAT_MODE) {
39 }
40
41 const bool compat_mode = (flags & BOTAN_FPE_FLAG_FE1_COMPAT_MODE);
42
43 std::unique_ptr<Botan::FPE_FE1> fpe_obj(new Botan::FPE_FE1(safe_get(n), rounds, compat_mode));
44
45 fpe_obj->set_key(key, key_len);
46
47 *fpe = new botan_fpe_struct(std::move(fpe_obj));
48 return BOTAN_FFI_SUCCESS;
49 });
50#else
51 BOTAN_UNUSED(fpe, n, key, key_len, rounds, flags);
53#endif
54}
#define BOTAN_FPE_FLAG_FE1_COMPAT_MODE
Definition ffi.h:2082
@ BOTAN_FFI_ERROR_BAD_FLAG
Definition ffi.h:128
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:129
Flags flags(Flag flags)
Definition p11.h:838

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_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().