ubiq-security-fpe
v2.0.0
Published
Ubiq Security, Inc. Format Preserving Encryption functions
Downloads
186
Maintainers
Readme
Format Preserving Encryption in Node
An implementation of the NIST-approved FF1 and FF3-1 algorithms in Node.
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.
Installation
Using the npm or yarn package managers:
You may want to make sure you are running the latest version of npm or yarn by first executing
$ npm install -g npm
# or
$ npm install -g yarn
Install the ubiq-security-fpe package with:
$ npm install ubiq-security-fpe
# or
$ yarn add ubiq-security-fpe
To build and install directly from a clone of the gitlab repository source:
$ git clone [email protected]:ubiqsecurity/ubiq-fpe-node.git
$ cd ubiq-node-fpe
$ npm install
Requirements
Node.js version 12 or later npm version 6 or later
All dependencies are pre-required in the module itself.
Testing
To run the tests:
$ npm run 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
See the Node API docs.
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".
A radix of up to 255 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
/*
* @key is an array of bytes which must be 16, 24, or 32 long
* @twk is an array of bytes of which must be between @twkmin
* and @twkmax lengths passed in.
* @custom_radix_str is the custom radix string indicating valid
* characters allowed by @PT and @encrypted_text. In this
* case, Radix 10 (numeric) is being used.
*
* @PT is "user input" for the data being encrypted
*/
const custom_radix_str = "0123456789"
const ctx = new FF1(key, twk, twkmin, twkmax, custom_radix_str.length, custom_radix_str);
const cipher_text = ctx.encrypt(PT);
const decrypted_text = ctx.decrypt(cipher_text);