Ubiq-fpe-go - Format preserving encryption in Go

Format Preserving Encryption in Go

An implementation of the NIST-approved FF1 and FF3-1 algorithms in Go.

This implementation conforms (as best as possible) to Draft SP 800-38G Rev. 1. The implementation passes all tests specified by NIST in their Cryptographic Standards and Guidelines examples for FF1; however, no official examples/samples exist (or are known) for FF3-1. FF3 is not implemented as NIST has officially deprecated its use in light of recent cryptanalysis performed on it.

Testing

To run the tests:

$ go test

As described above, the unit tests for FF1 come from the NIST guidelines. As no such guidelines are available for FF3-1, the unit tests verify only that the encryption and decryption implementations are compatible with each other.

Documentation

$ go doc -all

About alphabets and the radix parameter

The interfaces operate on strings, and the radix parameter determines which characters are valid within those strings, i.e. the alphabet. For example, if your radix is 10, then the alphabet for your plain text consists of the characters in the string "0123456789". If your radix is 16, then the alphabet is the characters in the string "0123456789abcdef".

More concretely, if you want to encrypt, say, a 16 digit number grouped into 4 groups of 4 using a - as a delimiter as in 0123-4567-8901-2345, then you would need a radix of at least 11, and you would need to translate the - character to an a (as that is the value that follows 9) prior to the encryption. Conversely, you would need to translate an a to a - after decryption.

This mapping of user inputs to alphabets defined by the radix is not performed by the library and must be done prior to calling the encrypt and after calling the decrypt functions.

A radix of up to 36 is supported, and the alphabet for a radix of 36 is "0123456789abcdefghijklmnopqrstuvwxyz".

Tweaks

Tweaks are very much like Initialization Vectors (IVs) in "traditional" encryption algorithms. For FF1, the minimun and maximum allowed lengths of the tweak may be specified by the user, and any tweak length between those values may be used. For FF3-1, the size of the tweak is fixed at 7 bytes.

Plain/ciphertext input lengths

For both FF1 and FF3-1, the minimum length is determined by the inequality:

  • radixminlen >= 1000000

or:

  • minlen >= 6 / log10 radix

Thus, the minimum length is determined by the radix and is automatically calculated from it.

For FF1, the maximum input length is

  • 232

For FF3-1, the maximum input length is

  • 2 * logradix 296

or:

  • 192 / log2 radix

Examples

The unit test code provides the best and simplest example of how to use the interfaces.

FF1

	// K is a slice containing the key
	// T is a slice containing the tweak
	// tweak length is unbounded
	// r is the radix
	ff1, err := NewFF1(K, T, 0, 0, r)
	if err != nil {
		...
	}

	// PT is a slice containing the plaintext
	CT, err := ff1.Encrypt(PT, nil)
	if err != nil {
		...
	}

	PT, err = ff1.Decrypt(CT, nil)
	if err != nil {
		...
	}

FF3-1

	// K is a slice containing the key
	// T is a slice containing the tweak
	// r is the radix
	ff3_1, err := NewFF3_1(K, T, r)
	if err != nil {
		...
	}

	// PT is a slice containing the plaintext
	CT, err := ff3_1.Encrypt(PT, nil)
	if err != nil {
		...
	}

	PT, err = ff3_1.Decrypt(CT, nil)
	if err != nil {
		...
	}
Owner
Ubiq Security, Inc.
Simplifying encryption for developers
Ubiq Security, Inc.
Similar Resources

A simple, modern and secure encryption tool (and Go library) with small explicit keys, no config options, and UNIX-style composability.

A simple, modern and secure encryption tool (and Go library) with small explicit keys, no config options, and UNIX-style composability.

A simple, modern and secure encryption tool (and Go library) with small explicit keys, no config options, and UNIX-style composability.

Jan 7, 2023

Easy to use encryption library for Go

encryptedbox EncryptedBox is an easy to use module for Go that can encrypt or sign any type of data. It is especially useful when you must serialize y

Jul 20, 2022

A tool for secrets management, encryption as a service, and privileged access management

A tool for secrets management, encryption as a service, and privileged access management

Deploy HCP Vault & AWS Transit Gateways via Terraform https://medium.com/hashicorp-engineering/deploying-hcp-vault-using-the-hcp-terraform-provider-5e

