botan-bindings
Copyright(c) 2023-2024 Apotheca Labs
(c) 2024-2025 Haskell Foundation
LicenseBSD-3-Clause
Maintainerjoris@well-typed.com, leo@apotheca.io
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageGHC2021

Botan.Bindings.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 BotanFPEStruct Source #

Opaque FPE struct

newtype BotanFPE Source #

Botan FPE object

Constructors

MkBotanFPE 

Fields

Instances

Instances details
Storable BotanFPE Source # 
Instance details

Defined in Botan.Bindings.FPE

Methods

sizeOf :: BotanFPE -> Int

alignment :: BotanFPE -> Int

peekElemOff :: Ptr BotanFPE -> Int -> IO BotanFPE

pokeElemOff :: Ptr BotanFPE -> Int -> BotanFPE -> IO ()

peekByteOff :: Ptr b -> Int -> IO BotanFPE

pokeByteOff :: Ptr b -> Int -> BotanFPE -> IO ()

peek :: Ptr BotanFPE -> IO BotanFPE

poke :: Ptr BotanFPE -> BotanFPE -> IO ()

Eq BotanFPE Source # 
Instance details

Defined in Botan.Bindings.FPE

Methods

(==) :: BotanFPE -> BotanFPE -> Bool

(/=) :: BotanFPE -> BotanFPE -> Bool

Ord BotanFPE Source # 
Instance details

Defined in Botan.Bindings.FPE

Methods

compare :: BotanFPE -> BotanFPE -> Ordering

(<) :: BotanFPE -> BotanFPE -> Bool

(<=) :: BotanFPE -> BotanFPE -> Bool

(>) :: BotanFPE -> BotanFPE -> Bool

(>=) :: BotanFPE -> BotanFPE -> Bool

max :: BotanFPE -> BotanFPE -> BotanFPE

min :: BotanFPE -> BotanFPE -> BotanFPE

botan_fpe_destroy :: FinalizerPtr BotanFPEStruct Source #

Destroy the FPE object

pattern BOTAN_FPE_FLAG_NONE :: (Eq a, Num a) => a Source #

pattern BOTAN_FPE_FLAG_FE1_COMPAT_MODE :: (Eq a, Num a) => a Source #

botan_fpe_fe1_init Source #

Arguments

:: Ptr BotanFPE

fpe

-> BotanMP

n

-> ConstPtr Word8

key[]

-> CSize

key_len

-> CSize

rounds

-> Word32

flags

-> IO CInt 

botan_fpe_encrypt Source #

Arguments

:: BotanFPE

fpe

-> BotanMP

x

-> ConstPtr Word8

tweak[]

-> CSize

tweak_len

-> IO CInt 

botan_fpe_decrypt Source #

Arguments

:: BotanFPE

fpe

-> BotanMP

x

-> ConstPtr Word8

tweak[]

-> CSize

tweak_len

-> IO CInt