Botan  1.10.9
Functions
Botan::FPE Namespace Reference

Functions

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

Function Documentation

BigInt BOTAN_DLL Botan::FPE::fe1_decrypt ( const BigInt n,
const BigInt X,
const SymmetricKey key,
const MemoryRegion< 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 166 of file fpe_fe1.cpp.

References r.

169  {
170  FPE_Encryptor F(key, n, tweak);
171 
172  BigInt a, b;
173  factor(n, a, b);
174 
175  const size_t r = rounds(a, b);
176 
177  BigInt X = X0;
178 
179  for(size_t i = 0; i != r; ++i)
180  {
181  BigInt W = X % a;
182  BigInt R = X / a;
183 
184  BigInt L = (W - F(r-i-1, R)) % a;
185  X = b * L + R;
186  }
187 
188  return X;
189  }
BigInt n
Definition: numthry.cpp:26
BigInt r
Definition: numthry.cpp:26
BigInt BOTAN_DLL Botan::FPE::fe1_encrypt ( const BigInt n,
const BigInt X,
const SymmetricKey key,
const MemoryRegion< byte > &  tweak 
)

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 138 of file fpe_fe1.cpp.

References r.

141  {
142  FPE_Encryptor F(key, n, tweak);
143 
144  BigInt a, b;
145  factor(n, a, b);
146 
147  const size_t r = rounds(a, b);
148 
149  BigInt X = X0;
150 
151  for(size_t i = 0; i != r; ++i)
152  {
153  BigInt L = X / b;
154  BigInt R = X % b;
155 
156  BigInt W = (L + F(i, R)) % a;
157  X = a * R + W;
158  }
159 
160  return X;
161  }
BigInt n
Definition: numthry.cpp:26
BigInt r
Definition: numthry.cpp:26