Nov 23, 2021

TTAK.KO-12.0223 Lightweight Encryption Algorithm with Galois/Counter Mode (LEA-GCM)

LEACrypt The Lightweight Encryption Algorithm (also known as LEA) is a 128-bit block cipher developed by South Korea in 2013 to provide confidentialit

Dec 16, 2022

Functional encryption for images

ImageFE Functional encryption for images. Introduction In the traditional cryptography framework, a decryptor either recovers the entire plaintext fro

Mar 8, 2022

Attempts to make attribute based encryption work, particularly trying out bn256 pairing curve

Attempts to make attribute based encryption work, particularly trying out bn256 pairing curve

EC Pairings over bn256 This is an attempt to solve the core problem of attribute based encryption, where the goal is to be able to use CA-issued attri

Jan 5, 2022

Go Encrypt! Is a simple command-line encryption and decryption application using AES-256 GCM.

Go Encrypt! Go Encrypt! is a command-line application used to easily encrypt and decrypt files with the AES-256 GCM encryption algorithm. Usage Usage

Jan 5, 2022

Lattigo: lattice-based multiparty homomorphic encryption library in Go

Lattigo: lattice-based multiparty homomorphic encryption library in Go Lattigo i

Dec 7, 2022

Card-encrypt - The encryption code necessary to enroll debit cards in the Palla API

💳 Card RSA Encryption Thank you for choosing Palla! 💸 In this repository you'l

Jul 15, 2022
Go implementation of the Data At Rest Encryption (DARE) format.

Secure IO Go implementation of the Data At Rest Encryption (DARE) format. Introduction It is a common problem to store data securely - especially on u

Dec 18, 2022
The minilock file encryption system, ported to pure Golang. Includes CLI utilities.
The minilock file encryption system, ported to pure Golang. Includes CLI utilities.

Go-miniLock A pure-Go reimplementation of the miniLock asymmetric encryption system. by Cathal Garvey, Copyright Oct. 2015, proudly licensed under the

Nov 28, 2022
An easy-to-use XChaCha20-encryption wrapper for io.ReadWriteCloser (even lossy UDP) using ECDH key exchange algorithm, ED25519 signatures and Blake3+Poly1305 checksums/message-authentication for Go (golang). Also a multiplexer.

Quick start Prepare keys (on both sides): [ -f ~/.ssh/id_ed25519 ] && [ -f ~/.ssh/id_ed25519.pub ] || ssh-keygen -t ed25519 scp ~/.ssh/id_ed25519.pub

Dec 30, 2022
DERO Homomorphic Encryption Blockchain Protocol
DERO Homomorphic Encryption Blockchain Protocol

Homomorphic encryption is a form of encryption allowing one to perform calculations on encrypted data without decrypting it first. The result of the computation is in an encrypted form, when decrypted the output is the same as if the operations had been performed on the unencrypted data.

Dec 27, 2022
Sekura is an Encryption tool that's heavily inspired by the Rubberhose file system.

It allows for multiple, independent file systems on a single disk whose existence can only be verified if you posses the correct password.

Oct 16, 2022
A document encryption solution for the reMarkable 2 ePaper tablet.

Remarkable 2 Encryption This repository contains multiple tools to encrypt the home folder of the reMarkable 2 epaper tablet using gocryptfs. Detailed

Nov 7, 2022
A super easy file encryption utility written in go and under 800kb
A super easy file encryption utility written in go and under 800kb

filecrypt A super easy to use file encryption utility written in golang âš  Help Wanted on porting filecrypt to other programing languages NOTE: if you

Nov 10, 2022
Encryption Abstraction Layer and Utilities for ratnet

What is Bencrypt? Bencrypt is an abstraction layer for cryptosystems in Go, that lets applications use hybrid cryptosystems without being coupled to t

Nov 9, 2022
A simple, semantic and developer-friendly golang package for encoding&decoding and encryption&decryption

A simple, semantic and developer-friendly golang package for encoding&decoding and encryption&decryption

Jan 4, 2023
Encryption & Decryption package for golang

encdec Encryption & Decryption package for golang func main() { startingTime := time.Now() privKey, pubKey := GenerateRsaKeyPair() fmt.Println("Priva

Feb 11, 2022