Botan: Botan::FPE Namespace Reference

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

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

  n | the modulus
  X | the ciphertext as a BigInt
  key | is the key used for encryption
  tweak | the same tweak used for encryption

Definition at line 166 of file fpe_fe1.cpp.

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 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

  n | the modulus
  X | the plaintext as a BigInt
  key | a random key
  tweak | will modify the ciphertext (think of as an IV)

Definition at line 138 of file fpe_fe1.cpp.

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 }