Botan  1.11.15
Functions
Botan::FPE Namespace Reference

Functions

BigInt fe1_decrypt (const BigInt &n, const BigInt &X0, const SymmetricKey &key, const std::vector< byte > &tweak)
BigInt fe1_encrypt (const BigInt &n, const BigInt &X0, const SymmetricKey &key, const std::vector< byte > &tweak)

Function Documentation

BigInt BOTAN_DLL Botan::FPE::fe1_decrypt ( const BigInt &  n,
const BigInt &  X,
const SymmetricKey &  key,
const std::vector< byte > &  tweak 
)

Decrypt X from and onto the group Z_n using key and tweak

Parameters:
nthe modulus
Xthe ciphertext as a BigInt
keyis the key used for encryption
tweakthe same tweak used for encryption

Definition at line 161 of file fpe_fe1.cpp.

   {
   FPE_Encryptor F(key, n, tweak);

   BigInt a, b;
   factor(n, a, b);

   const size_t r = rounds(a, b);

   BigInt X = X0;

   for(size_t i = 0; i != r; ++i)
      {
      BigInt W = X % a;
      BigInt R = X / a;

      BigInt L = (W - F(r-i-1, R)) % a;
      X = b * L + R;
      }

   return X;
   }
BigInt BOTAN_DLL Botan::FPE::fe1_encrypt ( const BigInt &  n,
const BigInt &  X,
const SymmetricKey &  key,
const std::vector< byte > &  tweak 
)

Format Preserving Encryption using the scheme FE1 from the paper "Format-Preserving Encryption" by Bellare, Rogaway, et al (http://eprint.iacr.org/2009/251)

Encrypt X from and onto the group Z_n using key and tweak

Parameters:
nthe modulus
Xthe plaintext as a BigInt
keya random key
tweakwill modify the ciphertext (think of as an IV)

Definition at line 133 of file fpe_fe1.cpp.

   {
   FPE_Encryptor F(key, n, tweak);

   BigInt a, b;
   factor(n, a, b);

   const size_t r = rounds(a, b);

   BigInt X = X0;

   for(size_t i = 0; i != r; ++i)
      {
      BigInt L = X / b;
      BigInt R = X % b;

      BigInt W = (L + F(i, R)) % a;
      X = a * R + W;
      }

   return X;
   }