botan-low-0.0.1.0: Low-level Botan bindings
Copyright(c) Leo D 2023
LicenseBSD-3-Clause
Maintainerleo@apotheca.io
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Botan.Low.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

newtype FPE Source #

Constructors

MkFPE 

Fields

withFPE :: FPE -> (BotanFPE -> IO a) -> IO a Source #

fpeInitFE1 Source #

Arguments

:: MP

n

-> ByteString

key[]

-> Int

rounds

-> FPEFlags

flags

-> IO FPE

fpe

Initialize a FE1 FPE context

fpeEncrypt Source #

Arguments

:: FPE

fpe

-> MP

x

-> ByteString

tweak[]

-> IO () 

Encrypt the x value in-place

NOTE: Mutates the MP

fpeDecrypt Source #

Arguments

:: FPE

fpe

-> MP

x

-> ByteString

tweak[]

-> IO () 

Decrypt the x value in-place

NOTE: Mutates the MP