11#include <botan/fpe_fe1.h>
12#include <botan/numthry.h>
13#include <botan/hmac.h>
14#include <botan/sha2_32.h>
24const size_t MAX_N_BYTES = 128/8;
41 a <<= (n_low_zero / 2);
42 b <<= n_low_zero - (n_low_zero / 2);
63 throw std::runtime_error(
"Could not factor n for use in FPE");
75 throw std::logic_error(
"FPE rounds: a < b");
89 ~FPE_Encryptor() {
delete mac; }
107 if(n_bin.
size() > MAX_N_BYTES)
108 throw std::runtime_error(
"N is too large for FPE encryption");
116 mac_n_t = mac->
final();
119BigInt FPE_Encryptor::operator()(
size_t round_no,
const BigInt& R)
142 FPE_Encryptor F(key, n, tweak);
147 const size_t r = rounds(a, b);
151 for(
size_t i = 0; i != r; ++i)
156 BigInt W = (L + F(i, R)) % a;
170 FPE_Encryptor F(key, n, tweak);
175 const size_t r = rounds(a, b);
179 for(
size_t i = 0; i != r; ++i)
184 BigInt L = (W - F(r-i-1, R)) % a;
static SecureVector< byte > encode(const BigInt &n, Base base=Binary)
void update(const byte in[], size_t length)
void update_be(const T in)
void set_key(const SymmetricKey &key)
BigInt fe1_encrypt(const BigInt &n, const BigInt &X0, const SymmetricKey &key, const MemoryRegion< byte > &tweak)
BigInt fe1_decrypt(const BigInt &n, const BigInt &X0, const SymmetricKey &key, const MemoryRegion< byte > &tweak)
size_t low_zero_bits(const BigInt &n)
const size_t PRIME_TABLE_SIZE
const u16bit BOTAN_DLL PRIMES[]
void swap(Botan::MemoryRegion< T > &x, Botan::MemoryRegion< T > &y)