Z-Botan-0.4.0.0: Crypto for Haskell
CopyrightAnjie Dong Han 2021
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.Crypto.FPE

Description

Format preserving encryption (FPE) refers to a set of techniques for encrypting data such that the ciphertext has the same format as the plaintext. For instance, you can use FPE to encrypt credit card numbers with valid checksums such that the ciphertext is also an credit card number with a valid checksum, or similarly for bank account numbers, US Social Security numbers, or even more general mappings like English words onto other English words.

The scheme currently implemented in botan is called FE1, and described in the paper Format Preserving Encryption by Mihir Bellare, Thomas Ristenpart, Phillip Rogaway, and Till Stegers. FPE is an area of ongoing standardization and it is likely that other schemes will be included in the future.

To encrypt an arbitrary value using FE1, you need to use a ranking method. Basically, the idea is to assign an integer to every value you might encrypt. For instance, a 16 digit credit card number consists of a 15 digit code plus a 1 digit checksum. So to encrypt a credit card number, you first remove the checksum, encrypt the 15 digit value modulo 1015, and then calculate what the checksum is for the new (ciphertext) number. Or, if you were encrypting words in a dictionary, you could rank the words by their lexicographical order, and choose the modulus to be the number of words in the dictionary.

Synopsis

Documentation

data FPE Source #

Instances

Instances details
Show FPE Source # 
Instance details

Defined in Z.Crypto.FPE

Methods

showsPrec :: Int -> FPE -> ShowS #

show :: FPE -> String #

showList :: [FPE] -> ShowS #

Generic FPE Source # 
Instance details

Defined in Z.Crypto.FPE

Associated Types

type Rep FPE :: Type -> Type #

Methods

from :: FPE -> Rep FPE x #

to :: Rep FPE x -> FPE #

Print FPE Source # 
Instance details

Defined in Z.Crypto.FPE

Methods

toUTF8BuilderP :: Int -> FPE -> Builder () #

type Rep FPE Source # 
Instance details

Defined in Z.Crypto.FPE

type Rep FPE = D1 ('MetaData "FPE" "Z.Crypto.FPE" "Z-Botan-0.4.0.0-Cymuol1BxyD6d85e6LsrR5" 'True) (C1 ('MetaCons "FPE" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BotanStruct)))

newFPE Source #

Arguments

:: HasCallStack 
=> MPI

mod (n)

-> Bytes

key

-> IO FPE 

Initialize an FPE operation to encrypt/decrypt integers less than n. It is expected that n is trivially factorable into small integers. Common usage would be n to be a power of 10.

encryptFPE Source #

Arguments

:: HasCallStack 
=> FPE 
-> MPI 
-> Bytes

tweak

-> IO MPI 

Encrypts the value x modulo the value n using the key and tweak specified. Returns an integer less than n. The tweak is a value that does not need to be secret that parameterizes the encryption function. For instance, if you were encrypting a database column with a single key, you could use a per-row-unique integer index value as the tweak. The same tweak value must be used during decryption.

decryptFPE Source #

Arguments

:: HasCallStack 
=> FPE 
-> MPI 
-> Bytes

tweak

-> IO MPI 

Decrypts an FE1 ciphertext. The tweak must be the same as that provided to the encryption function. Returns the plaintext integer. Note that there is not any implicit authentication or checking of data in FE1, so if you provide an incorrect key or tweak the result is simply a random integer.