Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- 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 std::vector< uint8_t > &tweak)
BigInt | fe1_encrypt (const BigInt &n, const BigInt &X0, const SymmetricKey &key, const std::vector< uint8_t > &tweak)

## Function Documentation

BigInt BOTAN_DLL Botan::FPE::fe1_decrypt | ( | const BigInt & | n,
|  | const BigInt & | X,
|  | const SymmetricKey & | key,
|  | const std::vector< uint8_t > & | 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 160 of file fpe_fe1.cpp.

163 {
164 FPE_Encryptor F(key, n, tweak);
165
166 BigInt a, b;
167 factor(n, a, b);
168
169 const size_t r = rounds(a, b);
170
171 BigInt X = X0;
172
173 for(size_t i = 0; i != r; ++i)
174 {
175 BigInt W = X % a;
176 BigInt R = X / a;
177
178 BigInt L = (W - F(r-i-1, R)) % a;
179 X = b * L + R;
180 }
181
182 return X;
183 }

BigInt BOTAN_DLL Botan::FPE::fe1_encrypt | ( | const BigInt & | n,
|  | const BigInt & | X,
|  | const SymmetricKey & | key,
|  | const std::vector< uint8_t > & | 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

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

135 {
136 FPE_Encryptor F(key, n, tweak);
137
138 BigInt a, b;
139 factor(n, a, b);
140
141 const size_t r = rounds(a, b);
142
143 BigInt X = X0;
144
145 for(size_t i = 0; i != r; ++i)
146 {
147 BigInt L = X / b;
148 BigInt R = X % b;
149
150 BigInt W = (L + F(i, R)) % a;
151 X = a * R + W;
152 }
153
154 return X;
155 }