Botan  2.4.0
Crypto and TLS for C++11
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

◆ fe1_decrypt()

BigInt 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
nthe modulus
Xthe ciphertext as a BigInt
keyis the key used for encryption
tweakthe same tweak used for encryption

Definition at line 159 of file fpe_fe1.cpp.

References X.

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

◆ fe1_encrypt()

BigInt 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 (https://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 131 of file fpe_fe1.cpp.

References X.

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